android: Apply correct theme at boot.
This commit is contained in:
parent
b81c893ea8
commit
14110ff81e
@ -41,6 +41,8 @@ public final class MainActivity extends AppCompatActivity implements MainView {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
ThemeUtil.applyTheme();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
@ -57,9 +59,6 @@ public final class MainActivity extends AppCompatActivity implements MainView {
|
||||
mPlatformGamesFragment = new PlatformGamesFragment();
|
||||
getSupportFragmentManager().beginTransaction().add(mFrameLayoutId, mPlatformGamesFragment)
|
||||
.commit();
|
||||
|
||||
// Apply current theme setting
|
||||
ThemeUtil.applyTheme();
|
||||
}
|
||||
} else {
|
||||
mPlatformGamesFragment = (PlatformGamesFragment) getSupportFragmentManager().getFragment(savedInstanceState, "mPlatformGamesFragment");
|
||||
|
@ -12,18 +12,16 @@ public class ThemeUtil {
|
||||
|
||||
public static void applyTheme() {
|
||||
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) {
|
||||
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());
|
||||
private static void applyTheme(int designValue) {
|
||||
switch (designValue) {
|
||||
case 0:
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user