add system theme switch to settings
This commit is contained in:
@@ -2,20 +2,23 @@ package ru.vtosters.lite.hooks.ui;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class SystemThemeChangerHook {
|
||||
public static void onThemeChanged(Configuration configuration) {
|
||||
switch (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK) {
|
||||
case Configuration.UI_MODE_NIGHT_YES:
|
||||
// Night mode is active, we're using dark theme
|
||||
ThemesUtils.applyTheme(ThemesUtils.getDarkTheme());
|
||||
break;
|
||||
case Configuration.UI_MODE_NIGHT_NO:
|
||||
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
||||
// Night mode is not active, we're using light theme
|
||||
ThemesUtils.applyTheme(ThemesUtils.getLightTheme());
|
||||
break;
|
||||
if (Preferences.systemtheme()) {
|
||||
switch (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK) {
|
||||
case Configuration.UI_MODE_NIGHT_YES:
|
||||
// Night mode is active, we're using dark theme
|
||||
ThemesUtils.applyTheme(ThemesUtils.getDarkTheme());
|
||||
break;
|
||||
case Configuration.UI_MODE_NIGHT_NO:
|
||||
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
||||
// Night mode is not active, we're using light theme
|
||||
ThemesUtils.applyTheme(ThemesUtils.getLightTheme());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,8 +174,8 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 28 && false) { // TODO refactoring system theme
|
||||
addMaterialSwitchPreference(this, "systemtheme", AndroidUtils.getString("appearance_theme_use_system"), AndroidUtils.getString("appearance_theme_use_system_summary"), "ic_recent_outline_28", true, (preference, o) -> {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
addMaterialSwitchPreference(this, "systemtheme", AndroidUtils.getString("appearance_theme_use_system"), "", "ic_recent_outline_28", true, (preference, o) -> {
|
||||
boolean value = (boolean) o;
|
||||
|
||||
edit().putBoolean("systemtheme", value).commit();
|
||||
|
||||
@@ -15,6 +15,7 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.vtosters.lite.data.Users;
|
||||
@@ -60,7 +61,7 @@ public class Preferences {
|
||||
}
|
||||
|
||||
public static boolean systemtheme() {
|
||||
return false; //getBoolValue("systemtheme", true) && VERSION.SDK_INT >= 28;
|
||||
return Build.VERSION.SDK_INT >= 28 && getBoolValue("systemtheme", true);
|
||||
}
|
||||
|
||||
public static boolean authorsrecomm() {
|
||||
|
||||
Reference in New Issue
Block a user