Dynamic colors [1/2]
This commit is contained in:
@@ -38,11 +38,9 @@ import android.view.LayoutInflater
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.app.ActivityOptionsCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.util.Preferences
|
||||
|
||||
private const val TAG = "Context"
|
||||
|
||||
@@ -115,44 +113,6 @@ fun Context.getStyledAttributeColor(id: Int): Int {
|
||||
return styledAttr
|
||||
}
|
||||
|
||||
fun Context.accentColor(): Int {
|
||||
val color = when (Preferences.getInteger(this, Preferences.PREFERENCE_THEME_ACCENT)) {
|
||||
0 -> R.color.colorAccent
|
||||
1 -> R.color.colorAccent01
|
||||
2 -> R.color.colorAccent02
|
||||
3 -> R.color.colorAccent03
|
||||
4 -> R.color.colorAccent04
|
||||
5 -> R.color.colorAccent05
|
||||
6 -> R.color.colorAccent06
|
||||
7 -> R.color.colorAccent07
|
||||
8 -> R.color.colorAccent08
|
||||
9 -> R.color.colorAccent09
|
||||
10 -> R.color.colorAccent10
|
||||
11 -> R.color.colorAccent11
|
||||
12 -> R.color.colorAccent12
|
||||
13 -> R.color.colorAccent13
|
||||
else -> if (isSAndAbove()) R.color.colorAccent else R.color.colorAccent01
|
||||
}
|
||||
return ContextCompat.getColor(this, color)
|
||||
}
|
||||
|
||||
fun Context.backgroundColor(): Int {
|
||||
val color = when (Preferences.getInteger(this, Preferences.PREFERENCE_THEME_TYPE)) {
|
||||
1 -> R.color.colorWhite
|
||||
2 -> R.color.colorDarkBackground
|
||||
3 -> R.color.colorBlack
|
||||
4 -> R.color.colorDarkXBackground
|
||||
5 -> R.color.colorDarkordBackground
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (color == null) {
|
||||
return getStyledAttributeColor(com.google.android.material.R.attr.colorSurface)
|
||||
}
|
||||
|
||||
return ContextCompat.getColor(this, color)
|
||||
}
|
||||
|
||||
fun Context.isIgnoringBatteryOptimizations(): Boolean {
|
||||
return if (isMAndAbove()) {
|
||||
(getSystemService(Context.POWER_SERVICE) as PowerManager).isIgnoringBatteryOptimizations(
|
||||
|
||||
@@ -19,56 +19,10 @@
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.app.UiModeManager
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import com.aurora.store.util.CommonUtil
|
||||
import com.aurora.store.util.Preferences
|
||||
|
||||
fun AppCompatActivity.applyThemeAccent() {
|
||||
val themeId = Preferences.getInteger(this, Preferences.PREFERENCE_THEME_TYPE)
|
||||
val accentId = Preferences.getInteger(this, Preferences.PREFERENCE_THEME_ACCENT)
|
||||
val uiModeManager = getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
||||
|
||||
val themeStyle = CommonUtil.getThemeStyleById(themeId)
|
||||
val accentStyle = CommonUtil.getAccentStyleById(accentId)
|
||||
|
||||
/*Apply Theme*/
|
||||
setTheme(themeStyle)
|
||||
theme.applyStyle(accentStyle, true)
|
||||
|
||||
when (themeId) {
|
||||
0 -> {
|
||||
if (isSAndAbove()) {
|
||||
uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_CUSTOM)
|
||||
} else {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
}
|
||||
}
|
||||
|
||||
1 -> {
|
||||
if (!isVAndAbove()) setSystemBarConfiguration(light = true)
|
||||
if (isSAndAbove()) {
|
||||
uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_NO)
|
||||
} else {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
if (!isVAndAbove()) setSystemBarConfiguration(light = false)
|
||||
if (isSAndAbove()) {
|
||||
uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_YES)
|
||||
} else {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun AppCompatActivity.setSystemBarConfiguration(light: Boolean) {
|
||||
|
||||
@@ -20,10 +20,8 @@
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
|
||||
fun View.isVisible() = visibility == View.VISIBLE
|
||||
|
||||
@@ -84,10 +82,3 @@ fun View.flip(resetToZero: Boolean = true, duration: Long = 400) {
|
||||
fun View.getString(resourceId: Int): String {
|
||||
return context.getString(resourceId)
|
||||
}
|
||||
|
||||
fun FloatingActionButton.applyColors() {
|
||||
val accentColor = context.accentColor()
|
||||
backgroundTintList = ColorStateList.valueOf(accentColor)
|
||||
imageTintList = ColorStateList.valueOf(contrastingColor(accentColor))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user