Merge pull request #690 from ologe/feature/theme-fixes

Theme fixes
This commit is contained in:
Hemanth S 2020-04-15 14:17:56 +05:30 committed by GitHub
commit c0e0728aa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 108 additions and 51 deletions

View file

@ -8,6 +8,7 @@ import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.ATH import code.name.monkey.appthemehelper.ATH
import code.name.monkey.appthemehelper.ThemeStore 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.R
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.RetroUtil 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 { abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
private val handler = Handler() private val handler = Handler()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
setTheme(ThemeManager.getThemeResValue(this)) updateTheme()
hideStatusBar() hideStatusBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setImmersiveFullscreen() setImmersiveFullscreen()
@ -34,6 +35,11 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
toggleScreenOn() toggleScreenOn()
} }
private fun updateTheme() {
setTheme(ThemeManager.getThemeResValue(this))
setDefaultNightMode(ThemeManager.getNightMode(this))
}
private fun toggleScreenOn() { private fun toggleScreenOn() {
if (PreferenceUtil.getInstance(this).isScreenOnEnabled) { if (PreferenceUtil.getInstance(this).isScreenOnEnabled) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

View file

@ -127,7 +127,7 @@ public class AlbumGlideRequest {
.asBitmap() .asBitmap()
.transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class) .transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class)
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
.error(DEFAULT_ERROR_IMAGE) .placeholder(DEFAULT_ERROR_IMAGE)
.animate(DEFAULT_ANIMATION) .animate(DEFAULT_ANIMATION)
.signature(createSignature(builder.song)); .signature(createSignature(builder.song));
} }

View file

@ -88,7 +88,7 @@ public class ArtistGlideRequest {
//noinspection unchecked //noinspection unchecked
return createBaseRequest(requestManager, artist, noCustomImage, forceDownload) return createBaseRequest(requestManager, artist, noCustomImage, forceDownload)
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
.error(DEFAULT_ERROR_IMAGE) .placeholder(DEFAULT_ERROR_IMAGE)
.animate(DEFAULT_ANIMATION) .animate(DEFAULT_ANIMATION)
.priority(Priority.LOW) .priority(Priority.LOW)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
@ -124,7 +124,6 @@ public class ArtistGlideRequest {
builder.forceDownload) builder.forceDownload)
.asBitmap() .asBitmap()
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
.error(DEFAULT_ERROR_IMAGE)
.animate(DEFAULT_ANIMATION) .animate(DEFAULT_ANIMATION)
.priority(Priority.LOW) .priority(Priority.LOW)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
@ -151,7 +150,6 @@ public class ArtistGlideRequest {
.transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class) .transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class)
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
.placeholder(DEFAULT_ERROR_IMAGE) .placeholder(DEFAULT_ERROR_IMAGE)
.error(DEFAULT_ERROR_IMAGE)
.animate(DEFAULT_ANIMATION) .animate(DEFAULT_ANIMATION)
.priority(Priority.LOW) .priority(Priority.LOW)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)

View file

@ -102,7 +102,7 @@ public class SongGlideRequest {
//noinspection unchecked //noinspection unchecked
return createBaseRequest(requestManager, song, ignoreMediaStore) return createBaseRequest(requestManager, song, ignoreMediaStore)
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
.error(DEFAULT_ERROR_IMAGE) .placeholder(DEFAULT_ERROR_IMAGE)
.animate(DEFAULT_ANIMATION) .animate(DEFAULT_ANIMATION)
.signature(createSignature(song)); .signature(createSignature(song));
} }
@ -120,7 +120,7 @@ public class SongGlideRequest {
return createBaseRequest(builder.requestManager, builder.song, builder.ignoreMediaStore) return createBaseRequest(builder.requestManager, builder.song, builder.ignoreMediaStore)
.asBitmap() .asBitmap()
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
.error(DEFAULT_ERROR_IMAGE) .placeholder(DEFAULT_ERROR_IMAGE)
.animate(DEFAULT_ANIMATION) .animate(DEFAULT_ANIMATION)
.signature(createSignature(builder.song)); .signature(createSignature(builder.song));
} }
@ -141,7 +141,7 @@ public class SongGlideRequest {
.asBitmap() .asBitmap()
.transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class) .transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class)
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
.error(DEFAULT_ERROR_IMAGE) .placeholder(DEFAULT_ERROR_IMAGE)
.animate(DEFAULT_ANIMATION) .animate(DEFAULT_ANIMATION)
.signature(createSignature(builder.song)); .signature(createSignature(builder.song));
} }

View file

@ -57,6 +57,7 @@ import code.name.monkey.retromusic.transform.HorizontalFlipTransformation;
import code.name.monkey.retromusic.transform.NormalPageTransformer; import code.name.monkey.retromusic.transform.NormalPageTransformer;
import code.name.monkey.retromusic.transform.VerticalFlipTransformation; import code.name.monkey.retromusic.transform.VerticalFlipTransformation;
import code.name.monkey.retromusic.transform.VerticalStackTransformer; import code.name.monkey.retromusic.transform.VerticalStackTransformer;
import code.name.monkey.retromusic.util.theme.ThemeMode;
public final class PreferenceUtil { public final class PreferenceUtil {
@ -527,11 +528,20 @@ public final class PreferenceUtil {
} }
@NonNull @NonNull
public String getGeneralThemeValue() { public ThemeMode getGeneralThemeValue() {
if (isBlackMode()) { if (isBlackMode()) {
return "black"; return ThemeMode.BLACK;
} else { } 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;
}
} }
} }

View file

@ -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
}
}

View file

@ -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

View file

@ -0,0 +1,8 @@
package code.name.monkey.retromusic.util.theme
enum class ThemeMode {
LIGHT,
DARK,
BLACK,
AUTO
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="window_color">@android:color/black</color>
</resources>

View file

@ -16,12 +16,14 @@
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowSharedElementsUseOverlay">false</item> <item name="android:windowSharedElementsUseOverlay">false</item>
<item name="android:textViewStyle">@style/TextViewStyleIm</item> <item name="android:textViewStyle">@style/TextViewStyleIm</item>
<item name="android:windowBackground">@color/window_color_dark</item>
</style> </style>
<style name="Theme.RetroMusic.FollowSystem" parent="Theme.RetroMusic.Base.Adaptive"> <style name="Theme.RetroMusic.FollowSystem" parent="Theme.RetroMusic.Base.Adaptive">
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowSharedElementsUseOverlay">false</item> <item name="android:windowSharedElementsUseOverlay">false</item>
<item name="android:textViewStyle">@style/TextViewStyleIm</item> <item name="android:textViewStyle">@style/TextViewStyleIm</item>
<item name="android:windowBackground">@color/window_color</item>
</style> </style>
<style name="Theme.RetroMusic.Notification" parent="@android:style/TextAppearance.Material.Notification" /> <style name="Theme.RetroMusic.Notification" parent="@android:style/TextAppearance.Material.Notification" />

View file

@ -56,7 +56,7 @@
<item name="android:windowLightNavigationBar">false</item> <item name="android:windowLightNavigationBar">false</item>
<!--Manual setting colors--> <!--Manual setting colors-->
<item name="colorSurface">@color/darkColorSurface</item> <item name="colorSurface">@color/darkColorSurface</item>
<item name="android:windowBackground">@color/window_color_dark</item>
</style> </style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar"> <style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="window_color">@color/md_white_1000</color>
<color name="window_color_light">@color/md_white_1000</color>
<color name="window_color_dark">@android:color/black</color>
<color name="twenty_percent_black_overlay">#34000000</color> <color name="twenty_percent_black_overlay">#34000000</color>
<color name="eighty_percent_black_overlay">#80000000</color> <color name="eighty_percent_black_overlay">#80000000</color>
<color name="app_shortcut_default_foreground">#607d8b</color> <color name="app_shortcut_default_foreground">#607d8b</color>

View file

@ -2,11 +2,17 @@
<style name="Theme.RetroMusic" parent="Theme.RetroMusic.Base" /> <style name="Theme.RetroMusic" parent="Theme.RetroMusic.Base" />
<style name="Theme.RetroMusic.Light" parent="Theme.RetroMusic.Base.Light" /> <style name="Theme.RetroMusic.Light" parent="Theme.RetroMusic.Base.Light" >
<item name="android:windowBackground">@color/window_color_light</item>
</style>
<style name="Theme.RetroMusic.Black" parent="Theme.RetroMusic.Base.Black" /> <style name="Theme.RetroMusic.Black" parent="Theme.RetroMusic.Base.Black" >
<item name="android:windowBackground">@color/window_color_dark</item>
</style>
<style name="Theme.RetroMusic.FollowSystem" parent="Theme.RetroMusic.Base.Adaptive" /> <style name="Theme.RetroMusic.FollowSystem" parent="Theme.RetroMusic.Base.Adaptive" >
<item name="android:windowBackground">@color/window_color</item>
</style>
<style name="Theme.RetroMusic.Notification" parent="@android:style/TextAppearance.StatusBar.EventContent" /> <style name="Theme.RetroMusic.Notification" parent="@android:style/TextAppearance.StatusBar.EventContent" />

View file

@ -41,6 +41,7 @@
<!--Manual setting colors--> <!--Manual setting colors-->
<item name="colorSurface">@color/darkColorSurface</item> <item name="colorSurface">@color/darkColorSurface</item>
<item name="android:windowBackground">@color/window_color_dark</item>
</style> </style>