Fixed Preference title tint for MD3

This commit is contained in:
Prathamesh More 2021-10-06 16:58:48 +05:30
parent 480d66cc24
commit 8ce6cf58fa
9 changed files with 27 additions and 11 deletions

View file

@ -72,7 +72,7 @@
android:orientation="vertical"
app:layout_constraintGuide_begin="@dimen/list_pref_guideline_begin" />
<code.name.monkey.retromusic.views.ATESwitch
<code.name.monkey.appthemehelper.common.views.ATESwitch
android:id="@android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -60,7 +60,7 @@
android:orientation="vertical"
app:layout_constraintGuide_begin="@dimen/list_pref_guideline_begin" />
<code.name.monkey.retromusic.views.ATESwitch
<code.name.monkey.appthemehelper.common.views.ATESwitch
android:id="@android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -299,5 +299,9 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
}
return true
}
fun isMD3Enabled(context: Context): Boolean {
return prefs(context).getBoolean(ThemeStorePrefKeys.KEY_MATERIAL_YOU, false)
}
}
}

View file

@ -27,5 +27,7 @@ internal interface ThemeStorePrefKeys {
const val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar"
const val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar"
const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark"
const val KEY_MATERIAL_YOU = "material_you"
}
}

View file

@ -16,9 +16,11 @@ package code.name.monkey.appthemehelper.common.views
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
class ATEAccentTextView @JvmOverloads constructor(
context: Context,
@ -27,6 +29,13 @@ class ATEAccentTextView @JvmOverloads constructor(
) : AppCompatTextView(context, attrs, defStyleAttr) {
init {
setTextColor(ThemeStore.accentColor(context))
setTextColor(
// Set MD3 accent if MD3 is enabled or in-app accent otherwise
if (ThemeStore.isMD3Enabled(context) && VersionUtils.hasS()) {
ContextCompat.getColor(context, R.color.m3_accent_color)
} else {
ThemeStore.accentColor(context)
}
)
}
}

View file

@ -1,13 +1,14 @@
package code.name.monkey.retromusic.views
package code.name.monkey.appthemehelper.common.views
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import code.name.monkey.appthemehelper.ATH
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.RetroColorUtil
import code.name.monkey.appthemehelper.util.VersionUtils
/**
* @author Aidan Follestad (afollestad)
@ -31,8 +32,8 @@ class ATESwitch : SwitchCompat {
}
private fun init(context: Context) {
if (PreferenceUtil.materialYou) {
ATH.setTint(this, RetroColorUtil.getMD3AccentColor(context))
if (ThemeStore.isMD3Enabled(context) && VersionUtils.hasS()) {
ATH.setTint(this, ContextCompat.getColor(context, R.color.m3_accent_color))
} else {
ATH.setTint(this, ThemeStore.accentColor(context))
}

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<code.name.monkey.retromusic.views.ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
<ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"