Added MD3 accent to all preferences

This commit is contained in:
Prathamesh More 2021-10-22 10:16:06 +05:30
parent 67edb9d216
commit d8aaa5a21b
3 changed files with 22 additions and 2 deletions

View file

@ -84,5 +84,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
app:srcCompat="@drawable/ic_shuffle" app:srcCompat="@drawable/ic_shuffle"
style="@style/Widget.Material3.FloatingActionButton.Primary"
android:layout_marginHorizontal="16dp"/> android:layout_marginHorizontal="16dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -17,9 +17,12 @@ package code.name.monkey.appthemehelper.common.prefs.supportv7
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceCategory import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceViewHolder import androidx.preference.PreferenceViewHolder
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
class ATEPreferenceCategory @JvmOverloads constructor( class ATEPreferenceCategory @JvmOverloads constructor(
context: Context?, context: Context?,
@ -31,6 +34,13 @@ class ATEPreferenceCategory @JvmOverloads constructor(
override fun onBindViewHolder(holder: PreferenceViewHolder) { override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder) super.onBindViewHolder(holder)
val title = holder.itemView.findViewById<TextView>(android.R.id.title) val title = holder.itemView.findViewById<TextView>(android.R.id.title)
title.setTextColor(ThemeStore.accentColor(context)) title.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

@ -5,6 +5,7 @@ import android.text.Editable
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.SeekBar import android.widget.SeekBar
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat import androidx.core.graphics.BlendModeCompat
import androidx.core.widget.doAfterTextChanged import androidx.core.widget.doAfterTextChanged
@ -14,6 +15,7 @@ import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.VersionUtils
class ATESeekBarPreference @JvmOverloads constructor( class ATESeekBarPreference @JvmOverloads constructor(
context: Context, context: Context,
@ -43,7 +45,14 @@ class ATESeekBarPreference @JvmOverloads constructor(
override fun onBindViewHolder(view: PreferenceViewHolder) { override fun onBindViewHolder(view: PreferenceViewHolder) {
super.onBindViewHolder(view) super.onBindViewHolder(view)
val seekBar = view.findViewById(R.id.seekbar) as SeekBar val seekBar = view.findViewById(R.id.seekbar) as SeekBar
TintHelper.setTintAuto(seekBar, ThemeStore.accentColor(context), false) TintHelper.setTintAuto(
seekBar, // 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)
}, false
)
(view.findViewById(R.id.seekbar_value) as TextView).apply { (view.findViewById(R.id.seekbar_value) as TextView).apply {
appendUnit(editableText) appendUnit(editableText)
doAfterTextChanged { doAfterTextChanged {