isdarktheme now should work depending on the dark theme of the app v2

This commit is contained in:
gdlbo
2022-06-14 13:26:47 +03:00
parent 2f4603af26
commit bacf196a31
2 changed files with 10 additions and 9 deletions
@@ -3,6 +3,7 @@ package ru.vtosters.lite.utils;
import static androidx.core.content.ContextCompat.getDrawable;
import static ru.vtosters.lite.utils.Preferences.getLocale;
import static ru.vtosters.lite.utils.Preferences.preferences;
import static ru.vtosters.lite.utils.Themes.isDarkTheme;
import android.app.Activity;
import android.app.Application;
@@ -322,6 +323,8 @@ public class Globals {
configuration.setLayoutDirection(locale);
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
edit().putBoolean("isdark", isDarkTheme()).commit();
return context;
} // Language changer and BaseContext injector
@@ -326,7 +326,7 @@ public class Themes {
}
public static void systemThemeChanger() {
Boolean isDarkTheme = isDarkTheme();
boolean isDarkTheme = isDarkTheme();
if (isDarkTheme){
applyTheme(getDarkTheme(), getImDarkTheme());
@@ -334,23 +334,21 @@ public class Themes {
applyTheme(getLightTheme(), getImLightTheme());
}
edit().putBoolean("isdark", isDarkTheme).commit();
if (!systemtheme()) return;
if (!systemtheme()){
edit().putBoolean("isdark", isDarkTheme).commit();
return;
}
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_UNDEFINED:
applyTheme(getLightTheme(), getImLightTheme());
edit().putBoolean("isdark", !isDarkTheme).commit();
break;
case Configuration.UI_MODE_NIGHT_NO:
edit().putBoolean("isdark", false).commit();
applyTheme(getLightTheme(), getImLightTheme());
edit().putBoolean("isdark", !isDarkTheme).commit();
break;
case Configuration.UI_MODE_NIGHT_YES:
edit().putBoolean("isdark", true).commit();
applyTheme(getDarkTheme(), getImDarkTheme());
edit().putBoolean("isdark", isDarkTheme).commit();
break;
}
}