Fixing bugs

This commit is contained in:
h4h13 2019-09-28 23:22:49 +05:30
commit 2be114da11
110 changed files with 1049 additions and 1070 deletions

View file

@ -57,6 +57,7 @@ import code.name.monkey.retromusic.transform.VerticalStackTransformer;
public final class PreferenceUtil {
public static final String LIBRARY_CATEGORIES = "library_categories";
public static final String BLACK_THEME = "black_theme";
public static final String DIALOG_CORNER = "dialog_corner";
public static final String KEEP_SCREEN_ON = "keep_screen_on";
public static final String TOGGLE_HOME_BANNER = "toggle_home_banner";
@ -141,6 +142,7 @@ public final class PreferenceUtil {
private static PreferenceUtil sInstance;
private final SharedPreferences mPreferences;
private PreferenceUtil(@NonNull final Context context) {
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}
@ -158,8 +160,6 @@ public final class PreferenceUtil {
switch (themePrefValue) {
case "light":
return R.style.Theme_RetroMusic_Light;
case "black":
return R.style.Theme_RetroMusic_Black;
case "dark":
default:
return R.style.Theme_RetroMusic;
@ -176,6 +176,10 @@ public final class PreferenceUtil {
editor.apply();
}
public boolean isBlackMode() {
return mPreferences.getBoolean(BLACK_THEME, false);
}
public String getUserBio() {
return mPreferences.getString(USER_BIO, "");
}
@ -565,6 +569,13 @@ public final class PreferenceUtil {
editor.apply();
}
@NonNull
public String getGeneralThemeValue() {
if (isBlackMode()) return "black";
else
return mPreferences.getString(GENERAL_THEME, "dark");
}
public String getBaseTheme() {
return mPreferences.getString(GENERAL_THEME, "dark");
}

View file

@ -0,0 +1,35 @@
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
"black" -> R.style.Theme_RetroMusic_Black
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
*/
}
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
}
}