Initial work on dark theme

This commit is contained in:
Shinokuni 2019-12-08 18:55:42 +01:00
parent b40a834055
commit 9ede16c864
9 changed files with 59 additions and 8 deletions

View File

@ -5,7 +5,10 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import androidx.appcompat.app.AppCompatDelegate;
import com.facebook.stetho.Stetho;
import com.readrops.app.utils.SharedPreferencesManager;
import io.reactivex.plugins.RxJavaPlugins;
@ -26,6 +29,8 @@ public class ReadropsApp extends Application {
}
createNotificationChannels();
if (Boolean.valueOf(SharedPreferencesManager.readString(this, SharedPreferencesManager.SharedPrefKey.DARK_THEME)))
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
private void createNotificationChannels() {

View File

@ -3,6 +3,7 @@ package com.readrops.app.fragments.settings;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
@ -21,9 +22,10 @@ public class SettingsFragment extends PreferenceFragmentCompat {
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences);
AtomicBoolean serviceStarted = new AtomicBoolean(false);
Preference feedsColorsPreference = findPreference("reload_feeds_colors");
Preference themePreference = findPreference("dark_theme");
AtomicBoolean serviceStarted = new AtomicBoolean(false);
feedsColorsPreference.setOnPreferenceClickListener(preference -> {
Database database = Database.getInstance(getContext());
@ -39,5 +41,18 @@ public class SettingsFragment extends PreferenceFragmentCompat {
return true;
});
themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
boolean darkTheme = Boolean.parseBoolean(newValue.toString());
if (darkTheme) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
return true;
});
}
}

View File

@ -51,7 +51,8 @@ public final class SharedPreferencesManager {
public enum SharedPrefKey {
SHOW_READ_ARTICLES("show_read_articles", false),
ITEMS_TO_PARSE_MAX_NB("items_to_parse_max_nb", "20"),
OPEN_ITEMS_IN("open_items_in", "0");
OPEN_ITEMS_IN("open_items_in", "0"),
DARK_THEME("dark_theme", "false");
@NonNull
private String key;
@ -59,7 +60,7 @@ public final class SharedPreferencesManager {
private Object defaultValue;
public boolean getBooleanDefaultValue() {
return (boolean) defaultValue;
return Boolean.valueOf(defaultValue.toString());
}
public String getStringDefaultValue() {
@ -67,7 +68,7 @@ public final class SharedPreferencesManager {
}
public int getIntDefaultValue() {
return (int) defaultValue;
return Integer.parseInt(defaultValue.toString());
}
SharedPrefKey(@NonNull String key, @NonNull Object defaultValue) {

View File

@ -106,5 +106,8 @@
<string name="image_options">Options de l\'image</string>
<string name="download_image">Télécharger l\'image</string>
<string name="share_image">Partager l\'image</string>
<string name="theme">Thème</string>
<string name="light">Clair</string>
<string name="dark">Sombre</string>
</resources>

View File

@ -0,0 +1,10 @@
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="actionBarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
</resources>

View File

@ -39,4 +39,13 @@
<item>1</item>
</string-array>
<string-array name="themes">
<item>@string/light</item>
<item>@string/dark</item>
</string-array>
<string-array name="themes_values">
<item>false</item>
<item>true</item>
</string-array>
</resources>

View File

@ -115,4 +115,7 @@
<string name="image_options">Image Options</string>
<string name="download_image">Download image</string>
<string name="share_image">Share image</string>
<string name="theme">Theme</string>
<string name="light">Light</string>
<string name="dark">Dark</string>
</resources>

View File

@ -1,8 +1,6 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

View File

@ -16,11 +16,18 @@
android:title="@string/reload_feeds_colors" />
<ListPreference
android:defaultValue="@string/external_navigator"
android:defaultValue="1"
android:entries="@array/open_items_in"
android:entryValues="@array/open_item_in_values"
android:key="open_items_in"
android:title="@string/open_items_in" />
<ListPreference
android:defaultValue="1"
android:entries="@array/themes"
android:entryValues="@array/themes_values"
android:key="dark_theme"
android:title="@string/theme" />
</PreferenceCategory>
</PreferenceScreen>