Dynamic colors [1/2]
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user