Refactor app settings.

This commit is contained in:
Alex Hart
2021-05-12 13:02:44 -03:00
committed by Greyson Parrelli
parent a94d77d81e
commit f2d5ea0391
179 changed files with 5244 additions and 3894 deletions

View File

@@ -1,16 +1,24 @@
package org.thoughtcrime.securesms.keyvalue;
import android.net.Uri;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference;
import org.thoughtcrime.securesms.util.SingleLiveEvent;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.webrtc.CallBandwidthMode;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("deprecation")
public final class SettingsValues extends SignalStoreValues {
public static final String LINK_PREVIEWS = "settings.link_previews";
@@ -23,8 +31,31 @@ public final class SettingsValues extends SignalStoreValues {
private static final String CALL_BANDWIDTH_MODE = "settings.signal.call.bandwidth.mode";
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
public static final String THREAD_TRIM_ENABLED = "pref_trim_threads";
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
public static final String THREAD_TRIM_ENABLED = "pref_trim_threads";
public static final String THEME = "settings.theme";
public static final String MESSAGE_FONT_SIZE = "settings.message.font.size";
public static final String LANGUAGE = "settings.language";
public static final String PREFER_SYSTEM_EMOJI = "settings.use.system.emoji";
public static final String ENTER_KEY_SENDS = "settings.enter.key.sends";
public static final String BACKUPS_ENABLED = "settings.backups.enabled";
public static final String SMS_DELIVERY_REPORTS_ENABLED = "settings.sms.delivery.reports.enabled";
public static final String WIFI_CALLING_COMPATIBILITY_MODE_ENABLED = "settings.wifi.calling.compatibility.mode.enabled";
public static final String MESSAGE_NOTIFICATIONS_ENABLED = "settings.message.notifications.enabled";
public static final String MESSAGE_NOTIFICATION_SOUND = "settings.message.notifications.sound";
public static final String MESSAGE_VIBRATE_ENABLED = "settings.message.vibrate.enabled";
public static final String MESSAGE_LED_COLOR = "settings.message.led.color";
public static final String MESSAGE_LED_BLINK_PATTERN = "settings.message.led.blink";
public static final String MESSAGE_IN_CHAT_SOUNDS_ENABLED = "settings.message.in.chats.sounds.enabled";
public static final String MESSAGE_REPEAT_ALERTS = "settings.message.repeat.alerts";
public static final String MESSAGE_NOTIFICATION_PRIVACY = "settings.message.notification.privacy";
public static final String CALL_NOTIFICATIONS_ENABLED = "settings.call.notifications.enabled";
public static final String CALL_RINGTONE = "settings.call.ringtone";
public static final String CALL_VIBRATE_ENABLED = "settings.call.vibrate.enabled";
public static final String NOTIFY_WHEN_CONTACT_JOINS_SIGNAL = "settings.notify.when.contact.joins.signal";
private final SingleLiveEvent<String> onConfigurationSettingChanged = new SingleLiveEvent<>();
SettingsValues(@NonNull KeyValueStore store) {
super(store);
@@ -46,7 +77,29 @@ public final class SettingsValues extends SignalStoreValues {
PREFER_SYSTEM_CONTACT_PHOTOS,
CALL_BANDWIDTH_MODE,
THREAD_TRIM_LENGTH,
THREAD_TRIM_ENABLED);
THREAD_TRIM_ENABLED,
LANGUAGE,
THEME,
MESSAGE_FONT_SIZE,
PREFER_SYSTEM_EMOJI,
ENTER_KEY_SENDS,
BACKUPS_ENABLED,
MESSAGE_NOTIFICATIONS_ENABLED,
MESSAGE_NOTIFICATION_SOUND,
MESSAGE_VIBRATE_ENABLED,
MESSAGE_LED_COLOR,
MESSAGE_LED_BLINK_PATTERN,
MESSAGE_IN_CHAT_SOUNDS_ENABLED,
MESSAGE_REPEAT_ALERTS,
MESSAGE_NOTIFICATION_PRIVACY,
CALL_NOTIFICATIONS_ENABLED,
CALL_RINGTONE,
CALL_VIBRATE_ENABLED,
NOTIFY_WHEN_CONTACT_JOINS_SIGNAL);
}
public @NonNull LiveData<String> getOnConfigurationSettingChanged() {
return onConfigurationSettingChanged;
}
public boolean isLinkPreviewsEnabled() {
@@ -114,6 +167,181 @@ public final class SettingsValues extends SignalStoreValues {
return CallBandwidthMode.fromCode(getInteger(CALL_BANDWIDTH_MODE, CallBandwidthMode.HIGH_ALWAYS.getCode()));
}
public @NonNull String getTheme() {
return getString(THEME, TextSecurePreferences.getTheme(ApplicationDependencies.getApplication()));
}
public void setTheme(@NonNull String theme) {
putString(THEME, theme);
onConfigurationSettingChanged.postValue(THEME);
}
public int getMessageFontSize() {
return getInteger(MESSAGE_FONT_SIZE, TextSecurePreferences.getMessageBodyTextSize(ApplicationDependencies.getApplication()));
}
public void setMessageFontSize(int messageFontSize) {
putInteger(MESSAGE_FONT_SIZE, messageFontSize);
}
public @NonNull String getLanguage() {
return TextSecurePreferences.getLanguage(ApplicationDependencies.getApplication());
}
public void setLanguage(@NonNull String language) {
TextSecurePreferences.setLanguage(ApplicationDependencies.getApplication(), language);
onConfigurationSettingChanged.postValue(LANGUAGE);
}
public boolean isPreferSystemEmoji() {
return getBoolean(PREFER_SYSTEM_EMOJI, TextSecurePreferences.isSystemEmojiPreferred(ApplicationDependencies.getApplication()));
}
public void setPreferSystemEmoji(boolean useSystemEmoji) {
putBoolean(PREFER_SYSTEM_EMOJI, useSystemEmoji);
}
public boolean isEnterKeySends() {
return getBoolean(ENTER_KEY_SENDS, TextSecurePreferences.isEnterSendsEnabled(ApplicationDependencies.getApplication()));
}
public void setEnterKeySends(boolean enterKeySends) {
putBoolean(ENTER_KEY_SENDS, enterKeySends);
}
public boolean isBackupEnabled() {
return getBoolean(BACKUPS_ENABLED, TextSecurePreferences.isBackupEnabled(ApplicationDependencies.getApplication()));
}
public void setBackupEnabled(boolean backupEnabled) {
putBoolean(BACKUPS_ENABLED, backupEnabled);
}
public boolean isSmsDeliveryReportsEnabled() {
return getBoolean(SMS_DELIVERY_REPORTS_ENABLED, TextSecurePreferences.isSmsDeliveryReportsEnabled(ApplicationDependencies.getApplication()));
}
public void setSmsDeliveryReportsEnabled(boolean smsDeliveryReportsEnabled) {
putBoolean(SMS_DELIVERY_REPORTS_ENABLED, smsDeliveryReportsEnabled);
}
public boolean isWifiCallingCompatibilityModeEnabled() {
return getBoolean(WIFI_CALLING_COMPATIBILITY_MODE_ENABLED, TextSecurePreferences.isWifiSmsEnabled(ApplicationDependencies.getApplication()));
}
public void setWifiCallingCompatibilityModeEnabled(boolean wifiCallingCompatibilityModeEnabled) {
putBoolean(WIFI_CALLING_COMPATIBILITY_MODE_ENABLED, wifiCallingCompatibilityModeEnabled);
}
public void setMessageNotificationsEnabled(boolean messageNotificationsEnabled) {
putBoolean(MESSAGE_NOTIFICATIONS_ENABLED, messageNotificationsEnabled);
}
public boolean isMessageNotificationsEnabled() {
return getBoolean(MESSAGE_NOTIFICATIONS_ENABLED, TextSecurePreferences.isNotificationsEnabled(ApplicationDependencies.getApplication()));
}
public void setMessageNotificationSound(@NonNull Uri sound) {
putString(MESSAGE_NOTIFICATION_SOUND, sound.toString());
}
public @NonNull Uri getMessageNotificationSound() {
String result = getString(MESSAGE_NOTIFICATION_SOUND, TextSecurePreferences.getNotificationRingtone(ApplicationDependencies.getApplication()).toString());
if (result.startsWith("file:")) {
result = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
}
return Uri.parse(result);
}
public boolean isMessageVibrateEnabled() {
return getBoolean(MESSAGE_VIBRATE_ENABLED, TextSecurePreferences.isNotificationVibrateEnabled(ApplicationDependencies.getApplication()));
}
public void setMessageVibrateEnabled(boolean messageVibrateEnabled) {
putBoolean(MESSAGE_VIBRATE_ENABLED, messageVibrateEnabled);
}
public @NonNull String getMessageLedColor() {
return getString(MESSAGE_LED_COLOR, TextSecurePreferences.getNotificationLedColor(ApplicationDependencies.getApplication()));
}
public void setMessageLedColor(@NonNull String ledColor) {
putString(MESSAGE_LED_COLOR, ledColor);
}
public @NonNull String getMessageLedBlinkPattern() {
return getString(MESSAGE_LED_BLINK_PATTERN, TextSecurePreferences.getNotificationLedPattern(ApplicationDependencies.getApplication()));
}
public void setMessageLedBlinkPattern(@NonNull String blinkPattern) {
putString(MESSAGE_LED_BLINK_PATTERN, blinkPattern);
}
public boolean isMessageNotificationsInChatSoundsEnabled() {
return getBoolean(MESSAGE_IN_CHAT_SOUNDS_ENABLED, TextSecurePreferences.isInThreadNotifications(ApplicationDependencies.getApplication()));
}
public void setMessageNotificationsInChatSoundsEnabled(boolean inChatSoundsEnabled) {
putBoolean(MESSAGE_IN_CHAT_SOUNDS_ENABLED, inChatSoundsEnabled);
}
public int getMessageNotificationsRepeatAlerts() {
return getInteger(MESSAGE_REPEAT_ALERTS, TextSecurePreferences.getRepeatAlertsCount(ApplicationDependencies.getApplication()));
}
public void setMessageNotificationsRepeatAlerts(int count) {
putInteger(MESSAGE_REPEAT_ALERTS, count);
}
public @NonNull NotificationPrivacyPreference getMessageNotificationsPrivacy() {
return new NotificationPrivacyPreference(getString(MESSAGE_NOTIFICATION_PRIVACY, TextSecurePreferences.getNotificationPrivacy(ApplicationDependencies.getApplication()).toString()));
}
public void setMessageNotificationsPrivacy(@NonNull NotificationPrivacyPreference messageNotificationsPrivacy) {
putString(MESSAGE_NOTIFICATION_PRIVACY, messageNotificationsPrivacy.toString());
}
public boolean isCallNotificationsEnabled() {
return getBoolean(CALL_NOTIFICATIONS_ENABLED, TextSecurePreferences.isCallNotificationsEnabled(ApplicationDependencies.getApplication()));
}
public void setCallNotificationsEnabled(boolean callNotificationsEnabled) {
putBoolean(CALL_NOTIFICATIONS_ENABLED, callNotificationsEnabled);
}
public @NonNull Uri getCallRingtone() {
String result = getString(CALL_RINGTONE, TextSecurePreferences.getCallNotificationRingtone(ApplicationDependencies.getApplication()).toString());
if (result != null && result.startsWith("file:")) {
result = Settings.System.DEFAULT_RINGTONE_URI.toString();
}
return Uri.parse(result);
}
public void setCallRingtone(@NonNull Uri ringtone) {
putString(CALL_RINGTONE, ringtone.toString());
}
public boolean isCallVibrateEnabled() {
return getBoolean(CALL_VIBRATE_ENABLED, TextSecurePreferences.isCallNotificationVibrateEnabled(ApplicationDependencies.getApplication()));
}
public void setCallVibrateEnabled(boolean callVibrateEnabled) {
putBoolean(CALL_VIBRATE_ENABLED, callVibrateEnabled);
}
public boolean isNotifyWhenContactJoinsSignal() {
return getBoolean(NOTIFY_WHEN_CONTACT_JOINS_SIGNAL, TextSecurePreferences.isNewContactsNotificationEnabled(ApplicationDependencies.getApplication()));
}
public void setNotifyWhenContactJoinsSignal(boolean notifyWhenContactJoinsSignal) {
putBoolean(NOTIFY_WHEN_CONTACT_JOINS_SIGNAL, notifyWhenContactJoinsSignal);
}
private @Nullable Uri getUri(@NonNull String key) {
String uri = getString(key, "");