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 dcecc9577..97b359ad8 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 @@ -14,7 +14,6 @@ import android.view.WindowManager import android.widget.EdgeEffect import android.widget.ScrollView import androidx.annotation.ColorInt -import androidx.appcompat.app.AlertDialog import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 import com.google.android.material.bottomnavigation.BottomNavigationView @@ -191,24 +190,6 @@ object ATH { TintHelper.setTintAuto(view, color, true, isDark) } - fun setAlertDialogTint(dialog: AlertDialog): AlertDialog { - dialog.window?.setBackgroundDrawable(getDialogBackground()) - val colorStateList = Selector.colorBuild() - .setDefaultColor(ThemeStore.accentColor(dialog.context)) - .setPressedColor(ColorUtils.darkenColor(ThemeStore.accentColor(dialog.context))) - .create() - if (dialog.getButton(AlertDialog.BUTTON_NEGATIVE) != null) { - dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(colorStateList) - } - if (dialog.getButton(AlertDialog.BUTTON_POSITIVE) != null) { - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(colorStateList) - } - if (dialog.getButton(AlertDialog.BUTTON_NEUTRAL) != null) { - dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(colorStateList) - } - return dialog - } - fun setEdgeEffectColor(view: RecyclerView?, @ColorInt color: Int) { view?.edgeEffectFactory = object : RecyclerView.EdgeEffectFactory() { override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt index 468f4ce71..b9efd2398 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt @@ -13,8 +13,8 @@ import androidx.fragment.app.FragmentActivity import androidx.preference.Preference import androidx.preference.PreferenceViewHolder import com.jaredrummler.android.colorpicker.* -import io.legado.app.lib.theme.ATH import io.legado.app.utils.ColorUtils +import io.legado.app.utils.applyTint @Suppress("MemberVisibilityCanBePrivate", "unused") class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), @@ -215,9 +215,7 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex override fun onStart() { super.onStart() val alertDialog = dialog as? AlertDialog - alertDialog?.let { - ATH.setAlertDialogTint(it) - } + alertDialog?.applyTint() } diff --git a/app/src/main/java/io/legado/app/utils/AlertDialogExtensions.kt b/app/src/main/java/io/legado/app/utils/AlertDialogExtensions.kt index 44bacecbd..fb9cd464d 100644 --- a/app/src/main/java/io/legado/app/utils/AlertDialogExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/AlertDialogExtensions.kt @@ -3,9 +3,25 @@ package io.legado.app.utils import android.view.WindowManager import androidx.appcompat.app.AlertDialog import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.Selector +import io.legado.app.lib.theme.ThemeStore fun AlertDialog.applyTint(): AlertDialog { - return ATH.setAlertDialogTint(this) + window?.setBackgroundDrawable(ATH.getDialogBackground()) + val colorStateList = Selector.colorBuild() + .setDefaultColor(ThemeStore.accentColor(context)) + .setPressedColor(ColorUtils.darkenColor(ThemeStore.accentColor(context))) + .create() + if (getButton(AlertDialog.BUTTON_NEGATIVE) != null) { + getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(colorStateList) + } + if (getButton(AlertDialog.BUTTON_POSITIVE) != null) { + getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(colorStateList) + } + if (getButton(AlertDialog.BUTTON_NEUTRAL) != null) { + getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(colorStateList) + } + return this } fun AlertDialog.requestInputMethod() {