add dark/light/oled/day-night themes / change default theme to light

This commit is contained in:
David Luhmer 2018-09-28 21:22:17 +02:00
parent 23efac4eaa
commit e912dd2602
4 changed files with 42 additions and 24 deletions

View file

@ -109,6 +109,10 @@ a {
color: #ffffff !important;
}
#header.darkThemeOLED a:link, a:active, a:hover, a:visited {
color: #ffffff !important;
}
#header a:link, a:active, a:hover, a:visited {
color: #000000 !important;
text-decoration: none !important;

View file

@ -93,16 +93,20 @@ public class RssItemToHtmlTask extends AsyncTask<Void, Void, String> {
String body_id;
switch(ThemeChooser.getInstance(context).getSelectedTheme(context, false)) {
case 0:
body_id = "darkTheme";
case 0: // Auto (Light / Dark)
body_id = ThemeChooser.getInstance(context).isDarkTheme(context) ? "darkTheme" : "lightTheme";
break;
case 1:
case 1: // Light Theme
body_id = "lightTheme";
break;
case 2:
case 2: // Dark Theme
body_id = "darkTheme";
break;
case 3: // Dark Theme for OLED
body_id = "darkThemeOLED";
break;
default:
// this should never happen!
body_id = "darkTheme";
}

View file

@ -28,6 +28,7 @@ import android.content.res.Configuration;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatDelegate;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
public class ThemeChooser {
@ -46,27 +47,33 @@ public class ThemeChooser {
getSelectedTheme(context, false); // Init variable
}
public static void ChooseTheme(Activity act)
{
switch(getInstance(act).getSelectedTheme(act, false)) {
case 0: // Dark Theme
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
case 1: // Light Theme
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
case 2: // Dark Theme for OLED
public static void ChooseTheme(Activity act) {
switch(getInstance(act).getSelectedTheme(act, false)) {
case 0: // Auto (Light / Dark)
act.setTheme(R.style.AppTheme);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
break;
case 1: // Light Theme
act.setTheme(R.style.AppTheme);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
case 2: // Dark Theme
act.setTheme(R.style.AppTheme);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
case 3: // Dark Theme for OLED
act.setTheme(R.style.AppThemeOLED);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
}
}
}
// Check if the currently loaded theme is different from the one set in the settings
public boolean themeRequiresRestartOfUI(Context context) {
return mSelectedTheme != getSelectedTheme(context, true);
return !mSelectedTheme.equals(getSelectedTheme(context, true));
}
public boolean isDarkTheme(Context context) {
public boolean isDarkTheme(Context context) {
switch(AppCompatDelegate.getDefaultNightMode()) {
case AppCompatDelegate.MODE_NIGHT_YES:
return true;
@ -87,7 +94,7 @@ public class ThemeChooser {
public Integer getSelectedTheme(Context context, boolean forceReloadCache) {
if(mSelectedTheme == null || forceReloadCache) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
mSelectedTheme = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_APP_THEME, "1"));
mSelectedTheme = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_APP_THEME, "0"));
}
return mSelectedTheme;
}

View file

@ -200,19 +200,22 @@
</string-array>
<string name="pref_display_apptheme_night">On</string>
<string name="pref_display_apptheme_auto">Auto</string>
<string name="pref_display_apptheme_day">Off</string>
<string name="pref_display_apptheme_auto">Light / Dark (based on Daytime)</string>
<string name="pref_display_apptheme_light">Light</string>
<string name="pref_display_apptheme_dark">Dark</string>
<string name="pref_display_apptheme_dark_oled">Dark (for OLED Screens)</string>
<string-array name="pref_display_apptheme" translatable="false">
<item>@string/pref_display_apptheme_auto</item>
<item>@string/pref_display_apptheme_night</item>
<item>@string/pref_display_apptheme_day</item>
<item>@string/pref_display_apptheme_light</item>
<item>@string/pref_display_apptheme_dark</item>
<item>@string/pref_display_apptheme_dark_oled</item>
</string-array>
<string-array name="pref_display_apptheme_values" translatable="false">
<item>2</item>
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>