From f297766d64f259b11dccad29a3f316f244043193 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sun, 14 Apr 2019 17:22:05 +0200 Subject: [PATCH] Add dark theme (fixes #400) (#399) (#401) * Squash-merge from darkTheme1 * Imported de translation --- .../activities/FolderTypeDialogActivity.java | 3 +- .../activities/PullOrderDialogActivity.java | 3 +- .../activities/SettingsActivity.java | 62 +++++++++++++++---- .../activities/SyncthingActivity.java | 3 +- .../activities/ThemedAppCompatActivity.java | 27 ++++++++ .../activities/VersioningDialogActivity.java | 5 +- .../syncthingandroid/service/Constants.java | 12 +++- .../layout/fragment_external_versioning.xml | 2 +- .../res/layout/fragment_foldertype_dialog.xml | 2 +- .../res/layout/fragment_pullorder_dialog.xml | 2 +- .../res/layout/fragment_simple_versioning.xml | 4 +- .../layout/fragment_staggered_versioning.xml | 6 +- .../layout/fragment_trashcan_versioning.xml | 4 +- .../res/layout/fragment_versioning_dialog.xml | 4 +- app/src/main/res/values-de/strings.xml | 5 ++ app/src/main/res/values-night/colors.xml | 5 ++ app/src/main/res/values-night/themes.xml | 17 +++++ app/src/main/res/values/arrays.xml | 11 ++++ app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 5 ++ app/src/main/res/values/themes.xml | 7 ++- app/src/main/res/xml/app_settings.xml | 39 ++++++++---- 22 files changed, 179 insertions(+), 51 deletions(-) create mode 100644 app/src/main/java/com/nutomic/syncthingandroid/activities/ThemedAppCompatActivity.java create mode 100644 app/src/main/res/values-night/colors.xml create mode 100644 app/src/main/res/values-night/themes.xml diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderTypeDialogActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderTypeDialogActivity.java index 7afd17ee..f2d34d65 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderTypeDialogActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderTypeDialogActivity.java @@ -3,7 +3,6 @@ package com.nutomic.syncthingandroid.activities; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.Button; @@ -14,7 +13,7 @@ import com.nutomic.syncthingandroid.service.Constants; import java.util.Arrays; import java.util.List; -public class FolderTypeDialogActivity extends AppCompatActivity { +public class FolderTypeDialogActivity extends ThemedAppCompatActivity { public static final String EXTRA_FOLDER_TYPE = "com.github.catfriend1.syncthingandroid.activities.FolderTypeDialogActivity.FOLDER_TYPE"; public static final String EXTRA_RESULT_FOLDER_TYPE = "com.github.catfriend1.syncthingandroid.activities.FolderTypeDialogActivity.EXTRA_RESULT_FOLDER_TYPE"; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/PullOrderDialogActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/PullOrderDialogActivity.java index 41db3579..ab4b356b 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/PullOrderDialogActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/PullOrderDialogActivity.java @@ -3,7 +3,6 @@ package com.nutomic.syncthingandroid.activities; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.Button; @@ -13,7 +12,7 @@ import com.nutomic.syncthingandroid.R; import java.util.Arrays; import java.util.List; -public class PullOrderDialogActivity extends AppCompatActivity { +public class PullOrderDialogActivity extends ThemedAppCompatActivity { public static final String EXTRA_PULL_ORDER = "com.github.catfriend1.syncthingandroid.activities.PullOrderDialogActivity.PULL_ORDER"; public static final String EXTRA_RESULT_PULL_ORDER = "com.github.catfriend1.syncthingandroid.activities.PullOrderDialogActivity.EXTRA_RESULT_PULL_ORDER"; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index 78793d37..e9e0141f 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -1,6 +1,7 @@ package com.nutomic.syncthingandroid.activities; import android.Manifest; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.ClipData; @@ -51,6 +52,7 @@ import com.nutomic.syncthingandroid.service.NotificationHandler; import com.nutomic.syncthingandroid.service.RestApi; import com.nutomic.syncthingandroid.service.SyncthingService; import com.nutomic.syncthingandroid.service.SyncthingServiceBinder; +import com.nutomic.syncthingandroid.util.ConfigRouter; import com.nutomic.syncthingandroid.util.FileUtils; import com.nutomic.syncthingandroid.util.Languages; import com.nutomic.syncthingandroid.util.Util; @@ -170,11 +172,13 @@ public class SettingsActivity extends SyncthingActivity { private WifiSsidPreference mWifiSsidWhitelist; private CheckBoxPreference mRunInFlightMode; + /* User Interface */ + private Languages mLanguages; + /* Behaviour */ private CheckBoxPreference mStartServiceOnBoot; private CheckBoxPreference mUseRoot; private ListPreference mSuggestNewFolderRoot; - private Languages mLanguages; /* Syncthing Options */ private PreferenceScreen mCategorySyncthingOptions; @@ -259,9 +263,9 @@ public class SettingsActivity extends SyncthingActivity { mPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); ListPreference languagePref = (ListPreference) findPreference(Languages.PREFERENCE_LANGUAGE); - PreferenceScreen categoryBehaviour = (PreferenceScreen) findPreference("category_behaviour"); + PreferenceScreen categoryUserInterface = (PreferenceScreen) findPreference("category_user_interface"); if (Build.VERSION.SDK_INT >= 24) { - categoryBehaviour.removePreference(languagePref); + categoryUserInterface.removePreference(languagePref); } else { mLanguages = new Languages(getActivity()); languagePref.setDefaultValue(mLanguages.USE_SYSTEM_DEFAULT); @@ -305,7 +309,11 @@ public class SettingsActivity extends SyncthingActivity { } setPreferenceCategoryChangeListener(mCategoryRunConditions, this::onRunConditionPreferenceChange); + /* User Interface */ + setPreferenceCategoryChangeListener(categoryUserInterface, this::onUserInterfacePreferenceChange); + /* Behaviour */ + PreferenceScreen categoryBehaviour = (PreferenceScreen) findPreference("category_behaviour"); mStartServiceOnBoot = (CheckBoxPreference) findPreference(Constants.PREF_START_SERVICE_ON_BOOT); mUseRoot = @@ -587,6 +595,27 @@ public class SettingsActivity extends SyncthingActivity { return true; } + public boolean onUserInterfacePreferenceChange(Preference preference, Object o) { + switch (preference.getKey()) { + case Constants.PREF_APP_THEME: + String newTheme = (String) o; + String prevTheme = mPreferences.getString(Constants.PREF_APP_THEME, Constants.APP_THEME_LIGHT); + if (!newTheme.equals(prevTheme)) { + ConfigRouter config = new ConfigRouter(getActivity()); + Gui gui = config.getGui(mRestApi); + gui.theme = newTheme.equals(Constants.APP_THEME_LIGHT) ? "default" : "dark"; + config.updateGui(mRestApi, gui); + getAppRestartConfirmationDialog(getActivity()) + .show(); + } + break; + case Languages.PREFERENCE_LANGUAGE: + mLanguages.forceChangeLanguage(getActivity(), (String) o); + return false; + } + return true; + } + public boolean onBehaviourPreferenceChange(Preference preference, Object o) { switch (preference.getKey()) { case Constants.PREF_USE_ROOT: @@ -601,9 +630,6 @@ public class SettingsActivity extends SyncthingActivity { mSuggestNewFolderRoot.setValue(o.toString()); preference.setSummary(mSuggestNewFolderRoot.getEntry()); break; - case Languages.PREFERENCE_LANGUAGE: - mLanguages.forceChangeLanguage(getActivity(), (String) o); - return false; } return true; } @@ -773,13 +799,7 @@ public class SettingsActivity extends SyncthingActivity { final Intent intent; switch (preference.getKey()) { case Constants.PREF_VERBOSE_LOG: - new AlertDialog.Builder(getActivity()) - .setTitle(R.string.dialog_settings_restart_app_title) - .setMessage(R.string.dialog_settings_restart_app_question) - .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { - getActivity().setResult(RESULT_RESTART_APP); - getActivity().finish(); - }) + getAppRestartConfirmationDialog(getActivity()) .setNegativeButton(android.R.string.no, (dialogInterface, i) -> { // Revert. ((CheckBoxPreference) preference).setChecked(!((CheckBoxPreference) preference).isChecked()); @@ -900,6 +920,22 @@ public class SettingsActivity extends SyncthingActivity { }); } + /** + * Provides a template for an AlertDialog which quits and restarts the + * whole app including all of its activities and services. + * Use rarely as it's annoying for a user having to restart the whole app. + */ + private static AlertDialog.Builder getAppRestartConfirmationDialog(Activity activity) { + return new AlertDialog.Builder(activity) + .setTitle(R.string.dialog_settings_restart_app_title) + .setMessage(R.string.dialog_settings_restart_app_question) + .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { + activity.setResult(RESULT_RESTART_APP); + activity.finish(); + }) + .setNegativeButton(android.R.string.no, (dialogInterface, i) -> {}); + } + /** * Enables or disables {@link #mUseRoot} preference depending whether root is available. */ diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java index ef137bb9..2377b74c 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java @@ -8,7 +8,6 @@ import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; // import android.util.Log; @@ -20,7 +19,7 @@ import com.nutomic.syncthingandroid.service.SyncthingServiceBinder; /** * Connects to {@link SyncthingService} and provides access to it. */ -public abstract class SyncthingActivity extends AppCompatActivity implements ServiceConnection { +public abstract class SyncthingActivity extends ThemedAppCompatActivity implements ServiceConnection { private static final String TAG = "SyncthingActivity"; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/ThemedAppCompatActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/ThemedAppCompatActivity.java new file mode 100644 index 00000000..f775886d --- /dev/null +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/ThemedAppCompatActivity.java @@ -0,0 +1,27 @@ +package com.nutomic.syncthingandroid.activities; + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.app.AppCompatDelegate; +// import android.util.Log; + +import com.nutomic.syncthingandroid.service.Constants; + +/** + * Provides a themed instance of AppCompatActivity. + */ +public abstract class ThemedAppCompatActivity extends AppCompatActivity { + + // private static final String TAG = "ThemedAppCompatActivity"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + // Load theme. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + Integer prefAppTheme = Integer.parseInt(sharedPreferences.getString(Constants.PREF_APP_THEME, Constants.APP_THEME_LIGHT)); + AppCompatDelegate.setDefaultNightMode(prefAppTheme); + super.onCreate(savedInstanceState); + } +} diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/VersioningDialogActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/VersioningDialogActivity.java index 8c77861b..3caa8ccf 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/VersioningDialogActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/VersioningDialogActivity.java @@ -5,7 +5,6 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.Button; @@ -20,7 +19,7 @@ import com.nutomic.syncthingandroid.fragments.dialog.TrashCanVersioningFragment; import java.util.Arrays; import java.util.List; -public class VersioningDialogActivity extends AppCompatActivity { +public class VersioningDialogActivity extends ThemedAppCompatActivity { private Fragment mCurrentFragment; @@ -131,4 +130,4 @@ public class VersioningDialogActivity extends AppCompatActivity { saveConfiguration(); super.onBackPressed(); } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java index 288efeef..74c5b855 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java @@ -29,6 +29,10 @@ public class Constants { public static final String PREF_RUN_IN_FLIGHT_MODE = "run_in_flight_mode"; public static final String PREF_RUN_ON_TIME_SCHEDULE = "run_on_time_schedule"; + // Preferences - User Interface + public static final String PREF_APP_THEME = "app_theme"; + public static final String PREF_EXPERT_MODE = "expert_mode"; + // Preferences - Behaviour public static final String PREF_USE_ROOT = "use_root"; @@ -36,8 +40,6 @@ public class Constants { public static final String PREF_SUGGEST_NEW_FOLDER_ROOT_DATA = "external_android_data"; public static final String PREF_SUGGEST_NEW_FOLDER_ROOT_MEDIA = "external_android_media"; - public static final String PREF_EXPERT_MODE = "expert_mode"; - // Preferences - Troubleshooting public static final String PREF_VERBOSE_LOG = "verbose_log"; public static final String PREF_ENVIRONMENT_VARIABLES = "environment_variables"; @@ -95,6 +97,12 @@ public class Constants { */ public static final String PREF_DEBUG_FACILITIES_AVAILABLE = "debug_facilities_available"; + /** + * Available app themes + */ + public static final String APP_THEME_LIGHT = "1"; + public static final String APP_THEME_DARK = "2"; + /** * Available folder types. */ diff --git a/app/src/main/res/layout/fragment_external_versioning.xml b/app/src/main/res/layout/fragment_external_versioning.xml index 64c7e5e0..e95d8497 100644 --- a/app/src/main/res/layout/fragment_external_versioning.xml +++ b/app/src/main/res/layout/fragment_external_versioning.xml @@ -9,7 +9,7 @@ android:layout_margin="10dp" android:text="@string/command" android:textAlignment="center" - android:textColor="@android:color/black" + android:textColor="?attr/colorControlNormal" android:textSize="18sp" android:textStyle="bold" /> diff --git a/app/src/main/res/layout/fragment_foldertype_dialog.xml b/app/src/main/res/layout/fragment_foldertype_dialog.xml index 533af666..d758dd1d 100644 --- a/app/src/main/res/layout/fragment_foldertype_dialog.xml +++ b/app/src/main/res/layout/fragment_foldertype_dialog.xml @@ -29,7 +29,7 @@ android:layout_height="50dp" android:layout_gravity="end" android:text="@string/finish" - android:textColor="@color/primary_dark" /> + android:textColor="?attr/colorControlNormal" /> diff --git a/app/src/main/res/layout/fragment_pullorder_dialog.xml b/app/src/main/res/layout/fragment_pullorder_dialog.xml index f2d8db19..4c3e3679 100644 --- a/app/src/main/res/layout/fragment_pullorder_dialog.xml +++ b/app/src/main/res/layout/fragment_pullorder_dialog.xml @@ -29,7 +29,7 @@ android:layout_height="50dp" android:layout_gravity="end" android:text="@string/finish" - android:textColor="@color/primary_dark" /> + android:textColor="?attr/colorControlNormal" /> diff --git a/app/src/main/res/layout/fragment_simple_versioning.xml b/app/src/main/res/layout/fragment_simple_versioning.xml index 42cb5552..61a4c1d5 100644 --- a/app/src/main/res/layout/fragment_simple_versioning.xml +++ b/app/src/main/res/layout/fragment_simple_versioning.xml @@ -21,7 +21,7 @@ android:layout_margin="10dp" android:text="@string/keep_versions" android:textAlignment="center" - android:textColor="@android:color/black" + android:textColor="?attr/colorControlNormal" android:textSize="18sp" android:textStyle="bold" /> @@ -40,4 +40,4 @@ android:layout_margin="10dp" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/fragment_staggered_versioning.xml b/app/src/main/res/layout/fragment_staggered_versioning.xml index 60434246..a2115cbb 100644 --- a/app/src/main/res/layout/fragment_staggered_versioning.xml +++ b/app/src/main/res/layout/fragment_staggered_versioning.xml @@ -15,7 +15,7 @@ android:layout_height="wrap_content" android:text="@string/maximum_age" android:textAlignment="center" - android:textColor="@android:color/black" + android:textColor="?attr/colorControlNormal" android:textSize="18sp" android:textStyle="bold" android:layout_margin="10dp" @@ -42,7 +42,7 @@ android:layout_margin="10dp" android:text="@string/versions_path" android:textAlignment="center" - android:textColor="@android:color/black" + android:textColor="?attr/colorControlNormal" android:textSize="18sp" android:textStyle="bold" /> @@ -63,4 +63,4 @@ android:layout_margin="10dp" android:text="@string/versions_path_description" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/fragment_trashcan_versioning.xml b/app/src/main/res/layout/fragment_trashcan_versioning.xml index 8a51226e..db10cbaf 100644 --- a/app/src/main/res/layout/fragment_trashcan_versioning.xml +++ b/app/src/main/res/layout/fragment_trashcan_versioning.xml @@ -21,7 +21,7 @@ android:layout_height="wrap_content" android:text="@string/clean_out_after" android:textAlignment="center" - android:textColor="@android:color/black" + android:textColor="?attr/colorControlNormal" android:textSize="18sp" android:layout_margin="10dp" android:textStyle="bold"/> @@ -41,4 +41,4 @@ android:layout_margin="10dp" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/fragment_versioning_dialog.xml b/app/src/main/res/layout/fragment_versioning_dialog.xml index 6fa83336..ed18795d 100644 --- a/app/src/main/res/layout/fragment_versioning_dialog.xml +++ b/app/src/main/res/layout/fragment_versioning_dialog.xml @@ -34,9 +34,9 @@ android:layout_height="50dp" android:layout_gravity="end" android:text="@string/finish" - android:textColor="@color/primary_dark" /> + android:textColor="?attr/colorControlNormal" /> - \ No newline at end of file + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 3aecb00f..356ce682 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -402,6 +402,11 @@ Bitte melden Sie auftretende Probleme via GitHub. Einstellungen Laufkonditionen + + Benutzeroberfläche + + Thema + Verhalten Syncthing-Optionen diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml new file mode 100644 index 00000000..fb7087fb --- /dev/null +++ b/app/src/main/res/values-night/colors.xml @@ -0,0 +1,5 @@ + + + #0288D1 + #002171 + diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 00000000..660a1ae6 --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index de74ee89..2fcf1393 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -15,6 +15,17 @@ battery_power + + + Light + Dark + + + + 1 + 2 + + external_android_data diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 5d2bb95c..629ad20d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -10,7 +10,9 @@ #ff33b5e5 #ff99cc00 #f57c00 + #263238 #cccccc + #4fc4ff diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 27205732..58c90954 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -405,6 +405,11 @@ Please report any problems you encounter via Github. Settings Run Conditions + + User Interface + + Theme + Behaviour Syncthing Options diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 8afc7d4f..3ba947f2 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -4,7 +4,7 @@ - - diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index be93e943..4b063e31 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -81,6 +81,33 @@ + + + + + + + + + + + + + @@ -107,18 +134,6 @@ android:summary="@null" android:defaultValue="external_android_data" /> - - - - -