1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-29 15:51:17 +00:00

Theme: follow system default #1515 (#1555)

- Now app by default follows system theme for api level 28 and higher, for api level below 28, it fall backs to light theme.
This commit is contained in:
Praveen Rajput 2020-09-28 17:02:34 +05:30 committed by GitHub
parent 4eccb41c1f
commit cdf6a69d1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 3 deletions

View file

@ -13,13 +13,14 @@ import com.nutomic.syncthingandroid.service.Constants;
*/ */
public class ThemedAppCompatActivity extends AppCompatActivity { public class ThemedAppCompatActivity extends AppCompatActivity {
private static final String LIGHT_THEME = "1"; private static final String FOLLOW_SYSTEM = "-1";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
// Load theme. // Load theme.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Integer prefAppTheme = Integer.parseInt(prefs.getString(Constants.PREF_APP_THEME, LIGHT_THEME)); //For api level below 28, Follow system fall backs to light mode
Integer prefAppTheme = Integer.parseInt(prefs.getString(Constants.PREF_APP_THEME, FOLLOW_SYSTEM));
AppCompatDelegate.setDefaultNightMode(prefAppTheme); AppCompatDelegate.setDefaultNightMode(prefAppTheme);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }

View file

@ -16,11 +16,13 @@
</string-array> </string-array>
<string-array name="theme_names"> <string-array name="theme_names">
<item>@string/preference_theme_follow_system</item>
<item>@string/preference_theme_option_light</item> <item>@string/preference_theme_option_light</item>
<item>@string/preference_theme_option_dark</item> <item>@string/preference_theme_option_dark</item>
</string-array> </string-array>
<string-array name="theme_values"> <string-array name="theme_values">
<item>-1</item>
<item>1</item> <item>1</item>
<item>2</item> <item>2</item>
</string-array> </string-array>

View file

@ -380,6 +380,7 @@ Please report any problems you encounter via Github.</string>
<string name="start_into_web_gui_summary">When starting the app, open web GUI instead of the main screen</string> <string name="start_into_web_gui_summary">When starting the app, open web GUI instead of the main screen</string>
<string name="preference_theme_title">Theme</string> <string name="preference_theme_title">Theme</string>
<string name="preference_theme_follow_system">Follow system</string>
<string name="preference_theme_option_light">Light</string> <string name="preference_theme_option_light">Light</string>
<string name="preference_theme_option_dark">Dark</string> <string name="preference_theme_option_dark">Dark</string>

View file

@ -6,7 +6,7 @@
android:title="@string/preference_theme_title" android:title="@string/preference_theme_title"
android:entries="@array/theme_names" android:entries="@array/theme_names"
android:entryValues="@array/theme_values" android:entryValues="@array/theme_values"
android:defaultValue="1"/> <!-- 1 is Light Theme --> android:defaultValue="-1"/> <!-- -1 is Follow System -->
<PreferenceScreen <PreferenceScreen
android:title="@string/category_run_conditions" android:title="@string/category_run_conditions"