mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-11 01:13:46 +01:00
Cleanup and format
This commit is contained in:
parent
68dd206140
commit
f1f1613f00
@ -46,6 +46,9 @@ object ThemeUtils {
|
|||||||
private const val THEME_LIGHT_VALUE = "light"
|
private const val THEME_LIGHT_VALUE = "light"
|
||||||
private const val THEME_BLACK_VALUE = "black"
|
private const val THEME_BLACK_VALUE = "black"
|
||||||
|
|
||||||
|
// The default theme
|
||||||
|
private const val DEFAULT_THEME = SYSTEM_THEME_VALUE
|
||||||
|
|
||||||
private var currentTheme = AtomicReference<String>(null)
|
private var currentTheme = AtomicReference<String>(null)
|
||||||
|
|
||||||
private val mColorByAttr = HashMap<Int, Int>()
|
private val mColorByAttr = HashMap<Int, Int>()
|
||||||
@ -57,11 +60,12 @@ object ThemeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if current theme is Light/Status or current theme is System and system theme is light
|
* @return true if current theme is Light or current theme is System and system theme is light
|
||||||
*/
|
*/
|
||||||
fun isLightTheme(context: Context): Boolean {
|
fun isLightTheme(context: Context): Boolean {
|
||||||
val theme = getApplicationTheme(context)
|
val theme = getApplicationTheme(context)
|
||||||
return theme == THEME_LIGHT_VALUE || (theme == SYSTEM_THEME_VALUE && !isSystemDarkTheme(context.resources))
|
return theme == THEME_LIGHT_VALUE
|
||||||
|
|| (theme == SYSTEM_THEME_VALUE && !isSystemDarkTheme(context.resources))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,11 +78,11 @@ object ThemeUtils {
|
|||||||
val currentTheme = this.currentTheme.get()
|
val currentTheme = this.currentTheme.get()
|
||||||
return if (currentTheme == null) {
|
return if (currentTheme == null) {
|
||||||
val prefs = DefaultSharedPreferences.getInstance(context)
|
val prefs = DefaultSharedPreferences.getInstance(context)
|
||||||
var themeFromPref = prefs.getString(APPLICATION_THEME_KEY, SYSTEM_THEME_VALUE) ?: SYSTEM_THEME_VALUE
|
var themeFromPref = prefs.getString(APPLICATION_THEME_KEY, DEFAULT_THEME) ?: DEFAULT_THEME
|
||||||
if (themeFromPref == "status") {
|
if (themeFromPref == "status") {
|
||||||
// Migrate to light theme, which is the closest theme
|
// Migrate to the default theme
|
||||||
themeFromPref = SYSTEM_THEME_VALUE
|
themeFromPref = DEFAULT_THEME
|
||||||
prefs.edit { putString(APPLICATION_THEME_KEY, SYSTEM_THEME_VALUE) }
|
prefs.edit { putString(APPLICATION_THEME_KEY, DEFAULT_THEME) }
|
||||||
}
|
}
|
||||||
this.currentTheme.set(themeFromPref)
|
this.currentTheme.set(themeFromPref)
|
||||||
themeFromPref
|
themeFromPref
|
||||||
@ -101,12 +105,14 @@ object ThemeUtils {
|
|||||||
*/
|
*/
|
||||||
fun setApplicationTheme(context: Context, aTheme: String) {
|
fun setApplicationTheme(context: Context, aTheme: String) {
|
||||||
currentTheme.set(aTheme)
|
currentTheme.set(aTheme)
|
||||||
when (aTheme) {
|
context.setTheme(
|
||||||
SYSTEM_THEME_VALUE -> context.setTheme(if (isSystemDarkTheme(context.resources)) R.style.AppTheme_Dark else R.style.AppTheme_Light)
|
when (aTheme) {
|
||||||
THEME_DARK_VALUE -> context.setTheme(R.style.AppTheme_Dark)
|
SYSTEM_THEME_VALUE -> if (isSystemDarkTheme(context.resources)) R.style.AppTheme_Dark else R.style.AppTheme_Light
|
||||||
THEME_BLACK_VALUE -> context.setTheme(R.style.AppTheme_Black)
|
THEME_DARK_VALUE -> R.style.AppTheme_Dark
|
||||||
else -> context.setTheme(R.style.AppTheme_Light)
|
THEME_BLACK_VALUE -> R.style.AppTheme_Black
|
||||||
}
|
else -> R.style.AppTheme_Light
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// Clear the cache
|
// Clear the cache
|
||||||
mColorByAttr.clear()
|
mColorByAttr.clear()
|
||||||
@ -127,40 +133,6 @@ object ThemeUtils {
|
|||||||
mColorByAttr.clear()
|
mColorByAttr.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the TabLayout colors.
|
|
||||||
* It seems that there is no proper way to manage it with the manifest file.
|
|
||||||
*
|
|
||||||
* @param activity the activity
|
|
||||||
* @param layout the layout
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
fun setTabLayoutTheme(activity: Activity, layout: TabLayout) {
|
|
||||||
if (activity is VectorGroupDetailsActivity) {
|
|
||||||
val textColor: Int
|
|
||||||
val underlineColor: Int
|
|
||||||
val backgroundColor: Int
|
|
||||||
|
|
||||||
if (TextUtils.equals(getApplicationTheme(activity), THEME_LIGHT_VALUE)) {
|
|
||||||
textColor = ContextCompat.getColor(activity, android.R.color.white)
|
|
||||||
underlineColor = textColor
|
|
||||||
backgroundColor = ContextCompat.getColor(activity, R.color.tab_groups)
|
|
||||||
} else if (TextUtils.equals(getApplicationTheme(activity), THEME_STATUS_VALUE)) {
|
|
||||||
textColor = ContextCompat.getColor(activity, android.R.color.white)
|
|
||||||
underlineColor = textColor
|
|
||||||
backgroundColor = getColor(activity, R.attr.colorPrimary)
|
|
||||||
} else {
|
|
||||||
textColor = ContextCompat.getColor(activity, R.color.tab_groups)
|
|
||||||
underlineColor = textColor
|
|
||||||
backgroundColor = getColor(activity, R.attr.colorPrimary)
|
|
||||||
}
|
|
||||||
|
|
||||||
layout.setTabTextColors(textColor, textColor)
|
|
||||||
layout.setSelectedTabIndicatorColor(underlineColor)
|
|
||||||
layout.setBackgroundColor(backgroundColor)
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates color attributes to colors
|
* Translates color attributes to colors
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user