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