Skip to content

Commit

Permalink
Merge pull request #5899 from Stypox/fix-settings-theme
Browse files Browse the repository at this point in the history
Fix settings switches are not red anymore
  • Loading branch information
TobiGr authored Mar 24, 2021
2 parents c7efa8c + 0fcaf20 commit 67afd05
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void initSettings(final Context context) {

@Override
protected void onCreate(final Bundle savedInstanceBundle) {
ThemeHelper.setTheme(this);
setTheme(ThemeHelper.getSettingsThemeStyle(this));
assureCorrectAppLanguage(this);
super.onCreate(savedInstanceBundle);

Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,39 @@ public static int getThemeForService(final Context context, final int serviceId)
return baseTheme;
}

@StyleRes
public static int getSettingsThemeStyle(final Context context) {
final Resources res = context.getResources();
final String lightTheme = res.getString(R.string.light_theme_key);
final String blackTheme = res.getString(R.string.black_theme_key);
final String automaticDeviceTheme = res.getString(R.string.auto_device_theme_key);


final String selectedTheme = getSelectedThemeKey(context);

if (selectedTheme.equals(lightTheme)) {
return R.style.LightSettingsTheme;
} else if (selectedTheme.equals(blackTheme)) {
return R.style.BlackSettingsTheme;
} else if (selectedTheme.equals(automaticDeviceTheme)) {
if (isDeviceDarkThemeEnabled(context)) {
// use the dark theme variant preferred by the user
final String selectedNightTheme = getSelectedNightThemeKey(context);
if (selectedNightTheme.equals(blackTheme)) {
return R.style.BlackSettingsTheme;
} else {
return R.style.DarkSettingsTheme;
}
} else {
// there is only one day theme
return R.style.LightSettingsTheme;
}
} else {
// default to dark theme
return R.style.DarkSettingsTheme;
}
}

/**
* Get a resource id from a resource styled according to the context's theme.
*
Expand Down

0 comments on commit 67afd05

Please sign in to comment.