2020-06-19 15:48:14 +00:00
|
|
|
package com.vanced.manager.utils
|
|
|
|
|
2020-07-05 12:49:35 +00:00
|
|
|
import android.app.Activity
|
2020-06-19 15:48:14 +00:00
|
|
|
import android.content.res.Configuration
|
|
|
|
import com.vanced.manager.R
|
2020-11-05 18:26:27 +00:00
|
|
|
import com.vanced.manager.utils.Extensions.getDefaultPrefs
|
2020-06-19 15:48:14 +00:00
|
|
|
|
|
|
|
object ThemeHelper {
|
|
|
|
|
2020-11-05 18:26:27 +00:00
|
|
|
fun Activity.setFinalTheme() {
|
|
|
|
val prefs = getDefaultPrefs()
|
|
|
|
val currentAccent = prefs.getString("manager_accent", "Blue")
|
|
|
|
when (prefs.getString("manager_theme", "System Default")) {
|
|
|
|
"Light" -> setTheme(getLightAccent(currentAccent))
|
|
|
|
"Dark" -> setTheme(getDarkAccent(currentAccent))
|
2020-10-31 19:45:39 +00:00
|
|
|
"System Default" -> {
|
2020-11-05 18:26:27 +00:00
|
|
|
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
|
|
|
Configuration.UI_MODE_NIGHT_YES -> setTheme(getDarkAccent(currentAccent))
|
|
|
|
Configuration.UI_MODE_NIGHT_NO -> setTheme(getLightAccent(currentAccent))
|
2020-06-19 15:48:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-05 18:26:27 +00:00
|
|
|
else -> setTheme(getLightAccent("Blue"))
|
2020-06-19 15:48:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 06:35:04 +00:00
|
|
|
private fun getDarkAccent(accentColor: String?): Int {
|
|
|
|
return when (accentColor) {
|
|
|
|
"Blue" -> R.style.DarkTheme_Blue
|
|
|
|
"Red" -> R.style.DarkTheme_Red
|
|
|
|
"Green" -> R.style.DarkTheme_Green
|
|
|
|
"Yellow" -> R.style.DarkTheme_Yellow
|
|
|
|
"Purple" -> R.style.DarkTheme_Purple
|
|
|
|
else -> R.style.DarkTheme_Blue
|
2020-06-19 15:48:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 06:35:04 +00:00
|
|
|
private fun getLightAccent(accentColor: String?): Int {
|
|
|
|
return when (accentColor) {
|
|
|
|
"Blue" -> R.style.LightTheme_Blue
|
|
|
|
"Red" -> R.style.LightTheme_Red
|
|
|
|
"Green" -> R.style.LightTheme_Green
|
|
|
|
"Yellow" -> R.style.LightTheme_Yellow
|
|
|
|
"Purple" -> R.style.LightTheme_Purple
|
|
|
|
else -> R.style.LightTheme_Blue
|
2020-06-19 15:48:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|