mirror of
https://github.com/YTVanced/VancedManager
synced 2025-01-03 14:10:59 +00:00
reference accent color variable instead of getting preference value every time
This commit is contained in:
parent
4fcfe72a0f
commit
2e3416ef43
12 changed files with 16 additions and 33 deletions
|
@ -10,6 +10,8 @@ import com.crowdin.platform.data.remote.NetworkType
|
|||
import com.vanced.manager.BuildConfig.*
|
||||
import com.vanced.manager.utils.AppUtils.log
|
||||
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.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
|
@ -23,7 +25,7 @@ open class App: Application() {
|
|||
override fun onCreate() {
|
||||
scope.launch { loadJson(this@App) }
|
||||
super.onCreate()
|
||||
|
||||
mutableAccentColor.value = prefs.managerAccent
|
||||
Crowdin.init(this,
|
||||
CrowdinConfig.Builder().apply {
|
||||
withDistributionHash(CROWDIN_HASH)
|
||||
|
|
|
@ -4,8 +4,7 @@ import android.content.Context
|
|||
import android.content.res.ColorStateList
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
import com.vanced.manager.utils.accentColor
|
||||
|
||||
class ThemedAppCard @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -14,7 +13,7 @@ class ThemedAppCard @JvmOverloads constructor(
|
|||
) : MaterialCardView(context, attributeSet, defStyleAttr) {
|
||||
|
||||
init {
|
||||
setCardBackgroundColor(ColorStateList.valueOf(context.defPrefs.managerAccent).withAlpha(35))
|
||||
setCardBackgroundColor(ColorStateList.valueOf(accentColor.value!!).withAlpha(35))
|
||||
}
|
||||
|
||||
}
|
|
@ -4,8 +4,7 @@ import android.content.Context
|
|||
import android.content.res.ColorStateList
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatImageButton
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
import com.vanced.manager.utils.accentColor
|
||||
|
||||
class ThemedImageButton @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -14,7 +13,7 @@ class ThemedImageButton @JvmOverloads constructor(
|
|||
) : AppCompatImageButton(context, attributeSet, defStyleAttr) {
|
||||
|
||||
init {
|
||||
imageTintList = ColorStateList.valueOf(context.defPrefs.managerAccent)
|
||||
imageTintList = ColorStateList.valueOf(accentColor.value!!)
|
||||
}
|
||||
|
||||
}
|
|
@ -7,9 +7,7 @@ import androidx.core.graphics.ColorUtils
|
|||
import com.google.android.material.button.MaterialButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.lifecycleOwner
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedMaterialButton @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -18,7 +16,6 @@ class ThemedMaterialButton @JvmOverloads constructor(
|
|||
) : MaterialButton(context, attributeSet, defStyleAttr) {
|
||||
|
||||
init {
|
||||
setBgColor(context.defPrefs.managerAccent)
|
||||
context.lifecycleOwner()?.let { owner ->
|
||||
accentColor.observe(owner) { color ->
|
||||
setBgColor(color.toInt())
|
||||
|
|
|
@ -5,14 +5,13 @@ import android.content.res.ColorStateList
|
|||
import android.util.AttributeSet
|
||||
import com.google.android.material.checkbox.MaterialCheckBox
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
import com.vanced.manager.utils.accentColor
|
||||
|
||||
class ThemedMaterialCheckbox @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attributeSet: AttributeSet? = null,
|
||||
) : MaterialCheckBox(context, attributeSet, R.attr.checkboxStyle) {
|
||||
init {
|
||||
buttonTintList = ColorStateList.valueOf(context.defPrefs.managerAccent)
|
||||
buttonTintList = ColorStateList.valueOf(accentColor.value!!)
|
||||
}
|
||||
}
|
|
@ -5,14 +5,13 @@ import android.content.res.ColorStateList
|
|||
import android.util.AttributeSet
|
||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
import com.vanced.manager.utils.accentColor
|
||||
|
||||
class ThemedMaterialRadioButton @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attributeSet: AttributeSet? = null,
|
||||
) : MaterialRadioButton(context, attributeSet, R.attr.radioButtonStyle) {
|
||||
init {
|
||||
buttonTintList = ColorStateList.valueOf(context.defPrefs.managerAccent)
|
||||
buttonTintList = ColorStateList.valueOf(accentColor.value!!)
|
||||
}
|
||||
}
|
|
@ -4,8 +4,7 @@ import android.content.Context
|
|||
import android.content.res.ColorStateList
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.slider.Slider
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
import com.vanced.manager.utils.accentColor
|
||||
|
||||
class ThemedMaterialSlider @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -14,7 +13,7 @@ class ThemedMaterialSlider @JvmOverloads constructor(
|
|||
) : Slider(context, attributeSet, defStyleAttr) {
|
||||
|
||||
init {
|
||||
val accentValue = ColorStateList.valueOf(context.defPrefs.managerAccent)
|
||||
val accentValue = ColorStateList.valueOf(accentColor.value!!)
|
||||
thumbTintList = accentValue
|
||||
trackActiveTintList = accentValue
|
||||
trackInactiveTintList = accentValue.withAlpha(70)
|
||||
|
|
|
@ -6,10 +6,7 @@ import android.util.AttributeSet
|
|||
import androidx.core.graphics.ColorUtils
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.lifecycleOwner
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
|
||||
class ThemedOutlinedMaterialButton @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -17,7 +14,6 @@ class ThemedOutlinedMaterialButton @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : MaterialButton(context, attributeSet, defStyleAttr) {
|
||||
init {
|
||||
applyAccent(context.defPrefs.managerAccent)
|
||||
context.lifecycleOwner()?.let { owner ->
|
||||
accentColor.observe(owner) { color ->
|
||||
applyAccent(color.toInt())
|
||||
|
|
|
@ -4,15 +4,14 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
import com.vanced.manager.utils.accentColor
|
||||
|
||||
class ThemedSwipeRefreshlayout @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attributeSet: AttributeSet? = null
|
||||
) : SwipeRefreshLayout(context, attributeSet) {
|
||||
init {
|
||||
setColorSchemeColors(context.defPrefs.managerAccent)
|
||||
setColorSchemeColors(accentColor.value!!)
|
||||
initAttrs(context, attributeSet)
|
||||
}
|
||||
private fun initAttrs(context: Context, attributeSet: AttributeSet?) {
|
||||
|
|
|
@ -9,9 +9,7 @@ import androidx.core.graphics.ColorUtils
|
|||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.lifecycleOwner
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedSwitchCompat @JvmOverloads constructor(
|
||||
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))
|
||||
|
||||
init {
|
||||
setSwitchColors(context.defPrefs.managerAccent)
|
||||
context.lifecycleOwner()?.let { owner ->
|
||||
accentColor.observe(owner) { color ->
|
||||
setSwitchColors(color.toInt())
|
||||
|
|
|
@ -4,9 +4,7 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.lifecycleOwner
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedTextView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -14,7 +12,6 @@ class ThemedTextView @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : AppCompatTextView(context, attributeSet, defStyleAttr) {
|
||||
init {
|
||||
setTextColor(context.defPrefs.managerAccent)
|
||||
context.lifecycleOwner()?.let { owner ->
|
||||
accentColor.observe(owner) { color ->
|
||||
setTextColor(color.toInt())
|
||||
|
|
|
@ -11,7 +11,7 @@ const val LIGHT = "Light"
|
|||
const val DARK = "Dark"
|
||||
const val SYSTEM_DEFAULT = "System Default"
|
||||
|
||||
val mutableAccentColor = MutableLiveData<Int>()
|
||||
val mutableAccentColor = MutableLiveData(defAccentColor)
|
||||
val accentColor: LiveData<Int> = mutableAccentColor
|
||||
|
||||
var currentTheme = ""
|
||||
|
|
Loading…
Reference in a new issue