32 lines
1.0 KiB
Kotlin
32 lines
1.0 KiB
Kotlin
package com.vanced.manager.ui.core
|
|
|
|
import android.content.Context
|
|
import android.content.res.ColorStateList
|
|
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,
|
|
attributeSet: AttributeSet? = null,
|
|
defStyleAttr: Int = 0
|
|
) : MaterialButton(context, attributeSet, defStyleAttr) {
|
|
init {
|
|
applyAccent(context.defPrefs.managerAccent)
|
|
context.lifecycleOwner()?.let { owner ->
|
|
accentColor.observe(owner) { color ->
|
|
applyAccent(color.toInt())
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun applyAccent(color: Int) {
|
|
setTextColor(color)
|
|
rippleColor = ColorStateList(arrayOf(intArrayOf()), intArrayOf(ColorUtils.setAlphaComponent(color, 50)))
|
|
}
|
|
} |