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
|
@ -19,13 +19,14 @@ import code.name.monkey.appthemehelper.util.VersionUtils
|
|||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
import code.name.monkey.retromusic.util.ThemeManager
|
||||
|
||||
abstract class AbsThemeActivity : ATHActivity(), Runnable {
|
||||
|
||||
private val handler = Handler()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(PreferenceUtil.getInstance(this).generalTheme)
|
||||
setTheme(ThemeManager.getThemeResValue(this))
|
||||
hideStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
//MaterialDialogsUtil.updateMaterialDialogsThemeSingleton(this)
|
||||
|
|
|
@ -46,8 +46,8 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
|
|||
setSummary(it)
|
||||
it.setOnPreferenceChangeListener { _, newValue ->
|
||||
val theme = newValue as String
|
||||
setSummary(generalTheme, newValue)
|
||||
val color = when (theme) {
|
||||
setSummary(it, newValue)
|
||||
/* val color = when (theme) {
|
||||
"light" -> Color.WHITE
|
||||
"black" -> Color.BLACK
|
||||
"dark" -> ContextCompat.getColor(requireContext(), R.color.md_grey_900)
|
||||
|
@ -58,6 +58,7 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
|
|||
.activityTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
||||
.primaryColor(color)
|
||||
.commit()
|
||||
*/
|
||||
|
||||
ThemeStore.markChanged(requireContext())
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -43,12 +43,12 @@
|
|||
<string-array name="pref_general_theme_list_titles">
|
||||
<item>@string/light_theme_name</item>
|
||||
<item>@string/dark_theme_name</item>
|
||||
<item>@string/black_theme_name</item>
|
||||
<item>Automatic</item>
|
||||
</string-array>
|
||||
<string-array name="pref_general_theme_list_values">
|
||||
<item>light</item>
|
||||
<item>dark</item>
|
||||
<item>black</item>
|
||||
<item>auto</item>
|
||||
</string-array>
|
||||
<string-array name="pref_grid_style_list_titles">
|
||||
<item>@string/normal_style</item>
|
||||
|
|
|
@ -14,12 +14,7 @@ open class ATHActivity : AppCompatActivity() {
|
|||
|
||||
private var updateTime: Long = -1
|
||||
|
||||
private val themeRes: Int
|
||||
@StyleRes
|
||||
get() = ThemeStore.activityTheme(this)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(themeRes)
|
||||
super.onCreate(savedInstanceState)
|
||||
updateTime = System.currentTimeMillis()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue