mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
style: simplify ThemeHelper#getThemeColor
This commit is contained in:
parent
3f095da89f
commit
dbb7126dfb
@ -5,6 +5,7 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.text.Spanned
|
||||
import android.util.TypedValue
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -15,6 +16,7 @@ import com.github.libretube.R
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.ui.adapters.IconsSheetAdapter
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import com.google.android.material.color.MaterialColors
|
||||
|
||||
object ThemeHelper {
|
||||
|
||||
@ -114,13 +116,9 @@ object ThemeHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a color by a resource code
|
||||
* Get a color by a color resource attr
|
||||
*/
|
||||
fun getThemeColor(context: Context, colorCode: Int): Int {
|
||||
val value = TypedValue()
|
||||
context.theme.resolveAttribute(colorCode, value, true)
|
||||
return value.data
|
||||
}
|
||||
fun getThemeColor(context: Context, colorCode: Int) = MaterialColors.getColor(context, colorCode, Color.TRANSPARENT)
|
||||
|
||||
/**
|
||||
* Get the styled app name
|
||||
|
@ -9,7 +9,6 @@ import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import com.github.libretube.db.DatabaseHolder.Database
|
||||
import com.github.libretube.helpers.ThemeHelper
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
/**
|
||||
@ -21,15 +20,12 @@ fun View.setWatchProgressLength(videoId: String, duration: Long) {
|
||||
updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
matchConstraintPercentWidth = 0f
|
||||
}
|
||||
var backgroundColor = MaterialColors.getColor(
|
||||
this,
|
||||
var backgroundColor = ThemeHelper.getThemeColor(
|
||||
context,
|
||||
com.google.android.material.R.attr.colorPrimaryDark
|
||||
)
|
||||
// increase the brightness for better contrast in light mode
|
||||
if (!ThemeHelper.isDarkMode(
|
||||
context
|
||||
)
|
||||
) {
|
||||
if (!ThemeHelper.isDarkMode(context)) {
|
||||
backgroundColor = ColorUtils.blendARGB(backgroundColor, Color.WHITE, 0.4f)
|
||||
}
|
||||
setBackgroundColor(backgroundColor)
|
||||
|
Loading…
x
Reference in New Issue
Block a user