PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt

80 lines
2.9 KiB
Kotlin
Raw Normal View History

/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.extensions
2020-05-20 20:28:38 +00:00
import android.app.Dialog
2019-12-01 15:27:01 +00:00
import android.content.Context
2019-12-16 05:06:08 +00:00
import android.content.res.ColorStateList
2019-12-01 15:27:01 +00:00
import android.graphics.Color
2020-05-23 21:47:23 +00:00
import android.widget.CheckBox
import android.widget.SeekBar
2020-05-20 20:28:38 +00:00
import androidx.annotation.AttrRes
2019-12-16 05:06:08 +00:00
import androidx.appcompat.widget.Toolbar
2020-05-20 20:28:38 +00:00
import androidx.fragment.app.Fragment
2020-05-20 10:14:49 +00:00
import code.name.monkey.appthemehelper.ThemeStore
2019-12-01 15:27:01 +00:00
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil
2019-12-01 15:27:01 +00:00
import code.name.monkey.retromusic.R
fun Int.ripAlpha(): Int {
return ColorUtil.stripAlpha(this)
2019-12-01 15:27:01 +00:00
}
2020-05-20 20:28:38 +00:00
fun Dialog.colorControlNormal() = resolveColor(android.R.attr.colorControlNormal)
2019-12-16 05:06:08 +00:00
fun Toolbar.backgroundTintList() {
val surfaceColor = ATHUtil.resolveColor(context, R.attr.colorSurface, Color.BLACK)
val colorStateList = ColorStateList.valueOf(surfaceColor)
backgroundTintList = colorStateList
2020-02-22 12:10:12 +00:00
}
2020-05-20 20:28:38 +00:00
fun Context.accentColor() = ThemeStore.accentColor(this)
2020-02-22 12:10:12 +00:00
2020-05-20 20:28:38 +00:00
fun Fragment.accentColor() = ThemeStore.accentColor(requireContext())
fun Context.surfaceColor() = resolveColor(R.attr.colorSurface, Color.WHITE)
fun Fragment.surfaceColor() = resolveColor(R.attr.colorSurface, Color.WHITE)
fun Context.textColorSecondary() = resolveColor(android.R.attr.textColorSecondary)
fun Fragment.textColorSecondary() = resolveColor(android.R.attr.textColorSecondary)
fun Context.colorControlNormal() = resolveColor(android.R.attr.colorControlNormal)
fun Fragment.colorControlNormal() = resolveColor(android.R.attr.colorControlNormal)
fun Context.textColorPrimary() = resolveColor(android.R.attr.textColorPrimary)
fun Fragment.textColorPrimary() = resolveColor(android.R.attr.textColorPrimary)
fun Context.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
ATHUtil.resolveColor(this, attr, fallBackColor)
fun Fragment.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
ATHUtil.resolveColor(requireContext(), attr, fallBackColor)
2020-02-22 12:10:12 +00:00
2020-05-20 20:28:38 +00:00
fun Dialog.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
ATHUtil.resolveColor(context, attr, fallBackColor)
2020-05-23 21:47:23 +00:00
fun CheckBox.addAccentColor() {
buttonTintList = ColorStateList.valueOf(ThemeStore.accentColor(context))
}
fun SeekBar.addAccentColor() {
val colorState = ColorStateList.valueOf(ThemeStore.accentColor(context))
progressTintList = colorState
thumbTintList = colorState
}