Merge branch '2131-follow-system-theme' into 'master'

Change default theme to 'follow system' instead of 'light'

Closes #2131

See merge request briar/briar!1824
This commit is contained in:
akwizgran
2024-05-24 13:39:11 +00:00
7 changed files with 8 additions and 51 deletions

View File

@@ -27,7 +27,7 @@ class BriarAccountManager extends AndroidAccountManager {
super.deleteAccount();
Localizer.reinitialize();
UiUtils.setTheme(appContext,
appContext.getString(R.string.pref_theme_light_value));
appContext.getString(R.string.pref_theme_system_value));
}
}
}

View File

@@ -33,6 +33,7 @@ import static java.util.logging.Level.FINE;
import static java.util.logging.Level.INFO;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
import static org.briarproject.briar.android.settings.DisplayFragment.PREF_THEME;
public class BriarApplicationImpl extends Application
implements BriarApplication {
@@ -109,11 +110,11 @@ public class BriarApplicationImpl extends Application
}
private void setTheme(Context ctx, SharedPreferences prefs) {
String theme = prefs.getString("pref_key_theme", null);
String theme = prefs.getString(PREF_THEME, null);
if (theme == null) {
// set default value
theme = getString(R.string.pref_theme_light_value);
prefs.edit().putString("pref_key_theme", theme).apply();
theme = getString(R.string.pref_theme_system_value);
prefs.edit().putString(PREF_THEME, theme).apply();
}
// set theme
UiUtils.setTheme(ctx, theme);

View File

@@ -10,12 +10,9 @@ import org.briarproject.briar.android.util.UiUtils;
import org.briarproject.nullsafety.NotNullByDefault;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
import androidx.core.text.TextUtilsCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
@@ -24,10 +21,7 @@ import androidx.preference.PreferenceFragmentCompat;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.os.Build.VERSION.SDK_INT;
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.SIGN_OUT_URI;
import static org.briarproject.briar.android.settings.SettingsActivity.EXTRA_THEME_CHANGE;
@@ -36,10 +30,7 @@ import static org.briarproject.briar.android.settings.SettingsActivity.EXTRA_THE
public class DisplayFragment extends PreferenceFragmentCompat {
public static final String PREF_LANGUAGE = "pref_key_language";
private static final String PREF_THEME = "pref_key_theme";
private static final Logger LOG =
getLogger(DisplayFragment.class.getName());
public static final String PREF_THEME = "pref_key_theme";
@Override
public void onCreatePreferences(Bundle bundle, String s) {
@@ -50,7 +41,6 @@ public class DisplayFragment extends PreferenceFragmentCompat {
language.setOnPreferenceChangeListener(this::onLanguageChanged);
ListPreference theme = requireNonNull(findPreference(PREF_THEME));
setThemeEntries(theme);
theme.setOnPreferenceChangeListener(this::onThemeChanged);
}
@@ -91,30 +81,6 @@ public class DisplayFragment extends PreferenceFragmentCompat {
language.setEntryValues(entryValues.toArray(new CharSequence[0]));
}
private boolean isLeftToRight(Locale locale) {
// TextUtilsCompat returns the wrong direction for Hebrew on some phones
String language = locale.getLanguage();
if (language.equals("iw") || language.equals("he")) return false;
int direction = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
return direction == LAYOUT_DIRECTION_LTR;
}
private void setThemeEntries(ListPreference theme) {
if (SDK_INT < 27) {
// remove System Default Theme option from preference entries
// as it is not functional on this API anyway
List<CharSequence> entries =
new ArrayList<>(Arrays.asList(theme.getEntries()));
entries.remove(getString(R.string.pref_theme_system));
theme.setEntries(entries.toArray(new CharSequence[0]));
// also remove corresponding value
List<CharSequence> values =
new ArrayList<>(Arrays.asList(theme.getEntryValues()));
values.remove(getString(R.string.pref_theme_system_value));
theme.setEntryValues(values.toArray(new CharSequence[0]));
}
}
private boolean onThemeChanged(Preference preference, Object newValue) {
// activate new theme
FragmentActivity activity = requireActivity();

View File

@@ -92,7 +92,6 @@ import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
import static android.view.inputmethod.EditorInfo.IME_NULL;
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
import static android.widget.Toast.LENGTH_LONG;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_TIME;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
@@ -349,12 +348,7 @@ public class UiUtils {
} else if (theme
.equals(ctx.getString(R.string.pref_theme_dark_value))) {
setDefaultNightMode(MODE_NIGHT_YES);
} else if (theme
.equals(ctx.getString(R.string.pref_theme_auto_value))) {
// TODO remove AUTO-setting as it is deprecated
setDefaultNightMode(MODE_NIGHT_AUTO_TIME);
} else if (theme
.equals(ctx.getString(R.string.pref_theme_system_value))) {
} else {
setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
}
}

View File

@@ -63,17 +63,14 @@
<string-array name="pref_theme_entries">
<item>@string/pref_theme_light</item>
<item>@string/pref_theme_dark</item>
<item>@string/pref_theme_auto</item>
<item>@string/pref_theme_system</item>
</string-array>
<string name="pref_theme_light_value" translatable="false">light</string>
<string name="pref_theme_dark_value" translatable="false">dark</string>
<string name="pref_theme_auto_value" translatable="false">auto</string>
<string name="pref_theme_system_value" translatable="false">system</string>
<string-array name="pref_theme_values">
<item>@string/pref_theme_light_value</item>
<item>@string/pref_theme_dark_value</item>
<item>@string/pref_theme_auto_value</item>
<item>@string/pref_theme_system_value</item>
</string-array>

View File

@@ -546,7 +546,6 @@
<string name="pref_theme_title">Theme</string>
<string name="pref_theme_light">Light</string>
<string name="pref_theme_dark">Dark</string>
<string name="pref_theme_auto">Automatic (Daytime)</string>
<string name="pref_theme_system">System default</string>
<!-- Settings Connections -->

View File

@@ -13,7 +13,7 @@
tools:summary="System default" />
<ListPreference
android:defaultValue="@string/pref_theme_light_value"
android:defaultValue="@string/pref_theme_system_value"
android:entries="@array/pref_theme_entries"
android:entryValues="@array/pref_theme_values"
android:key="pref_key_theme"