mirror of
https://github.com/Michatec/Radio.git
synced 2026-03-31 23:46:28 +02:00
60 lines
2.3 KiB
Kotlin
60 lines
2.3 KiB
Kotlin
package com.michatec.radio.helpers
|
|
|
|
import android.content.Context
|
|
import android.util.Log
|
|
import androidx.appcompat.app.AppCompatDelegate
|
|
import com.michatec.radio.Keys
|
|
import com.michatec.radio.R
|
|
|
|
|
|
/*
|
|
* AppThemeHelper object
|
|
*/
|
|
object AppThemeHelper {
|
|
|
|
/* Define log tag */
|
|
private val TAG: String = AppThemeHelper::class.java.simpleName
|
|
|
|
/* Sets app theme */
|
|
fun setTheme(nightModeState: String) {
|
|
when (nightModeState) {
|
|
Keys.STATE_THEME_DARK_MODE -> {
|
|
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) {
|
|
// turn on dark mode
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
|
Log.i(TAG, "Dark Mode activated.")
|
|
}
|
|
}
|
|
Keys.STATE_THEME_LIGHT_MODE -> {
|
|
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_NO) {
|
|
// turn on light mode
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
|
Log.i(TAG, "Theme: Light Mode activated.")
|
|
}
|
|
}
|
|
Keys.STATE_THEME_FOLLOW_SYSTEM -> {
|
|
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) {
|
|
// turn on mode "follow system"
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
|
Log.i(TAG, "Theme: Follow System Mode activated.")
|
|
}
|
|
}
|
|
else -> {
|
|
// turn on mode "follow system"
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
|
Log.i(TAG, "Theme: Follow System Mode activated.")
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* Returns a readable String for currently selected App Theme */
|
|
fun getCurrentTheme(context: Context): String {
|
|
return when (PreferencesHelper.loadThemeSelection()) {
|
|
Keys.STATE_THEME_LIGHT_MODE -> context.getString(R.string.pref_theme_selection_mode_light)
|
|
Keys.STATE_THEME_DARK_MODE -> context.getString(R.string.pref_theme_selection_mode_dark)
|
|
else -> context.getString(R.string.pref_theme_selection_mode_device_default)
|
|
}
|
|
}
|
|
}
|