Add support for Android 10 dark theme.
This is still untested please take a look.
This commit is contained in:
parent
df7cb7ab49
commit
752843a497
6 changed files with 48 additions and 12 deletions
|
@ -157,8 +157,9 @@ public final class PreferenceUtil {
|
|||
switch (themePrefValue) {
|
||||
case "light":
|
||||
return R.style.Theme_RetroMusic_Light;
|
||||
case "black":
|
||||
return R.style.Theme_RetroMusic_Black;
|
||||
/* Drop black theme as of now, you may want to add a toggle for that later
|
||||
case "black":
|
||||
return R.style.Theme_RetroMusic_Black;*/
|
||||
case "dark":
|
||||
default:
|
||||
return R.style.Theme_RetroMusic;
|
||||
|
@ -558,6 +559,10 @@ public final class PreferenceUtil {
|
|||
return getThemeResFromPrefValue(mPreferences.getString(GENERAL_THEME, "dark"));
|
||||
}
|
||||
|
||||
public String getGeneralThemeValue() {
|
||||
return mPreferences.getString(GENERAL_THEME, "dark");
|
||||
}
|
||||
|
||||
public void setGeneralTheme(String theme) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(GENERAL_THEME, theme);
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package code.name.monkey.retromusic.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_MASK
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
import android.os.PowerManager
|
||||
import androidx.annotation.StyleRes
|
||||
import code.name.monkey.retromusic.R
|
||||
|
||||
/**
|
||||
* @author Paolo Valerdi
|
||||
*/
|
||||
object ThemeManager {
|
||||
|
||||
@StyleRes
|
||||
fun getThemeResValue(context: Context): Int = when(PreferenceUtil.getInstance(context).generalThemeValue) {
|
||||
"light" -> R.style.Theme_RetroMusic_Light
|
||||
"auto" -> if (isSystemDarkModeEnabled(context)) R.style.Theme_RetroMusic else R.style.Theme_RetroMusic_Light
|
||||
else -> R.style.Theme_RetroMusic
|
||||
/**
|
||||
* To add a toggle for amoled theme just add an if statement such as
|
||||
* if(PreferenceUtil.getInstance(context).useAmoled) blablabla
|
||||
*/
|
||||
}
|
||||
|
||||
fun isSystemDarkModeEnabled(context: Context): Boolean {
|
||||
val isBatterySaverEnabled = (context.getSystemService(Context.POWER_SERVICE) as PowerManager?)?.isPowerSaveMode ?: false
|
||||
val isDarkModeEnabled = (context.resources.configuration.uiMode and UI_MODE_NIGHT_MASK) == UI_MODE_NIGHT_YES
|
||||
|
||||
return isBatterySaverEnabled or isDarkModeEnabled
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue