0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2025-01-05 15:01:01 +00:00

reference accent color variable instead of getting preference value every time

This commit is contained in:
X1nto 2021-02-28 14:13:21 +04:00
parent 4fcfe72a0f
commit 2e3416ef43
12 changed files with 16 additions and 33 deletions

View file

@ -10,6 +10,8 @@ import com.crowdin.platform.data.remote.NetworkType
import com.vanced.manager.BuildConfig.* import com.vanced.manager.BuildConfig.*
import com.vanced.manager.utils.AppUtils.log import com.vanced.manager.utils.AppUtils.log
import com.vanced.manager.utils.loadJson import com.vanced.manager.utils.loadJson
import com.vanced.manager.utils.managerAccent
import com.vanced.manager.utils.mutableAccentColor
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
@ -23,7 +25,7 @@ open class App: Application() {
override fun onCreate() { override fun onCreate() {
scope.launch { loadJson(this@App) } scope.launch { loadJson(this@App) }
super.onCreate() super.onCreate()
mutableAccentColor.value = prefs.managerAccent
Crowdin.init(this, Crowdin.init(this,
CrowdinConfig.Builder().apply { CrowdinConfig.Builder().apply {
withDistributionHash(CROWDIN_HASH) withDistributionHash(CROWDIN_HASH)

View file

@ -4,8 +4,7 @@ import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.util.AttributeSet import android.util.AttributeSet
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.vanced.manager.utils.defPrefs import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.managerAccent
class ThemedAppCard @JvmOverloads constructor( class ThemedAppCard @JvmOverloads constructor(
context: Context, context: Context,
@ -14,7 +13,7 @@ class ThemedAppCard @JvmOverloads constructor(
) : MaterialCardView(context, attributeSet, defStyleAttr) { ) : MaterialCardView(context, attributeSet, defStyleAttr) {
init { init {
setCardBackgroundColor(ColorStateList.valueOf(context.defPrefs.managerAccent).withAlpha(35)) setCardBackgroundColor(ColorStateList.valueOf(accentColor.value!!).withAlpha(35))
} }
} }

View file

@ -4,8 +4,7 @@ import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageButton import androidx.appcompat.widget.AppCompatImageButton
import com.vanced.manager.utils.defPrefs import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.managerAccent
class ThemedImageButton @JvmOverloads constructor( class ThemedImageButton @JvmOverloads constructor(
context: Context, context: Context,
@ -14,7 +13,7 @@ class ThemedImageButton @JvmOverloads constructor(
) : AppCompatImageButton(context, attributeSet, defStyleAttr) { ) : AppCompatImageButton(context, attributeSet, defStyleAttr) {
init { init {
imageTintList = ColorStateList.valueOf(context.defPrefs.managerAccent) imageTintList = ColorStateList.valueOf(accentColor.value!!)
} }
} }

View file

@ -7,9 +7,7 @@ import androidx.core.graphics.ColorUtils
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.accentColor import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.defPrefs
import com.vanced.manager.utils.lifecycleOwner import com.vanced.manager.utils.lifecycleOwner
import com.vanced.manager.utils.managerAccent
class ThemedMaterialButton @JvmOverloads constructor( class ThemedMaterialButton @JvmOverloads constructor(
context: Context, context: Context,
@ -18,7 +16,6 @@ class ThemedMaterialButton @JvmOverloads constructor(
) : MaterialButton(context, attributeSet, defStyleAttr) { ) : MaterialButton(context, attributeSet, defStyleAttr) {
init { init {
setBgColor(context.defPrefs.managerAccent)
context.lifecycleOwner()?.let { owner -> context.lifecycleOwner()?.let { owner ->
accentColor.observe(owner) { color -> accentColor.observe(owner) { color ->
setBgColor(color.toInt()) setBgColor(color.toInt())

View file

@ -5,14 +5,13 @@ import android.content.res.ColorStateList
import android.util.AttributeSet import android.util.AttributeSet
import com.google.android.material.checkbox.MaterialCheckBox import com.google.android.material.checkbox.MaterialCheckBox
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.defPrefs import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.managerAccent
class ThemedMaterialCheckbox @JvmOverloads constructor( class ThemedMaterialCheckbox @JvmOverloads constructor(
context: Context, context: Context,
attributeSet: AttributeSet? = null, attributeSet: AttributeSet? = null,
) : MaterialCheckBox(context, attributeSet, R.attr.checkboxStyle) { ) : MaterialCheckBox(context, attributeSet, R.attr.checkboxStyle) {
init { init {
buttonTintList = ColorStateList.valueOf(context.defPrefs.managerAccent) buttonTintList = ColorStateList.valueOf(accentColor.value!!)
} }
} }

View file

@ -5,14 +5,13 @@ import android.content.res.ColorStateList
import android.util.AttributeSet import android.util.AttributeSet
import com.google.android.material.radiobutton.MaterialRadioButton import com.google.android.material.radiobutton.MaterialRadioButton
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.defPrefs import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.managerAccent
class ThemedMaterialRadioButton @JvmOverloads constructor( class ThemedMaterialRadioButton @JvmOverloads constructor(
context: Context, context: Context,
attributeSet: AttributeSet? = null, attributeSet: AttributeSet? = null,
) : MaterialRadioButton(context, attributeSet, R.attr.radioButtonStyle) { ) : MaterialRadioButton(context, attributeSet, R.attr.radioButtonStyle) {
init { init {
buttonTintList = ColorStateList.valueOf(context.defPrefs.managerAccent) buttonTintList = ColorStateList.valueOf(accentColor.value!!)
} }
} }

View file

@ -4,8 +4,7 @@ import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.util.AttributeSet import android.util.AttributeSet
import com.google.android.material.slider.Slider import com.google.android.material.slider.Slider
import com.vanced.manager.utils.defPrefs import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.managerAccent
class ThemedMaterialSlider @JvmOverloads constructor( class ThemedMaterialSlider @JvmOverloads constructor(
context: Context, context: Context,
@ -14,7 +13,7 @@ class ThemedMaterialSlider @JvmOverloads constructor(
) : Slider(context, attributeSet, defStyleAttr) { ) : Slider(context, attributeSet, defStyleAttr) {
init { init {
val accentValue = ColorStateList.valueOf(context.defPrefs.managerAccent) val accentValue = ColorStateList.valueOf(accentColor.value!!)
thumbTintList = accentValue thumbTintList = accentValue
trackActiveTintList = accentValue trackActiveTintList = accentValue
trackInactiveTintList = accentValue.withAlpha(70) trackInactiveTintList = accentValue.withAlpha(70)

View file

@ -6,10 +6,7 @@ import android.util.AttributeSet
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.vanced.manager.utils.accentColor import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.defPrefs
import com.vanced.manager.utils.lifecycleOwner import com.vanced.manager.utils.lifecycleOwner
import com.vanced.manager.utils.managerAccent
class ThemedOutlinedMaterialButton @JvmOverloads constructor( class ThemedOutlinedMaterialButton @JvmOverloads constructor(
context: Context, context: Context,
@ -17,7 +14,6 @@ class ThemedOutlinedMaterialButton @JvmOverloads constructor(
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : MaterialButton(context, attributeSet, defStyleAttr) { ) : MaterialButton(context, attributeSet, defStyleAttr) {
init { init {
applyAccent(context.defPrefs.managerAccent)
context.lifecycleOwner()?.let { owner -> context.lifecycleOwner()?.let { owner ->
accentColor.observe(owner) { color -> accentColor.observe(owner) { color ->
applyAccent(color.toInt()) applyAccent(color.toInt())

View file

@ -4,15 +4,14 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.defPrefs import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.managerAccent
class ThemedSwipeRefreshlayout @JvmOverloads constructor( class ThemedSwipeRefreshlayout @JvmOverloads constructor(
context: Context, context: Context,
attributeSet: AttributeSet? = null attributeSet: AttributeSet? = null
) : SwipeRefreshLayout(context, attributeSet) { ) : SwipeRefreshLayout(context, attributeSet) {
init { init {
setColorSchemeColors(context.defPrefs.managerAccent) setColorSchemeColors(accentColor.value!!)
initAttrs(context, attributeSet) initAttrs(context, attributeSet)
} }
private fun initAttrs(context: Context, attributeSet: AttributeSet?) { private fun initAttrs(context: Context, attributeSet: AttributeSet?) {

View file

@ -9,9 +9,7 @@ import androidx.core.graphics.ColorUtils
import androidx.core.graphics.drawable.DrawableCompat import androidx.core.graphics.drawable.DrawableCompat
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.accentColor import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.defPrefs
import com.vanced.manager.utils.lifecycleOwner import com.vanced.manager.utils.lifecycleOwner
import com.vanced.manager.utils.managerAccent
class ThemedSwitchCompat @JvmOverloads constructor( class ThemedSwitchCompat @JvmOverloads constructor(
context: Context, context: Context,
@ -21,7 +19,6 @@ class ThemedSwitchCompat @JvmOverloads constructor(
private val states = arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)) private val states = arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked))
init { init {
setSwitchColors(context.defPrefs.managerAccent)
context.lifecycleOwner()?.let { owner -> context.lifecycleOwner()?.let { owner ->
accentColor.observe(owner) { color -> accentColor.observe(owner) { color ->
setSwitchColors(color.toInt()) setSwitchColors(color.toInt())

View file

@ -4,9 +4,7 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import com.vanced.manager.utils.accentColor import com.vanced.manager.utils.accentColor
import com.vanced.manager.utils.defPrefs
import com.vanced.manager.utils.lifecycleOwner import com.vanced.manager.utils.lifecycleOwner
import com.vanced.manager.utils.managerAccent
class ThemedTextView @JvmOverloads constructor( class ThemedTextView @JvmOverloads constructor(
context: Context, context: Context,
@ -14,7 +12,6 @@ class ThemedTextView @JvmOverloads constructor(
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : AppCompatTextView(context, attributeSet, defStyleAttr) { ) : AppCompatTextView(context, attributeSet, defStyleAttr) {
init { init {
setTextColor(context.defPrefs.managerAccent)
context.lifecycleOwner()?.let { owner -> context.lifecycleOwner()?.let { owner ->
accentColor.observe(owner) { color -> accentColor.observe(owner) { color ->
setTextColor(color.toInt()) setTextColor(color.toInt())

View file

@ -11,7 +11,7 @@ const val LIGHT = "Light"
const val DARK = "Dark" const val DARK = "Dark"
const val SYSTEM_DEFAULT = "System Default" const val SYSTEM_DEFAULT = "System Default"
val mutableAccentColor = MutableLiveData<Int>() val mutableAccentColor = MutableLiveData(defAccentColor)
val accentColor: LiveData<Int> = mutableAccentColor val accentColor: LiveData<Int> = mutableAccentColor
var currentTheme = "" var currentTheme = ""