android: Apply correct theme at boot.

This commit is contained in:
bunnei 2020-04-24 02:33:05 -04:00
parent 73fc4515be
commit a98e82dfec
2 changed files with 19 additions and 13 deletions

View File

@ -41,6 +41,8 @@ public final class MainActivity extends AppCompatActivity implements MainView {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
ThemeUtil.applyTheme();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
@ -57,9 +59,6 @@ public final class MainActivity extends AppCompatActivity implements MainView {
mPlatformGamesFragment = new PlatformGamesFragment(); mPlatformGamesFragment = new PlatformGamesFragment();
getSupportFragmentManager().beginTransaction().add(mFrameLayoutId, mPlatformGamesFragment) getSupportFragmentManager().beginTransaction().add(mFrameLayoutId, mPlatformGamesFragment)
.commit(); .commit();
// Apply current theme setting
ThemeUtil.applyTheme();
} }
} else { } else {
mPlatformGamesFragment = (PlatformGamesFragment) getSupportFragmentManager().getFragment(savedInstanceState, "mPlatformGamesFragment"); mPlatformGamesFragment = (PlatformGamesFragment) getSupportFragmentManager().getFragment(savedInstanceState, "mPlatformGamesFragment");

View File

@ -12,18 +12,16 @@ public class ThemeUtil {
public static void applyTheme() { public static void applyTheme() {
Settings settings = new Settings(); Settings settings = new Settings();
settings.loadSettings(null);
applyTheme(settings); try {
settings.loadSettings(null);
applyTheme(settings);
} catch (Exception e) {
applyTheme(0);
}
} }
public static void applyTheme(Settings settings) { private static void applyTheme(int designValue) {
Setting design = settings.getSection(Settings.SECTION_PREMIUM).getSetting((SettingsFile.KEY_DESIGN));
if (design == null) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
return;
}
int designValue = Integer.parseInt(design.getValueAsString());
switch (designValue) { switch (designValue) {
case 0: case 0:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
@ -39,4 +37,13 @@ public class ThemeUtil {
} }
} }
public static void applyTheme(Settings settings) {
Setting design = settings.getSection(Settings.SECTION_PREMIUM).getSetting((SettingsFile.KEY_DESIGN));
if (design == null) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
return;
}
applyTheme(Integer.parseInt(design.getValueAsString()));
}
} }