mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
review: fix nullability and visibility of settings
This commit is contained in:
@@ -5,6 +5,7 @@ import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -14,6 +15,7 @@ import de.hdodenhof.circleimageview.CircleImageView;
|
||||
|
||||
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
||||
|
||||
@NotNullByDefault
|
||||
public class AvatarPreference extends Preference {
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_MOBILE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
||||
@@ -49,12 +51,12 @@ class ConnectionsStore extends SettingsStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInt(String key, int value) {
|
||||
public void putString(String key, @Nullable String value) {
|
||||
// translate between Android UI pref keys and bramble keys
|
||||
if (key.equals(PREF_KEY_TOR_NETWORK)) {
|
||||
super.putInt(PREF_TOR_NETWORK, value);
|
||||
super.putString(PREF_TOR_NETWORK, value);
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
throw new AssertionError(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ 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;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
@@ -25,6 +26,7 @@ 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.Level.INFO;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
||||
@@ -43,11 +45,11 @@ public class DisplayFragment extends PreferenceFragmentCompat {
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
addPreferencesFromResource(R.xml.settings_display);
|
||||
|
||||
ListPreference language = findPreference(PREF_LANGUAGE);
|
||||
ListPreference language = requireNonNull(findPreference(PREF_LANGUAGE));
|
||||
setLanguageEntries(language);
|
||||
language.setOnPreferenceChangeListener(this::onLanguageChanged);
|
||||
|
||||
ListPreference theme = findPreference(PREF_THEME);
|
||||
ListPreference theme = requireNonNull(findPreference(PREF_THEME));
|
||||
setThemeEntries(theme);
|
||||
theme.setOnPreferenceChangeListener(this::onThemeChanged);
|
||||
}
|
||||
@@ -121,7 +123,8 @@ public class DisplayFragment extends PreferenceFragmentCompat {
|
||||
|
||||
private boolean onThemeChanged(Preference preference, Object newValue) {
|
||||
// activate new theme
|
||||
UiUtils.setTheme(getActivity(), (String) newValue);
|
||||
FragmentActivity activity = requireActivity();
|
||||
UiUtils.setTheme(activity, (String) newValue);
|
||||
// bring up parent activity, so it can change its theme as well
|
||||
// upstream bug: https://issuetracker.google.com/issues/38352704
|
||||
Intent intent = new Intent(getActivity(), ENTRY_ACTIVITY);
|
||||
@@ -129,9 +132,9 @@ public class DisplayFragment extends PreferenceFragmentCompat {
|
||||
startActivity(intent);
|
||||
// bring this activity back to the foreground
|
||||
// TODO maybe tell the activity here to relaunch this fragment?
|
||||
intent = new Intent(getActivity(), getActivity().getClass());
|
||||
intent = new Intent(getActivity(), activity.getClass());
|
||||
startActivity(intent);
|
||||
getActivity().finish();
|
||||
activity.finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_SOUND;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_VIBRATION;
|
||||
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
class NotificationsManager {
|
||||
@@ -64,7 +63,7 @@ class NotificationsManager {
|
||||
|
||||
private volatile String ringtoneName, ringtoneUri;
|
||||
|
||||
public NotificationsManager(Context ctx,
|
||||
NotificationsManager(Context ctx,
|
||||
SettingsManager settingsManager,
|
||||
Executor dbExecutor) {
|
||||
this.ctx = ctx;
|
||||
@@ -153,7 +152,7 @@ class NotificationsManager {
|
||||
return ringtoneName;
|
||||
}
|
||||
|
||||
public String getRingtoneUri() {
|
||||
String getRingtoneUri() {
|
||||
return ringtoneUri;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.logging.Logger;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceDataStore;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
@@ -21,8 +20,6 @@ import static org.briarproject.bramble.util.LogUtils.now;
|
||||
|
||||
/**
|
||||
* A custom PreferenceDataStore that stores settings in Briar's encrypted DB.
|
||||
* <p>
|
||||
* Warning: This expects all strings to be integers and stores them as such.
|
||||
*/
|
||||
@NotNullByDefault
|
||||
class SettingsStore extends PreferenceDataStore {
|
||||
@@ -61,8 +58,11 @@ class SettingsStore extends PreferenceDataStore {
|
||||
|
||||
@Override
|
||||
public void putString(String key, @Nullable String value) {
|
||||
int integer = Integer.parseInt(requireNonNull(value));
|
||||
putInt(key, integer);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Store string setting: " + key + "=" + value);
|
||||
Settings s = new Settings();
|
||||
s.put(key, value);
|
||||
storeSettings(s);
|
||||
}
|
||||
|
||||
private void storeSettings(Settings s) {
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.AnyThread;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
@@ -117,7 +118,7 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
||||
this.authorManager = authorManager;
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.featureFlags = featureFlags;
|
||||
this.settingsStore = new SettingsStore(settingsManager, dbExecutor,
|
||||
settingsStore = new SettingsStore(settingsManager, dbExecutor,
|
||||
SETTINGS_NAMESPACE);
|
||||
torSummaryProvider = new TorSummaryProvider(getApplication(),
|
||||
locationUtils, circumventionProvider);
|
||||
@@ -195,6 +196,7 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
private void updateSettings(Settings settings) {
|
||||
screenLockEnabled.postValue(settings.getBoolean(PREF_SCREEN_LOCK,
|
||||
false));
|
||||
|
||||
@@ -20,7 +20,7 @@ class TorSummaryProvider implements SummaryProvider<ListPreference> {
|
||||
private final LocationUtils locationUtils;
|
||||
private final CircumventionProvider circumventionProvider;
|
||||
|
||||
public TorSummaryProvider(Context ctx,
|
||||
TorSummaryProvider(Context ctx,
|
||||
LocationUtils locationUtils,
|
||||
CircumventionProvider circumventionProvider) {
|
||||
this.ctx = ctx;
|
||||
|
||||
Reference in New Issue
Block a user