diff --git a/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt b/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt new file mode 100644 index 000000000..b2e467b7c --- /dev/null +++ b/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt @@ -0,0 +1,61 @@ +package io.legado.app.base + +import android.annotation.SuppressLint +import androidx.fragment.app.DialogFragment +import androidx.preference.* +import io.legado.app.ui.widget.prefs.EditTextPreferenceDialog +import io.legado.app.ui.widget.prefs.ListPreferenceDialog +import io.legado.app.ui.widget.prefs.MultiSelectListPreferenceDialog + +abstract class BasePreferenceFragment : PreferenceFragmentCompat() { + + private val dialogFragmentTag = "androidx.preference.PreferenceFragment.DIALOG" + + @SuppressLint("RestrictedApi") + override fun onDisplayPreferenceDialog(preference: Preference) { + + var handled = false + if (callbackFragment is OnPreferenceDisplayDialogCallback) { + handled = + (callbackFragment as OnPreferenceDisplayDialogCallback) + .onPreferenceDisplayDialog(this, preference) + } + if (!handled && activity is OnPreferenceDisplayDialogCallback) { + handled = (activity as OnPreferenceDisplayDialogCallback) + .onPreferenceDisplayDialog(this, preference) + } + + if (handled) { + return + } + + // check if dialog is already showing + if (parentFragmentManager.findFragmentByTag(dialogFragmentTag) != null) { + return + } + + val f: DialogFragment = when (preference) { + is EditTextPreference -> { + EditTextPreferenceDialog.newInstance(preference.getKey()) + } + is ListPreference -> { + ListPreferenceDialog.newInstance(preference.getKey()) + } + is MultiSelectListPreference -> { + MultiSelectListPreferenceDialog.newInstance(preference.getKey()) + } + else -> { + throw IllegalArgumentException( + "Cannot display dialog for an unknown Preference type: " + + preference.javaClass.simpleName + + ". Make sure to implement onPreferenceDisplayDialog() to handle " + + "displaying a custom dialog for this Preference." + ) + } + } + f.setTargetFragment(this, 0) + f.show(parentFragmentManager, dialogFragmentTag) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index a7822b84b..8b6a4782c 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -16,6 +16,7 @@ import androidx.appcompat.app.AlertDialog import androidx.recyclerview.widget.RecyclerView import androidx.viewpager.widget.ViewPager import com.google.android.material.bottomnavigation.BottomNavigationView +import io.legado.app.App import io.legado.app.R import io.legado.app.help.AppConfig import io.legado.app.utils.dp @@ -140,10 +141,7 @@ object ATH { } fun setAlertDialogTint(dialog: AlertDialog): AlertDialog { - val background = GradientDrawable() - background.cornerRadius = 3F.dp - background.setColor(dialog.context.backgroundColor) - dialog.window?.setBackgroundDrawable(background) + dialog.window?.setBackgroundDrawable(getDialogBackground()) val colorStateList = Selector.colorBuild() .setDefaultColor(ThemeStore.accentColor(dialog.context)) .setPressedColor(ColorUtils.darkenColor(ThemeStore.accentColor(dialog.context))) @@ -233,6 +231,13 @@ object ATH { } } + fun getDialogBackground(): GradientDrawable { + val background = GradientDrawable() + background.cornerRadius = 3F.dp + background.setColor(App.INSTANCE.backgroundColor) + return background + } + private val DEFAULT_EFFECT_FACTORY = object : RecyclerView.EdgeEffectFactory() { override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect { val edgeEffect = super.createEdgeEffect(view, direction) diff --git a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt index f6b4f0484..271190561 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.about -import android.graphics.drawable.GradientDrawable import android.os.Bundle import android.text.Spannable import android.text.SpannableString @@ -9,9 +8,8 @@ import android.view.Menu import android.view.MenuItem import io.legado.app.R import io.legado.app.base.BaseActivity +import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor -import io.legado.app.lib.theme.backgroundColor -import io.legado.app.utils.dp import io.legado.app.utils.openUrl import kotlinx.android.synthetic.main.activity_about.* import org.jetbrains.anko.share @@ -20,10 +18,7 @@ import org.jetbrains.anko.share class AboutActivity : BaseActivity(R.layout.activity_about) { override fun onActivityCreated(savedInstanceState: Bundle?) { - val background = GradientDrawable() - background.cornerRadius = 3F.dp - background.setColor(backgroundColor) - ll_about.background = background + ll_about.background = ATH.getDialogBackground() val fTag = "aboutFragment" var aboutFragment = supportFragmentManager.findFragmentByTag(fTag) if (aboutFragment == null) aboutFragment = AboutFragment() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 37d30f3d0..99e7e8421 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -10,8 +10,8 @@ import android.view.ViewGroup import android.widget.LinearLayout import androidx.fragment.app.DialogFragment import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig @@ -64,7 +64,7 @@ class MoreConfigDialog : DialogFragment() { .commit() } - class ReadPreferenceFragment : PreferenceFragmentCompat(), + class ReadPreferenceFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index cdb10159e..16e7a39c2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -10,8 +10,8 @@ import android.widget.LinearLayout import androidx.fragment.app.DialogFragment import androidx.preference.ListPreference import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig @@ -59,7 +59,7 @@ class ReadAloudConfigDialog : DialogFragment() { .commit() } - class ReadAloudPreferenceFragment : PreferenceFragmentCompat(), + class ReadAloudPreferenceFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 85740f674..56d753eaf 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -8,17 +8,18 @@ import android.view.View import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.PreferKey import io.legado.app.help.storage.Restore import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.filechooser.FileChooserDialog +import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString -class BackupConfigFragment : PreferenceFragmentCompat(), +class BackupConfigFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener, FileChooserDialog.CallBack { @@ -125,9 +126,11 @@ class BackupConfigFragment : PreferenceFragmentCompat(), multiChoiceItems(Restore.ignoreTitle, checkedItems) { _, which, isChecked -> Restore.ignoreConfig[Restore.ignoreKeys[which]] = isChecked } - }.show().setOnDismissListener { - Restore.saveIgnoreConfig() - } + }.show() + .applyTint() + .setOnDismissListener { + Restore.saveIgnoreConfig() + } } override fun onFilePicked(requestCode: Int, currentPath: String) { diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 850ee8e39..ffb980723 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -11,9 +11,9 @@ import android.view.View import androidx.documentfile.provider.DocumentFile import androidx.preference.ListPreference import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R +import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig @@ -29,7 +29,7 @@ import io.legado.app.utils.* import java.io.File -class OtherConfigFragment : PreferenceFragmentCompat(), +class OtherConfigFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { private val requestCodeCover = 231 diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 354ae254e..b42bcbdec 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -9,9 +9,9 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R +import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig @@ -27,7 +27,7 @@ import io.legado.app.utils.* @Suppress("SameParameterValue") -class ThemeConfigFragment : PreferenceFragmentCompat(), +class ThemeConfigFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { val items = arrayListOf("极简", "曜夜", "经典", "黑白", "A屏黑") diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index b16cbaf17..79758fc01 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -7,10 +7,10 @@ import android.view.Menu import android.view.MenuItem import android.view.View import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment +import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig @@ -68,7 +68,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog. /** * 配置 */ - class PreferenceFragment : PreferenceFragmentCompat(), + class PreferenceFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreferenceDialog.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreferenceDialog.kt new file mode 100644 index 000000000..abbff9a87 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreferenceDialog.kt @@ -0,0 +1,29 @@ +package io.legado.app.ui.widget.prefs + +import android.app.Dialog +import android.os.Bundle +import androidx.preference.EditTextPreferenceDialogFragmentCompat +import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.ATH + +class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() { + + companion object { + + fun newInstance(key: String): EditTextPreferenceDialog { + val fragment = EditTextPreferenceDialog() + val b = Bundle(1) + b.putString(PreferenceDialogFragmentCompat.ARG_KEY, key) + fragment.arguments = b + return fragment + } + + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val dialog = super.onCreateDialog(savedInstanceState) + dialog.window?.setBackgroundDrawable(ATH.getDialogBackground()) + return dialog + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/ListPreferenceDialog.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/ListPreferenceDialog.kt new file mode 100644 index 000000000..520d49d68 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/ListPreferenceDialog.kt @@ -0,0 +1,29 @@ +package io.legado.app.ui.widget.prefs + +import android.app.Dialog +import android.os.Bundle +import androidx.preference.ListPreferenceDialogFragmentCompat +import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.ATH + +class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() { + + companion object { + + fun newInstance(key: String?): ListPreferenceDialog { + val fragment = ListPreferenceDialog() + val b = Bundle(1) + b.putString(PreferenceDialogFragmentCompat.ARG_KEY, key) + fragment.arguments = b + return fragment + } + + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val dialog = super.onCreateDialog(savedInstanceState) + dialog.window?.setBackgroundDrawable(ATH.getDialogBackground()) + return dialog + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/MultiSelectListPreferenceDialog.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/MultiSelectListPreferenceDialog.kt new file mode 100644 index 000000000..6336120b0 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/MultiSelectListPreferenceDialog.kt @@ -0,0 +1,32 @@ +package io.legado.app.ui.widget.prefs + +import android.app.Dialog +import android.os.Bundle +import androidx.preference.MultiSelectListPreferenceDialogFragmentCompat +import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.ATH + +class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentCompat() { + + companion object { + + fun newInstance(key: String?): MultiSelectListPreferenceDialog { + val fragment = + MultiSelectListPreferenceDialog() + val b = Bundle(1) + b.putString(PreferenceDialogFragmentCompat.ARG_KEY, key) + fragment.arguments = b + return fragment + } + + } + + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val dialog = super.onCreateDialog(savedInstanceState) + dialog.window?.setBackgroundDrawable(ATH.getDialogBackground()) + return dialog + } + + +} \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_aloud.xml b/app/src/main/res/xml/pref_config_aloud.xml index c3d4f20cc..a41fa79b1 100644 --- a/app/src/main/res/xml/pref_config_aloud.xml +++ b/app/src/main/res/xml/pref_config_aloud.xml @@ -4,6 +4,8 @@ + app:allowDividerBelow="false"> + app:allowDividerBelow="false" + app:iconSpaceReserved="false"> + app:iconSpaceReserved="false" + app:layout="@layout/view_preference_category">