Dynamic colors [1/2]

This commit is contained in:
Rahul Patel
2024-08-31 02:33:07 +05:30
parent 4107eed2d9
commit 3546ed8a54
119 changed files with 676 additions and 2321 deletions

View File

@@ -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) {