? = sharedPreferences[MEDIA_DOWNLOAD_ROAMING_PREF]
+ fun getLogEncryptedSecret(): String? = sharedPreferences[LOG_ENCRYPTED_SECRET]
+ fun setLogEncryptedSecret(base64Secret: String?) = set(LOG_ENCRYPTED_SECRET, base64Secret)
+ fun getLogUnencryptedSecret(): String? = sharedPreferences[LOG_UNENCRYPTED_SECRET]
+ fun getNotificationChannelVersion(): Int = sharedPreferences[NOTIFICATION_CHANNEL_VERSION]
+ fun setNotificationChannelVersion(version: Int) = set(NOTIFICATION_CHANNEL_VERSION, version)
+ fun getNotificationMessagesChannelVersion(): Int = sharedPreferences[NOTIFICATION_MESSAGES_CHANNEL_VERSION]
+ fun setNotificationMessagesChannelVersion(version: Int) = set(NOTIFICATION_MESSAGES_CHANNEL_VERSION, version)
+ fun hasViewedSeed(): Boolean = sharedPreferences[HAS_VIEWED_SEED]
+ fun setHasViewedSeed(hasViewedSeed: Boolean) = set(HAS_VIEWED_SEED, hasViewedSeed)
+ fun getLastProfilePictureUpload(): Long = sharedPreferences[LAST_PROFILE_PICTURE_UPLOAD]
+ fun setLastProfilePictureUpload(newValue: Long) = set(LAST_PROFILE_PICTURE_UPLOAD, newValue)
+ fun getLastSnodePoolRefreshDate(): Long = sharedPreferences[LAST_SNODE_POOL_REFRESH_DATE]
+ fun setLastSnodePoolRefreshDate(date: Date) = set(LAST_SNODE_POOL_REFRESH_DATE, date.time)
+ fun shouldUpdateProfile(profileUpdateTime: Long): Boolean = profileUpdateTime > sharedPreferences[LAST_PROFILE_UPDATE_TIME]
+ fun setLastProfileUpdateTime(profileUpdateTime: Long) = set(LAST_PROFILE_UPDATE_TIME, profileUpdateTime)
+ fun getLastOpenTimeDate(): Long = sharedPreferences[LAST_OPEN_DATE]
+ fun setLastOpenDate() = set(LAST_OPEN_DATE, System.currentTimeMillis())
+ fun hasSeenLinkPreviewSuggestionDialog(): Boolean = sharedPreferences[HAS_SEEN_LINK_PREVIEW_SUGGESTION_DIALOG]
+ fun setHasSeenLinkPreviewSuggestionDialog() = set(HAS_SEEN_LINK_PREVIEW_SUGGESTION_DIALOG, true)
+ fun isCallNotificationsEnabled(): Boolean = sharedPreferences[CALL_NOTIFICATIONS_ENABLED]
+ fun setCallNotificationsEnabled(enabled: Boolean) = set(CALL_NOTIFICATIONS_ENABLED, enabled)
+ fun getLastVacuumTime(): Long = sharedPreferences[LAST_VACUUM_TIME]
+ fun setLastVacuumNow() = set(LAST_VACUUM_TIME, System.currentTimeMillis())
+ fun setShownCallNotification(): Boolean = when {
+ sharedPreferences[SHOWN_CALL_NOTIFICATION] -> false
+ else -> {
+ set(SHOWN_CALL_NOTIFICATION, true)
+ true
+ }
+ }
+ fun hasHiddenMessageRequests(): Boolean = sharedPreferences[HAS_HIDDEN_MESSAGE_REQUESTS]
+ fun hasHiddenMessageRequestsFlow() = flow(HAS_HIDDEN_MESSAGE_REQUESTS)
+ fun setHasHiddenMessageRequests() = set(HAS_HIDDEN_MESSAGE_REQUESTS, true)
+ fun removeHasHiddenMessageRequests() = remove(HAS_HIDDEN_MESSAGE_REQUESTS)
+ fun getFingerprintKeyGenerated(): Boolean = sharedPreferences[FINGERPRINT_KEY_GENERATED]
+ fun setFingerprintKeyGenerated() = set(FINGERPRINT_KEY_GENERATED, true)
+
+ fun hasSelectedAccentColor() = has(SELECTED_ACCENT_COLOR)
+ fun getSelectedAccentColor(): String? = sharedPreferences[SELECTED_ACCENT_COLOR]
+
+ var hasAppliedPatchSnodeVersion: Boolean
+ get() = sharedPreferences[PATCH_SNODE_VERSION_2024_07_23]
+ set(value) = set(PATCH_SNODE_VERSION_2024_07_23, value)
@StyleRes
- override fun getAccentColorStyle(): Int? {
- return when (getSelectedAccentColor()) {
- TextSecurePreferences.GREEN_ACCENT -> R.style.PrimaryGreen
- TextSecurePreferences.BLUE_ACCENT -> R.style.PrimaryBlue
- TextSecurePreferences.PURPLE_ACCENT -> R.style.PrimaryPurple
- TextSecurePreferences.PINK_ACCENT -> R.style.PrimaryPink
- TextSecurePreferences.RED_ACCENT -> R.style.PrimaryRed
- TextSecurePreferences.ORANGE_ACCENT -> R.style.PrimaryOrange
- TextSecurePreferences.YELLOW_ACCENT -> R.style.PrimaryYellow
- else -> null
- }
- }
-
- override fun setAccentColorStyle(@StyleRes newColorStyle: Int?) {
- setStringPreference(
- TextSecurePreferences.SELECTED_ACCENT_COLOR, when (newColorStyle) {
- R.style.PrimaryGreen -> TextSecurePreferences.GREEN_ACCENT
- R.style.PrimaryBlue -> TextSecurePreferences.BLUE_ACCENT
- R.style.PrimaryPurple -> TextSecurePreferences.PURPLE_ACCENT
- R.style.PrimaryPink -> TextSecurePreferences.PINK_ACCENT
- R.style.PrimaryRed -> TextSecurePreferences.RED_ACCENT
- R.style.PrimaryOrange -> TextSecurePreferences.ORANGE_ACCENT
- R.style.PrimaryYellow -> TextSecurePreferences.YELLOW_ACCENT
- else -> null
- }
- )
+ fun getAccentColorStyle(): Int? = when (getSelectedAccentColor()) {
+ GREEN_ACCENT -> R.style.PrimaryGreen
+ BLUE_ACCENT -> R.style.PrimaryBlue
+ PURPLE_ACCENT -> R.style.PrimaryPurple
+ PINK_ACCENT -> R.style.PrimaryPink
+ RED_ACCENT -> R.style.PrimaryRed
+ ORANGE_ACCENT -> R.style.PrimaryOrange
+ YELLOW_ACCENT -> R.style.PrimaryYellow
+ else -> null
}
- override fun getThemeStyle(): String {
- val hasLegacy = getStringPreference(LEGACY_PREF_KEY_SELECTED_UI_MODE, null)
- if (!hasLegacy.isNullOrEmpty()) {
- migrateLegacyUiPref()
- }
+ fun setAccentColorStyle(@StyleRes newColorStyle: Int?) = when (newColorStyle) {
+ R.style.PrimaryGreen -> GREEN_ACCENT
+ R.style.PrimaryBlue -> BLUE_ACCENT
+ R.style.PrimaryPurple -> PURPLE_ACCENT
+ R.style.PrimaryPink -> PINK_ACCENT
+ R.style.PrimaryRed -> RED_ACCENT
+ R.style.PrimaryOrange -> ORANGE_ACCENT
+ R.style.PrimaryYellow -> YELLOW_ACCENT
+ else -> null
+ }.let { set(SELECTED_ACCENT_COLOR, it) }
- return getStringPreference(SELECTED_STYLE, CLASSIC_DARK)!!
+ fun getThemeStyle(): String {
+ migrateLegacyUiPrefIfNecessary()
+ return sharedPreferences[SELECTED_STYLE]
}
- override fun setThemeStyle(themeStyle: String) {
- val safeTheme = if (themeStyle !in listOf(CLASSIC_DARK, CLASSIC_LIGHT, OCEAN_DARK, OCEAN_LIGHT)) CLASSIC_DARK else themeStyle
- setStringPreference(SELECTED_STYLE, safeTheme)
+ fun setThemeStyle(themeStyle: String) {
+ sharedPreferences[SELECTED_STYLE] = if (themeStyle !in listOf(CLASSIC_DARK, CLASSIC_LIGHT, OCEAN_DARK, OCEAN_LIGHT)) CLASSIC_DARK else themeStyle
}
- override fun getFollowSystemSettings(): Boolean {
- val hasLegacy = getStringPreference(LEGACY_PREF_KEY_SELECTED_UI_MODE, null)
- if (!hasLegacy.isNullOrEmpty()) {
- migrateLegacyUiPref()
- }
-
- return getBooleanPreference(FOLLOW_SYSTEM_SETTINGS, false)
+ fun getFollowSystemSettings(): Boolean {
+ migrateLegacyUiPrefIfNecessary()
+ return sharedPreferences[FOLLOW_SYSTEM_SETTINGS]
}
- private fun migrateLegacyUiPref() {
- val legacy = getStringPreference(LEGACY_PREF_KEY_SELECTED_UI_MODE, null) ?: return
+ private fun migrateLegacyUiPrefIfNecessary() {
+ val legacy = sharedPreferences[LEGACY_PREF_KEY_SELECTED_UI_MODE] ?: return
val (mode, followSystem) = when (legacy) {
- "DAY" -> {
- CLASSIC_LIGHT to false
- }
- "NIGHT" -> {
- CLASSIC_DARK to false
- }
- "SYSTEM_DEFAULT" -> {
- CLASSIC_DARK to true
- }
- else -> {
- CLASSIC_DARK to false
- }
+ "DAY" -> CLASSIC_LIGHT to false
+ "NIGHT" -> CLASSIC_DARK to false
+ "SYSTEM_DEFAULT" -> CLASSIC_DARK to true
+ else -> CLASSIC_DARK to false
}
- if (!hasPreference(FOLLOW_SYSTEM_SETTINGS) && !hasPreference(SELECTED_STYLE)) {
+ if (!has(FOLLOW_SYSTEM_SETTINGS) && !has(SELECTED_STYLE)) {
setThemeStyle(mode)
setFollowSystemSettings(followSystem)
}
- removePreference(LEGACY_PREF_KEY_SELECTED_UI_MODE)
- }
-
- override fun setFollowSystemSettings(followSystemSettings: Boolean) {
- setBooleanPreference(FOLLOW_SYSTEM_SETTINGS, followSystemSettings)
- }
-
- override fun autoplayAudioMessages(): Boolean {
- return getBooleanPreference(AUTOPLAY_AUDIO_MESSAGES, false)
- }
-
- override fun clearAll() {
- getDefaultSharedPreferences(context).edit().clear().commit()
+ remove(LEGACY_PREF_KEY_SELECTED_UI_MODE)
}
- override fun getHidePassword() = getBooleanPreference(HIDE_PASSWORD, false)
-
- override fun setHidePassword(value: Boolean) {
- setBooleanPreference(HIDE_PASSWORD, value)
- }
+ fun setFollowSystemSettings(followSystemSettings: Boolean) = set(FOLLOW_SYSTEM_SETTINGS, followSystemSettings)
+ fun autoplayAudioMessages(): Boolean = sharedPreferences[AUTOPLAY_AUDIO_MESSAGES]
+ fun clearAll() = getDefaultSharedPreferences(context).edit().clear().commit()
+ fun getHidePassword() = sharedPreferences[HIDE_PASSWORD]
+ fun setHidePassword(value: Boolean) = set(HIDE_PASSWORD, value)
}
+
+fun PreferenceFragmentCompat.findPreference(pref: Pref<*>) = findPreference
(pref.name)
diff --git a/libsession/src/main/java/org/session/libsession/utilities/Util.kt b/libsession/src/main/java/org/session/libsession/utilities/Util.kt
index 929f53e305e..5f076ec286d 100644
--- a/libsession/src/main/java/org/session/libsession/utilities/Util.kt
+++ b/libsession/src/main/java/org/session/libsession/utilities/Util.kt
@@ -11,6 +11,7 @@ import android.text.Spannable
import android.text.SpannableString
import android.text.TextUtils
import android.text.style.StyleSpan
+import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.Base64
import java.io.*
@@ -209,8 +210,8 @@ object Util {
}
@JvmStatic
- fun isOwnNumber(context: Context, number: String): Boolean {
- return TextSecurePreferences.getLocalNumber(context).equals(number)
+ fun isOwnNumber(number: String): Boolean {
+ return MessagingModuleConfiguration.shared.context.prefs.getLocalNumber().equals(number)
}
@JvmStatic
diff --git a/libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java b/libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java
index 0aef1583872..fcf353d88c9 100644
--- a/libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java
+++ b/libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java
@@ -17,6 +17,8 @@
*/
package org.session.libsession.utilities.recipients;
+import static org.session.libsession.utilities.TextSecurePreferencesKt.getPrefs;
+
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -524,7 +526,7 @@ public synchronized String toShortString() {
}
public synchronized @Nullable ContactPhoto getContactPhoto() {
- if (isLocalNumber) return new ProfileContactPhoto(address, String.valueOf(TextSecurePreferences.getProfileAvatarId(context)));
+ if (isLocalNumber) return new ProfileContactPhoto(address, String.valueOf(getPrefs(MessagingModuleConfiguration.getShared().getContext()).getProfileAvatarId()));
else if (isGroupRecipient() && groupAvatarId != null) return new GroupRecordContactPhoto(address, groupAvatarId);
else if (systemContactPhoto != null) return new SystemContactPhoto(address, systemContactPhoto, 0);
else if (profileAvatar != null) return new ProfileContactPhoto(address, profileAvatar);
diff --git a/libsession/src/main/java/org/session/libsession/utilities/recipients/RecipientProvider.java b/libsession/src/main/java/org/session/libsession/utilities/recipients/RecipientProvider.java
index 374956072bc..f6488e2bcfc 100644
--- a/libsession/src/main/java/org/session/libsession/utilities/recipients/RecipientProvider.java
+++ b/libsession/src/main/java/org/session/libsession/utilities/recipients/RecipientProvider.java
@@ -16,6 +16,8 @@
*/
package org.session.libsession.utilities.recipients;
+import static org.session.libsession.utilities.TextSecurePreferencesKt.getPrefs;
+
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
@@ -80,14 +82,16 @@ boolean removeCached(@NonNull Address address) {
return recipientCache.remove(address);
}
- private @NonNull Optional createPrefetchedRecipientDetails(@NonNull Context context, @NonNull Address address,
+ private @NonNull Optional createPrefetchedRecipientDetails(@NonNull Context context,
+ @NonNull Address address,
@NonNull Optional settings,
@NonNull Optional groupRecord)
{
if (address.isGroup() && settings.isPresent() && groupRecord.isPresent()) {
return Optional.of(getGroupRecipientDetails(context, address, groupRecord, settings, true));
} else if (!address.isGroup() && settings.isPresent()) {
- boolean isLocalNumber = address.serialize().equals(TextSecurePreferences.getLocalNumber(context));
+ TextSecurePreferences prefs = getPrefs(context);
+ boolean isLocalNumber = address.serialize().equals(prefs.getLocalNumber());
return Optional.of(new RecipientDetails(null, null, !TextUtils.isEmpty(settings.get().getSystemDisplayName()), isLocalNumber, settings.get(), null));
}
@@ -114,7 +118,8 @@ boolean removeCached(@NonNull Address address) {
}
boolean systemContact = settings.isPresent() && !TextUtils.isEmpty(settings.get().getSystemDisplayName());
- boolean isLocalNumber = address.serialize().equals(TextSecurePreferences.getLocalNumber(context));
+ TextSecurePreferences prefs = getPrefs(context);
+ boolean isLocalNumber = address.serialize().equals(prefs.getLocalNumber());
return new RecipientDetails(null, null, systemContact, isLocalNumber, settings.orNull(), null);
}