mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Fix theme and icon color on startup
This commit is contained in:
parent
ecc941dc11
commit
b3ae8b1fff
7 changed files with 20 additions and 4 deletions
|
|
@ -2,6 +2,9 @@ package com.cappielloantonio.play;
|
|||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.cappielloantonio.play.helper.ThemeHelper;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
|
@ -24,7 +27,9 @@ public class App extends Application {
|
|||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
ThemeHelper.applyTheme(PreferenceUtil.getInstance(getApplicationContext()).getTheme());
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
String themePref = sharedPreferences.getString("themePref", ThemeHelper.DEFAULT_MODE);
|
||||
ThemeHelper.applyTheme(themePref);
|
||||
}
|
||||
|
||||
public static App getInstance() {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import com.cappielloantonio.play.helper.MusicPlayerRemote;
|
|||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package com.cappielloantonio.play.helper;
|
||||
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
|
||||
public class ThemeHelper {
|
||||
private static final String TAG = "ThemeHelper";
|
||||
|
||||
public static final String LIGHT_MODE = "light";
|
||||
public static final String DARK_MODE = "dark";
|
||||
public static final String DEFAULT_MODE = "default";
|
||||
|
|
@ -13,14 +16,19 @@ public class ThemeHelper {
|
|||
public static void applyTheme(@NonNull String themePref) {
|
||||
switch (themePref) {
|
||||
case LIGHT_MODE: {
|
||||
Log.d(TAG, "applyTheme: LIGHT");
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||
break;
|
||||
}
|
||||
case DARK_MODE: {
|
||||
Log.d(TAG, "applyTheme: DARK");
|
||||
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Log.d(TAG, "applyTheme: SYSTEM");
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class PreferenceUtil {
|
|||
|
||||
public static PreferenceUtil getInstance(final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new PreferenceUtil(context.getApplicationContext());
|
||||
sInstance = new PreferenceUtil(context);
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue