From b99c7c19448332c552688bf8f9b2782931ca647d Mon Sep 17 00:00:00 2001 From: Steven Schoen Date: Wed, 26 Dec 2018 22:30:19 -0500 Subject: [PATCH] Clean up theme usage, add night mode support --- app/build.gradle | 6 +- .../stevenschoen/putionew/LoginActivity.java | 4 + .../stevenschoen/putionew/PutioActivity.kt | 1 + .../stevenschoen/putionew/PutioApplication.kt | 3 + .../com/stevenschoen/putionew/PutioUtils.java | 4 +- .../putionew/files/ConfirmDeleteFragment.kt | 4 +- .../putionew/files/CreateFolderFragment.kt | 4 +- .../files/DestinationFolderActivity.kt | 2 +- .../putionew/files/FileDetailsFragment.kt | 2 +- .../putionew/files/FolderFragment.kt | 8 +- .../putionew/files/RenameFragment.kt | 4 +- .../de/ankri/views/AutoScaleTextView.java | 96 ------------------- .../main/res/color/bottom_nav_item_tint.xml | 4 +- ...ose_black.xml => ic_toolbar_nav_close.xml} | 2 +- app/src/main/res/layout/about.xml | 6 +- app/src/main/res/layout/account.xml | 1 + app/src/main/res/layout/addtransfer_file.xml | 6 +- app/src/main/res/layout/addtransfer_link.xml | 2 +- .../main/res/layout/destination_activity.xml | 3 +- .../res/layout/download_individualorzip.xml | 6 +- app/src/main/res/layout/file_list.xml | 15 ++- app/src/main/res/layout/file_selection.xml | 8 +- app/src/main/res/layout/filedetails.xml | 7 +- app/src/main/res/layout/main.xml | 25 ++--- app/src/main/res/layout/rename.xml | 2 + app/src/main/res/layout/transfer.xml | 19 ++-- app/src/main/res/layout/transfersactivity.xml | 4 +- app/src/main/res/menu/menu_folder.xml | 2 + app/src/main/res/menu/menu_transfers.xml | 1 + .../main/res/menu/menu_transfersdialog.xml | 2 +- app/src/main/res/values-night/styles.xml | 22 +++++ app/src/main/res/values-v27/styles.xml | 12 --- app/src/main/res/values/attrs.xml | 9 +- .../values/{colors_putio.xml => colors.xml} | 7 +- app/src/main/res/values/styles.xml | 52 +++++----- 35 files changed, 148 insertions(+), 207 deletions(-) delete mode 100644 app/src/main/java/de/ankri/views/AutoScaleTextView.java rename app/src/main/res/drawable/{ic_toolbar_nav_close_black.xml => ic_toolbar_nav_close.xml} (89%) create mode 100644 app/src/main/res/values-night/styles.xml delete mode 100644 app/src/main/res/values-v27/styles.xml rename app/src/main/res/values/{colors_putio.xml => colors.xml} (68%) diff --git a/app/build.gradle b/app/build.gradle index 960c39b5..15eae175 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { applicationId 'com.stevenschoen.putionew' minSdkVersion 21 targetSdkVersion 27 - versionCode 135 - versionName '4.4.0' + versionCode 136 + versionName '4.5 beta 1' multiDexEnabled true kapt { @@ -58,7 +58,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.core:core-ktx:1.0.1' - implementation 'com.google.android.material:material:1.1.0-alpha01' + implementation 'com.google.android.material:material:1.1.0-alpha02' implementation 'androidx.leanback:leanback:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' diff --git a/app/src/main/java/com/stevenschoen/putionew/LoginActivity.java b/app/src/main/java/com/stevenschoen/putionew/LoginActivity.java index 8dc57283..e5eedc9e 100644 --- a/app/src/main/java/com/stevenschoen/putionew/LoginActivity.java +++ b/app/src/main/java/com/stevenschoen/putionew/LoginActivity.java @@ -21,6 +21,7 @@ import java.io.IOException; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -38,7 +39,10 @@ public class LoginActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { + getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); + super.onCreate(savedInstanceState); + setContentView(R.layout.login); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); diff --git a/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt b/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt index 44401639..8c039279 100644 --- a/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt +++ b/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt @@ -13,6 +13,7 @@ import android.preference.PreferenceManager import android.view.Menu import android.view.MenuItem import android.view.View +import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.interpolator.view.animation.FastOutSlowInInterpolator diff --git a/app/src/main/java/com/stevenschoen/putionew/PutioApplication.kt b/app/src/main/java/com/stevenschoen/putionew/PutioApplication.kt index 9b45ae51..c3ba0305 100644 --- a/app/src/main/java/com/stevenschoen/putionew/PutioApplication.kt +++ b/app/src/main/java/com/stevenschoen/putionew/PutioApplication.kt @@ -4,6 +4,7 @@ import android.app.Application import android.content.Context import android.os.Build import android.preference.PreferenceManager +import androidx.appcompat.app.AppCompatDelegate import androidx.fragment.app.Fragment import androidx.room.Room import com.stevenschoen.putionew.files.FileDownloadDatabase @@ -44,6 +45,8 @@ class PutioApplication : Application() { if (Build.VERSION.SDK_INT >= 26) { createNotificationChannels(this) } + + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) } val isLoggedIn: Boolean diff --git a/app/src/main/java/com/stevenschoen/putionew/PutioUtils.java b/app/src/main/java/com/stevenschoen/putionew/PutioUtils.java index 4cc27cda..fc267da3 100644 --- a/app/src/main/java/com/stevenschoen/putionew/PutioUtils.java +++ b/app/src/main/java/com/stevenschoen/putionew/PutioUtils.java @@ -29,6 +29,7 @@ import android.widget.Button; import android.widget.Toast; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -46,7 +47,6 @@ import java.util.List; import java.util.Locale; -import androidx.appcompat.app.AlertDialog; import io.reactivex.Single; import io.reactivex.SingleObserver; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -83,7 +83,7 @@ public PutioUtils(Context context) throws NoTokenException { } public static Dialog showPutioDialog(Context context, String title, int contentViewId) { - return new AlertDialog.Builder(context) + return new MaterialAlertDialogBuilder(context) .setTitle(title) .setView(contentViewId) .show(); diff --git a/app/src/main/java/com/stevenschoen/putionew/files/ConfirmDeleteFragment.kt b/app/src/main/java/com/stevenschoen/putionew/files/ConfirmDeleteFragment.kt index e83342ac..ce4dae8c 100644 --- a/app/src/main/java/com/stevenschoen/putionew/files/ConfirmDeleteFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/files/ConfirmDeleteFragment.kt @@ -3,9 +3,9 @@ package com.stevenschoen.putionew.files import android.app.Dialog import android.content.Context import android.os.Bundle -import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatDialogFragment import androidx.fragment.app.Fragment +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.stevenschoen.putionew.R class ConfirmDeleteFragment : AppCompatDialogFragment() { @@ -25,7 +25,7 @@ class ConfirmDeleteFragment : AppCompatDialogFragment() { var callbacks: Callbacks? = null override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - return AlertDialog.Builder(context!!) + return MaterialAlertDialogBuilder(context!!) .setTitle(resources.getQuantityString(R.plurals.deletetitle, amount, amount)) .setMessage(resources.getQuantityString(R.plurals.deletebody, amount, amount)) .setPositiveButton(R.string.delete) { _, _ -> callbacks?.onDeleteSelected() } diff --git a/app/src/main/java/com/stevenschoen/putionew/files/CreateFolderFragment.kt b/app/src/main/java/com/stevenschoen/putionew/files/CreateFolderFragment.kt index 0991de04..31545c72 100644 --- a/app/src/main/java/com/stevenschoen/putionew/files/CreateFolderFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/files/CreateFolderFragment.kt @@ -4,9 +4,9 @@ import android.app.Dialog import android.content.Context import android.os.Bundle import android.widget.EditText -import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.textfield.TextInputLayout import com.stevenschoen.putionew.R import com.stevenschoen.putionew.model.files.PutioFile @@ -30,7 +30,7 @@ class CreateFolderFragment : DialogFragment() { lateinit var nameView: EditText override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val dialog = AlertDialog.Builder(context!!) + val dialog = MaterialAlertDialogBuilder(context!!) .setTitle(R.string.create_folder) .setView(R.layout.create_folder_dialog) .setPositiveButton(R.string.create) { _, _ -> diff --git a/app/src/main/java/com/stevenschoen/putionew/files/DestinationFolderActivity.kt b/app/src/main/java/com/stevenschoen/putionew/files/DestinationFolderActivity.kt index 31299153..b1d1e75a 100644 --- a/app/src/main/java/com/stevenschoen/putionew/files/DestinationFolderActivity.kt +++ b/app/src/main/java/com/stevenschoen/putionew/files/DestinationFolderActivity.kt @@ -26,7 +26,7 @@ class DestinationFolderActivity : AppCompatActivity() { val toolbarView = findViewById(R.id.destination_toolbar) setSupportActionBar(toolbarView) - toolbarView.setNavigationIcon(R.drawable.ic_toolbar_nav_close_black) + toolbarView.setNavigationIcon(R.drawable.ic_toolbar_nav_close) toolbarView.setNavigationOnClickListener { finish() } findViewById(R.id.destination_cancel).setOnClickListener { diff --git a/app/src/main/java/com/stevenschoen/putionew/files/FileDetailsFragment.kt b/app/src/main/java/com/stevenschoen/putionew/files/FileDetailsFragment.kt index 8c78c5a5..a0f63f5f 100644 --- a/app/src/main/java/com/stevenschoen/putionew/files/FileDetailsFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/files/FileDetailsFragment.kt @@ -21,9 +21,9 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageButton import android.widget.ImageView -import android.widget.PopupMenu import android.widget.TextView import android.widget.Toast +import androidx.appcompat.widget.PopupMenu import androidx.core.content.res.use import androidx.core.view.updatePaddingRelative import androidx.core.widget.ImageViewCompat diff --git a/app/src/main/java/com/stevenschoen/putionew/files/FolderFragment.kt b/app/src/main/java/com/stevenschoen/putionew/files/FolderFragment.kt index 7349ea27..612cbdeb 100644 --- a/app/src/main/java/com/stevenschoen/putionew/files/FolderFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/files/FolderFragment.kt @@ -29,10 +29,10 @@ class FolderFragment : FileListFragment() { override val isRefreshing get() = folderLoader!!.isRefreshing() - val folder by lazy { arguments!!.getParcelable(EXTRA_FOLDER) } - val padForFab by lazy { arguments!!.getBoolean(EXTRA_PAD_FOR_FAB) } - val showSearch by lazy { arguments!!.getBoolean(EXTRA_SHOW_SEARCH) } - val showCreateFolder by lazy { arguments!!.getBoolean(EXTRA_SHOW_CREATEFOLDER) } + val folder by lazy { arguments!!.getParcelable(EXTRA_FOLDER)!! } + val padForFab by lazy { arguments!!.getBoolean(EXTRA_PAD_FOR_FAB)!! } + val showSearch by lazy { arguments!!.getBoolean(EXTRA_SHOW_SEARCH)!! } + val showCreateFolder by lazy { arguments!!.getBoolean(EXTRA_SHOW_CREATEFOLDER)!! } var folderLoader: FolderLoader? = null diff --git a/app/src/main/java/com/stevenschoen/putionew/files/RenameFragment.kt b/app/src/main/java/com/stevenschoen/putionew/files/RenameFragment.kt index 0f0b487c..89cb63f0 100644 --- a/app/src/main/java/com/stevenschoen/putionew/files/RenameFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/files/RenameFragment.kt @@ -5,8 +5,8 @@ import android.content.Context import android.os.Bundle import android.view.View import android.widget.EditText -import androidx.appcompat.app.AlertDialog import androidx.fragment.app.Fragment +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.stevenschoen.putionew.R import com.stevenschoen.putionew.model.files.PutioFile import com.trello.rxlifecycle2.components.support.RxAppCompatDialogFragment @@ -30,7 +30,7 @@ class RenameFragment : RxAppCompatDialogFragment() { lateinit var nameView: EditText override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val dialog = AlertDialog.Builder(context!!) + val dialog = MaterialAlertDialogBuilder(context!!) .setTitle(R.string.renametitle) .setView(R.layout.rename_dialog) .setPositiveButton(R.string.rename) { _, _ -> diff --git a/app/src/main/java/de/ankri/views/AutoScaleTextView.java b/app/src/main/java/de/ankri/views/AutoScaleTextView.java deleted file mode 100644 index 1626521b..00000000 --- a/app/src/main/java/de/ankri/views/AutoScaleTextView.java +++ /dev/null @@ -1,96 +0,0 @@ -package de.ankri.views; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Paint; -import android.util.AttributeSet; -import android.util.TypedValue; -import android.widget.TextView; - -import com.stevenschoen.putionew.R; - -/** - * A custom Text View that lowers the text size when the text is to big for the TextView. Modified version of one found on stackoverflow - * - * @author Andreas Krings - www.ankri.de - * @version 1.0 - */ -public class AutoScaleTextView extends TextView { - private Paint textPaint; - - private float preferredTextSize; - private float minTextSize; - - public AutoScaleTextView(Context context) { - this(context, null); - } - - public AutoScaleTextView(Context context, AttributeSet attrs) { - this(context, attrs, R.attr.autoScaleTextViewStyle); - - // Use this constructor, if you do not want use the default style - // super(context, attrs); - } - - public AutoScaleTextView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - - this.textPaint = new Paint(); - - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoScaleTextView, defStyle, 0); - this.minTextSize = a.getDimension(R.styleable.AutoScaleTextView_minTextSize, 10f); - a.recycle(); - - this.preferredTextSize = this.getTextSize(); - } - - /** - * Set the minimum text size for this view - * - * @param minTextSize The minimum text size - */ - public void setMinTextSize(float minTextSize) { - this.minTextSize = minTextSize; - } - - /** - * Resize the text so that it fits - * - * @param text The text. Neither null nor empty. - * @param textWidth The width of the TextView. > 0 - */ - private void refitText(String text, int textWidth) { - if (textWidth <= 0 || text == null || text.length() == 0) - return; - - // the width - int targetWidth = textWidth - this.getPaddingLeft() - this.getPaddingRight(); - - final float threshold = 0.5f; // How close we have to be - - this.textPaint.set(this.getPaint()); - - while ((this.preferredTextSize - this.minTextSize) > threshold) { - float size = (this.preferredTextSize + this.minTextSize) / 2; - this.textPaint.setTextSize(size); - if (this.textPaint.measureText(text) >= targetWidth) - this.preferredTextSize = size; // too big - else - this.minTextSize = size; // too small - } - // Use min size so that we undershoot rather than overshoot - this.setTextSize(TypedValue.COMPLEX_UNIT_PX, this.minTextSize); - } - - @Override - protected void onTextChanged(final CharSequence text, final int start, final int before, final int after) { - this.refitText(text.toString(), this.getWidth()); - } - - @Override - protected void onSizeChanged(int width, int height, int oldwidth, int oldheight) { - if (width != oldwidth) - this.refitText(this.getText().toString(), width); - } - -} diff --git a/app/src/main/res/color/bottom_nav_item_tint.xml b/app/src/main/res/color/bottom_nav_item_tint.xml index 5319a188..18ea9aca 100644 --- a/app/src/main/res/color/bottom_nav_item_tint.xml +++ b/app/src/main/res/color/bottom_nav_item_tint.xml @@ -1,5 +1,5 @@ - - + + diff --git a/app/src/main/res/drawable/ic_toolbar_nav_close_black.xml b/app/src/main/res/drawable/ic_toolbar_nav_close.xml similarity index 89% rename from app/src/main/res/drawable/ic_toolbar_nav_close_black.xml rename to app/src/main/res/drawable/ic_toolbar_nav_close.xml index d0c54590..5629fe32 100644 --- a/app/src/main/res/drawable/ic_toolbar_nav_close_black.xml +++ b/app/src/main/res/drawable/ic_toolbar_nav_close.xml @@ -5,7 +5,7 @@ android:viewportHeight="24.0" > diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml index 6094d280..f3089799 100644 --- a/app/src/main/res/layout/about.xml +++ b/app/src/main/res/layout/about.xml @@ -16,7 +16,7 @@ android:id="@+id/about_header" android:layout_width="0dp" android:layout_height="136dp" - android:background="?colorPrimary" + android:background="?putio_colorTopBar" android:elevation="4dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -76,6 +76,7 @@ android:background="?selectableItemBackground" android:drawableStart="@drawable/ic_about_github" android:drawablePadding="24dp" + android:drawableTint="?colorOnBackground" android:gravity="center_vertical" android:minHeight="48dp" android:paddingStart="24dp" @@ -93,6 +94,7 @@ android:background="?selectableItemBackground" android:drawableStart="@drawable/ic_about_email" android:drawablePadding="24dp" + android:drawableTint="?colorOnBackground" android:gravity="center_vertical" android:minHeight="48dp" android:paddingStart="24dp" @@ -110,6 +112,7 @@ android:background="?selectableItemBackground" android:drawableStart="@drawable/ic_about_translate" android:drawablePadding="24dp" + android:drawableTint="?colorOnBackground" android:gravity="center_vertical" android:minHeight="48dp" android:paddingStart="24dp" @@ -127,6 +130,7 @@ android:background="?selectableItemBackground" android:drawableStart="@drawable/ic_about_visit" android:drawablePadding="24dp" + android:drawableTint="?colorOnBackground" android:gravity="center_vertical" android:minHeight="48dp" android:paddingStart="24dp" diff --git a/app/src/main/res/layout/account.xml b/app/src/main/res/layout/account.xml index 5b885229..187220da 100644 --- a/app/src/main/res/layout/account.xml +++ b/app/src/main/res/layout/account.xml @@ -46,6 +46,7 @@ android:layout_marginEnd="32dp" android:gravity="center" android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" + android:textColor="@android:color/black" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout/addtransfer_file.xml b/app/src/main/res/layout/addtransfer_file.xml index 20e60731..e55c4361 100644 --- a/app/src/main/res/layout/addtransfer_file.xml +++ b/app/src/main/res/layout/addtransfer_file.xml @@ -42,7 +42,7 @@ android:src="@drawable/ic_close" /> - @@ -87,7 +87,7 @@