From 01814d8b313abf7c53abb9691493f86ababe4d46 Mon Sep 17 00:00:00 2001 From: Eugeniu Olog Date: Tue, 17 Mar 2020 21:10:36 +0100 Subject: [PATCH 1/2] - fixed fade animation color on dark mode (was always white) --- .../activities/base/AbsThemeActivity.kt | 10 +++- .../retromusic/util/PreferenceUtil.java | 16 ++++-- .../monkey/retromusic/util/ThemeManager.kt | 35 ------------- .../retromusic/util/theme/ThemeManager.kt | 50 +++++++++++++++++++ .../monkey/retromusic/util/theme/ThemeMode.kt | 8 +++ app/src/main/res/values-night/colors.xml | 6 +++ app/src/main/res/values-v21/styles.xml | 2 + .../main/res/values-v27/styles_parents.xml | 2 +- app/src/main/res/values/colors.xml | 5 ++ app/src/main/res/values/styles.xml | 12 +++-- app/src/main/res/values/styles_parents.xml | 1 + 11 files changed, 103 insertions(+), 44 deletions(-) delete mode 100644 app/src/main/java/code/name/monkey/retromusic/util/ThemeManager.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/util/theme/ThemeManager.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/util/theme/ThemeMode.kt create mode 100644 app/src/main/res/values-night/colors.xml diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt index 74bf61c5..24ca4b90 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt @@ -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) diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java index 5ed9fb34..924e9699 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java @@ -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; + } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/ThemeManager.kt b/app/src/main/java/code/name/monkey/retromusic/util/ThemeManager.kt deleted file mode 100644 index 4eaa224b..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/util/ThemeManager.kt +++ /dev/null @@ -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 - } - -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/util/theme/ThemeManager.kt b/app/src/main/java/code/name/monkey/retromusic/util/theme/ThemeManager.kt new file mode 100644 index 00000000..542fdbe5 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/util/theme/ThemeManager.kt @@ -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 \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/util/theme/ThemeMode.kt b/app/src/main/java/code/name/monkey/retromusic/util/theme/ThemeMode.kt new file mode 100644 index 00000000..88086741 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/util/theme/ThemeMode.kt @@ -0,0 +1,8 @@ +package code.name.monkey.retromusic.util.theme + +enum class ThemeMode { + LIGHT, + DARK, + BLACK, + AUTO +} \ No newline at end of file diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml new file mode 100644 index 00000000..9a919933 --- /dev/null +++ b/app/src/main/res/values-night/colors.xml @@ -0,0 +1,6 @@ + + + + @android:color/black + + \ No newline at end of file diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index e512f372..57d3cb48 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -16,12 +16,14 @@ @android:color/transparent false @style/TextViewStyleIm + @color/window_color_dark - - From 2c8574de4888d91983793312ac813fafab66d08b Mon Sep 17 00:00:00 2001 From: Eugeniu Olog Date: Tue, 17 Mar 2020 21:16:59 +0100 Subject: [PATCH 2/2] fix: placeholders was not shown during scrolling --- .../name/monkey/retromusic/glide/AlbumGlideRequest.java | 2 +- .../name/monkey/retromusic/glide/ArtistGlideRequest.java | 4 +--- .../code/name/monkey/retromusic/glide/SongGlideRequest.java | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/AlbumGlideRequest.java b/app/src/main/java/code/name/monkey/retromusic/glide/AlbumGlideRequest.java index aed589d3..8add6312 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/AlbumGlideRequest.java +++ b/app/src/main/java/code/name/monkey/retromusic/glide/AlbumGlideRequest.java @@ -127,7 +127,7 @@ public class AlbumGlideRequest { .asBitmap() .transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) - .error(DEFAULT_ERROR_IMAGE) + .placeholder(DEFAULT_ERROR_IMAGE) .animate(DEFAULT_ANIMATION) .signature(createSignature(builder.song)); } diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/ArtistGlideRequest.java b/app/src/main/java/code/name/monkey/retromusic/glide/ArtistGlideRequest.java index 175c3442..abc5d3f3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/ArtistGlideRequest.java +++ b/app/src/main/java/code/name/monkey/retromusic/glide/ArtistGlideRequest.java @@ -88,7 +88,7 @@ public class ArtistGlideRequest { //noinspection unchecked return createBaseRequest(requestManager, artist, noCustomImage, forceDownload) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) - .error(DEFAULT_ERROR_IMAGE) + .placeholder(DEFAULT_ERROR_IMAGE) .animate(DEFAULT_ANIMATION) .priority(Priority.LOW) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) @@ -124,7 +124,6 @@ public class ArtistGlideRequest { builder.forceDownload) .asBitmap() .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) - .error(DEFAULT_ERROR_IMAGE) .animate(DEFAULT_ANIMATION) .priority(Priority.LOW) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) @@ -151,7 +150,6 @@ public class ArtistGlideRequest { .transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) .placeholder(DEFAULT_ERROR_IMAGE) - .error(DEFAULT_ERROR_IMAGE) .animate(DEFAULT_ANIMATION) .priority(Priority.LOW) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/SongGlideRequest.java b/app/src/main/java/code/name/monkey/retromusic/glide/SongGlideRequest.java index acc90640..f95d13b5 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/SongGlideRequest.java +++ b/app/src/main/java/code/name/monkey/retromusic/glide/SongGlideRequest.java @@ -102,7 +102,7 @@ public class SongGlideRequest { //noinspection unchecked return createBaseRequest(requestManager, song, ignoreMediaStore) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) - .error(DEFAULT_ERROR_IMAGE) + .placeholder(DEFAULT_ERROR_IMAGE) .animate(DEFAULT_ANIMATION) .signature(createSignature(song)); } @@ -120,7 +120,7 @@ public class SongGlideRequest { return createBaseRequest(builder.requestManager, builder.song, builder.ignoreMediaStore) .asBitmap() .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) - .error(DEFAULT_ERROR_IMAGE) + .placeholder(DEFAULT_ERROR_IMAGE) .animate(DEFAULT_ANIMATION) .signature(createSignature(builder.song)); } @@ -141,7 +141,7 @@ public class SongGlideRequest { .asBitmap() .transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class) .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY) - .error(DEFAULT_ERROR_IMAGE) + .placeholder(DEFAULT_ERROR_IMAGE) .animate(DEFAULT_ANIMATION) .signature(createSignature(builder.song)); }