1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 06:11:19 +00:00

Add dark theme (fixes #400) (#399) (#401)

* Squash-merge from darkTheme1

* Imported de translation
This commit is contained in:
Catfriend1 2019-04-14 17:22:05 +02:00 committed by GitHub
parent b401a8cfff
commit f297766d64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 179 additions and 51 deletions

View file

@ -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";

View file

@ -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";

View file

@ -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.
*/

View file

@ -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";

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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.
*/

View file

@ -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" />

View file

@ -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" />
</LinearLayout>
</ScrollView>

View file

@ -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" />
</LinearLayout>
</ScrollView>

View file

@ -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" />

View file

@ -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"
/>

View file

@ -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"/>

View file

@ -34,7 +34,7 @@
android:layout_height="50dp"
android:layout_gravity="end"
android:text="@string/finish"
android:textColor="@color/primary_dark" />
android:textColor="?attr/colorControlNormal" />
</LinearLayout>
</ScrollView>

View file

@ -402,6 +402,11 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="settings_title">Einstellungen</string>
<string name="category_run_conditions">Laufkonditionen</string>
<string name="category_user_interface">Benutzeroberfläche</string>
<string name="preference_app_theme_title">Thema</string>
<string name="category_behaviour">Verhalten</string>
<string name="category_syncthing_options">Syncthing-Optionen</string>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#0288D1</color>
<color name="primary_dark">#002171</color>
</resources>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Button themes -->
<style name="Theme.Syncthing.GreyButton" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textColor">@color/btn_welcome_slide_color</item>
</style>
<!-- Dialog themes -->
<eat-comment/>
<style name="Theme.Syncthing.Dialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorAccent">@color/light_blue</item>
<item name="android:windowBackground">@color/blue_grey</item>
<item name="android:textColor">?attr/colorControlNormal</item>
</style>
</resources>

View file

@ -15,6 +15,17 @@
<item>battery_power</item>
</string-array>
<!-- Preference screen -->
<string-array name="app_theme_names">
<item>Light</item>
<item>Dark</item>
</string-array>
<string-array name="app_theme_values">
<item>1</item>
<item>2</item>
</string-array>
<!-- Preference screen -->
<string-array name="suggest_new_folder_root_values">
<item>external_android_data</item>

View file

@ -10,7 +10,9 @@
<color name="text_blue">#ff33b5e5</color>
<color name="text_green">#ff99cc00</color>
<color name="text_orange">#f57c00</color>
<color name="blue_grey">#263238</color>
<color name="light_grey">#cccccc</color>
<color name="light_blue">#4fc4ff</color>
<!-- FirstStartActivity welcome wizard start -->
<!-- Screens background color-->

View file

@ -405,6 +405,11 @@ Please report any problems you encounter via Github.</string>
<string name="settings_title">Settings</string>
<string name="category_run_conditions">Run Conditions</string>
<string name="category_user_interface">User Interface</string>
<string name="preference_app_theme_title">Theme</string>
<string name="category_behaviour">Behaviour</string>
<string name="category_syncthing_options">Syncthing Options</string>

View file

@ -4,7 +4,7 @@
<!-- Activity themes -->
<eat-comment/>
<style name="Theme.Syncthing.Base" parent="@style/Theme.AppCompat.Light.NoActionBar">
<style name="Theme.Syncthing.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
@ -22,6 +22,7 @@
<item name="android:spinnerStyle">@style/Widget.AppCompat.Spinner.Underlined</item>
<item name="android:spinnerItemStyle">@style/Widget.Syncthing.TextView.SpinnerItem</item>
<item name="android:alertDialogTheme">@style/Theme.Syncthing.Dialog</item>
</style>
<style name="Theme.Syncthing" parent="Theme.Syncthing.Base"/>
@ -41,14 +42,14 @@
<!-- Dialog themes -->
<eat-comment/>
<style name="Theme.Syncthing.Dialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<style name="Theme.Syncthing.Dialog" parent="Theme.AppCompat.DayNight.Dialog.Alert">
<item name="colorAccent">@color/primary_dark</item>
</style>
<!-- Toolbar themes -->
<eat-comment/>
<style name="ThemeOverlay.Syncthing.Toolbar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<style name="ThemeOverlay.Syncthing.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowBackground">@null</item>
<item name="colorAccent">@android:color/white</item>
</style>

View file

@ -81,6 +81,33 @@
</PreferenceScreen>
<PreferenceScreen
android:key="category_user_interface"
android:title="@string/category_user_interface">
<!-- App Theme -->
<ListPreference
android:key="app_theme"
android:title="@string/preference_app_theme_title"
android:entries="@array/app_theme_names"
android:entryValues="@array/app_theme_values"
android:defaultValue="1" />
<!-- Expert mode -->
<CheckBoxPreference
android:key="expert_mode"
android:title="@string/expert_mode_title"
android:summary="@string/expert_mode_summary"
android:defaultValue="false" />
<!-- Language -->
<ListPreference
android:key="pref_current_language"
android:title="@string/preference_language_title"
android:summary="@string/preference_language_summary" />
</PreferenceScreen>
<PreferenceScreen
android:key="category_behaviour"
android:title="@string/category_behaviour">
@ -107,18 +134,6 @@
android:summary="@null"
android:defaultValue="external_android_data" />
<!-- Expert mode -->
<CheckBoxPreference
android:key="expert_mode"
android:title="@string/expert_mode_title"
android:summary="@string/expert_mode_summary"
android:defaultValue="false" />
<ListPreference
android:key="pref_current_language"
android:title="@string/preference_language_title"
android:summary="@string/preference_language_summary" />
</PreferenceScreen>
<PreferenceScreen