- fixed fade animation color on dark mode (was always white)
This commit is contained in:
parent
c6fc672cd1
commit
01814d8b31
11 changed files with 103 additions and 44 deletions
|
@ -8,6 +8,7 @@ import android.view.KeyEvent
|
|||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode
|
||||
import androidx.core.content.ContextCompat
|
||||
import code.name.monkey.appthemehelper.ATH
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
|
@ -19,14 +20,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
|
||||
import code.name.monkey.retromusic.util.theme.ThemeManager
|
||||
|
||||
abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
|
||||
|
||||
private val handler = Handler()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(ThemeManager.getThemeResValue(this))
|
||||
updateTheme()
|
||||
hideStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
setImmersiveFullscreen()
|
||||
|
@ -34,6 +35,11 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
|
|||
toggleScreenOn()
|
||||
}
|
||||
|
||||
private fun updateTheme() {
|
||||
setTheme(ThemeManager.getThemeResValue(this))
|
||||
setDefaultNightMode(ThemeManager.getNightMode(this))
|
||||
}
|
||||
|
||||
private fun toggleScreenOn() {
|
||||
if (PreferenceUtil.getInstance(this).isScreenOnEnabled) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
|
|
@ -57,6 +57,7 @@ import code.name.monkey.retromusic.transform.HorizontalFlipTransformation;
|
|||
import code.name.monkey.retromusic.transform.NormalPageTransformer;
|
||||
import code.name.monkey.retromusic.transform.VerticalFlipTransformation;
|
||||
import code.name.monkey.retromusic.transform.VerticalStackTransformer;
|
||||
import code.name.monkey.retromusic.util.theme.ThemeMode;
|
||||
|
||||
public final class PreferenceUtil {
|
||||
|
||||
|
@ -527,11 +528,20 @@ public final class PreferenceUtil {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public String getGeneralThemeValue() {
|
||||
public ThemeMode getGeneralThemeValue() {
|
||||
if (isBlackMode()) {
|
||||
return "black";
|
||||
return ThemeMode.BLACK;
|
||||
} else {
|
||||
return mPreferences.getString(GENERAL_THEME, "dark");
|
||||
String themeMode = mPreferences.getString(GENERAL_THEME, "dark");
|
||||
switch (themeMode) {
|
||||
case "light":
|
||||
return ThemeMode.LIGHT;
|
||||
case "dark":
|
||||
return ThemeMode.DARK;
|
||||
case "auto":
|
||||
default:
|
||||
return ThemeMode.AUTO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
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
|
||||
"dark" -> R.style.Theme_RetroMusic_Base
|
||||
"auto" -> R.style.Theme_RetroMusic_FollowSystem
|
||||
"black" -> R.style.Theme_RetroMusic_Black
|
||||
else -> R.style.Theme_RetroMusic_FollowSystem
|
||||
}
|
||||
|
||||
private 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
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package code.name.monkey.retromusic.util.theme
|
||||
|
||||
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 androidx.appcompat.app.AppCompatDelegate
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.theme.ThemeMode.*
|
||||
|
||||
/**
|
||||
* @author Paolo Valerdi
|
||||
*/
|
||||
object ThemeManager {
|
||||
|
||||
@StyleRes
|
||||
fun getThemeResValue(
|
||||
context: Context
|
||||
): Int = when (context.generalThemeValue) {
|
||||
LIGHT -> R.style.Theme_RetroMusic_Light
|
||||
DARK -> R.style.Theme_RetroMusic_Base
|
||||
BLACK -> R.style.Theme_RetroMusic_Black
|
||||
AUTO -> R.style.Theme_RetroMusic_FollowSystem
|
||||
}
|
||||
|
||||
fun getNightMode(
|
||||
context: Context
|
||||
): Int = when (context.generalThemeValue) {
|
||||
LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
DARK,
|
||||
BLACK -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
AUTO -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
|
||||
private 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val Context.generalThemeValue: ThemeMode
|
||||
get() = PreferenceUtil.getInstance(this).generalThemeValue
|
|
@ -0,0 +1,8 @@
|
|||
package code.name.monkey.retromusic.util.theme
|
||||
|
||||
enum class ThemeMode {
|
||||
LIGHT,
|
||||
DARK,
|
||||
BLACK,
|
||||
AUTO
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue