Add Notification profiles.

This commit is contained in:
Cody Henthorne
2021-12-08 13:22:36 -05:00
parent 31e0696395
commit 6c608e955e
106 changed files with 5692 additions and 238 deletions

View File

@@ -0,0 +1,38 @@
package org.thoughtcrime.securesms.keyvalue
import androidx.annotation.VisibleForTesting
/**
* Values for managing enable/disable state and corresponding alerts for Notification Profiles.
*/
internal class NotificationProfileValues(store: KeyValueStore) : SignalStoreValues(store) {
companion object {
private const val KEY_LAST_PROFILE_POPUP = "np.last_profile_popup"
private const val KEY_LAST_PROFILE_POPUP_TIME = "np.last_profile_popup_time"
private const val KEY_SEEN_TOOLTIP = "np.seen_tooltip"
@VisibleForTesting
const val KEY_MANUALLY_ENABLED_PROFILE = "np.manually_enabled_profile"
@VisibleForTesting
const val KEY_MANUALLY_ENABLED_UNTIL = "np.manually_enabled_until"
@VisibleForTesting
const val KEY_MANUALLY_DISABLED_AT = "np.manually_disabled_at"
}
override fun onFirstEverAppLaunch() = Unit
override fun getKeysToIncludeInBackup(): MutableList<String> {
return mutableListOf(KEY_SEEN_TOOLTIP)
}
var manuallyEnabledProfile: Long by longValue(KEY_MANUALLY_ENABLED_PROFILE, 0L)
var manuallyEnabledUntil: Long by longValue(KEY_MANUALLY_ENABLED_UNTIL, 0L)
var manuallyDisabledAt: Long by longValue(KEY_MANUALLY_DISABLED_AT, 0L)
var lastProfilePopup: Long by longValue(KEY_LAST_PROFILE_POPUP, 0L)
var lastProfilePopupTime: Long by longValue(KEY_LAST_PROFILE_POPUP_TIME, 0L)
var hasSeenTooltip: Boolean by booleanValue(KEY_SEEN_TOOLTIP, false)
}

View File

@@ -18,28 +18,29 @@ public final class SignalStore {
private KeyValueStore store;
private final AccountValues accountValues;
private final KbsValues kbsValues;
private final RegistrationValues registrationValues;
private final PinValues pinValues;
private final RemoteConfigValues remoteConfigValues;
private final StorageServiceValues storageServiceValues;
private final UiHints uiHints;
private final TooltipValues tooltipValues;
private final MiscellaneousValues misc;
private final InternalValues internalValues;
private final EmojiValues emojiValues;
private final SettingsValues settingsValues;
private final CertificateValues certificateValues;
private final PhoneNumberPrivacyValues phoneNumberPrivacyValues;
private final OnboardingValues onboardingValues;
private final WallpaperValues wallpaperValues;
private final PaymentsValues paymentsValues;
private final DonationsValues donationsValues;
private final ProxyValues proxyValues;
private final RateLimitValues rateLimitValues;
private final ChatColorsValues chatColorsValues;
private final ImageEditorValues imageEditorValues;
private final AccountValues accountValues;
private final KbsValues kbsValues;
private final RegistrationValues registrationValues;
private final PinValues pinValues;
private final RemoteConfigValues remoteConfigValues;
private final StorageServiceValues storageServiceValues;
private final UiHints uiHints;
private final TooltipValues tooltipValues;
private final MiscellaneousValues misc;
private final InternalValues internalValues;
private final EmojiValues emojiValues;
private final SettingsValues settingsValues;
private final CertificateValues certificateValues;
private final PhoneNumberPrivacyValues phoneNumberPrivacyValues;
private final OnboardingValues onboardingValues;
private final WallpaperValues wallpaperValues;
private final PaymentsValues paymentsValues;
private final DonationsValues donationsValues;
private final ProxyValues proxyValues;
private final RateLimitValues rateLimitValues;
private final ChatColorsValues chatColorsValues;
private final ImageEditorValues imageEditorValues;
private final NotificationProfileValues notificationProfileValues;
private static volatile SignalStore instance;
@@ -56,29 +57,30 @@ public final class SignalStore {
}
private SignalStore(@NonNull KeyValueStore store) {
this.store = store;
this.accountValues = new AccountValues(store);
this.kbsValues = new KbsValues(store);
this.registrationValues = new RegistrationValues(store);
this.pinValues = new PinValues(store);
this.remoteConfigValues = new RemoteConfigValues(store);
this.storageServiceValues = new StorageServiceValues(store);
this.uiHints = new UiHints(store);
this.tooltipValues = new TooltipValues(store);
this.misc = new MiscellaneousValues(store);
this.internalValues = new InternalValues(store);
this.emojiValues = new EmojiValues(store);
this.settingsValues = new SettingsValues(store);
this.certificateValues = new CertificateValues(store);
this.phoneNumberPrivacyValues = new PhoneNumberPrivacyValues(store);
this.onboardingValues = new OnboardingValues(store);
this.wallpaperValues = new WallpaperValues(store);
this.paymentsValues = new PaymentsValues(store);
this.donationsValues = new DonationsValues(store);
this.proxyValues = new ProxyValues(store);
this.rateLimitValues = new RateLimitValues(store);
this.chatColorsValues = new ChatColorsValues(store);
this.imageEditorValues = new ImageEditorValues(store);
this.store = store;
this.accountValues = new AccountValues(store);
this.kbsValues = new KbsValues(store);
this.registrationValues = new RegistrationValues(store);
this.pinValues = new PinValues(store);
this.remoteConfigValues = new RemoteConfigValues(store);
this.storageServiceValues = new StorageServiceValues(store);
this.uiHints = new UiHints(store);
this.tooltipValues = new TooltipValues(store);
this.misc = new MiscellaneousValues(store);
this.internalValues = new InternalValues(store);
this.emojiValues = new EmojiValues(store);
this.settingsValues = new SettingsValues(store);
this.certificateValues = new CertificateValues(store);
this.phoneNumberPrivacyValues = new PhoneNumberPrivacyValues(store);
this.onboardingValues = new OnboardingValues(store);
this.wallpaperValues = new WallpaperValues(store);
this.paymentsValues = new PaymentsValues(store);
this.donationsValues = new DonationsValues(store);
this.proxyValues = new ProxyValues(store);
this.rateLimitValues = new RateLimitValues(store);
this.chatColorsValues = new ChatColorsValues(store);
this.imageEditorValues = new ImageEditorValues(store);
this.notificationProfileValues = new NotificationProfileValues(store);
}
public static void onFirstEverAppLaunch() {
@@ -104,6 +106,7 @@ public final class SignalStore {
rateLimit().onFirstEverAppLaunch();
chatColorsValues().onFirstEverAppLaunch();
imageEditorValues().onFirstEverAppLaunch();
notificationProfileValues().onFirstEverAppLaunch();
}
public static List<String> getKeysToIncludeInBackup() {
@@ -130,6 +133,7 @@ public final class SignalStore {
keys.addAll(rateLimit().getKeysToIncludeInBackup());
keys.addAll(chatColorsValues().getKeysToIncludeInBackup());
keys.addAll(imageEditorValues().getKeysToIncludeInBackup());
keys.addAll(notificationProfileValues().getKeysToIncludeInBackup());
return keys;
}
@@ -230,6 +234,10 @@ public final class SignalStore {
return getInstance().imageEditorValues;
}
public static @NonNull NotificationProfileValues notificationProfileValues() {
return getInstance().notificationProfileValues;
}
public static @NonNull GroupsV2AuthorizationSignalStoreCache groupsV2AuthorizationCache() {
return new GroupsV2AuthorizationSignalStoreCache(getStore());
}

View File

@@ -0,0 +1,104 @@
package org.thoughtcrime.securesms.keyvalue
import kotlin.reflect.KProperty
internal fun SignalStoreValues.longValue(key: String, default: Long): SignalStoreValueDelegate<Long> {
return LongValue(key, default)
}
internal fun SignalStoreValues.booleanValue(key: String, default: Boolean): SignalStoreValueDelegate<Boolean> {
return BooleanValue(key, default)
}
internal fun <T : String?> SignalStoreValues.stringValue(key: String, default: T): SignalStoreValueDelegate<T> {
return StringValue(key, default)
}
internal fun SignalStoreValues.integerValue(key: String, default: Int): SignalStoreValueDelegate<Int> {
return IntValue(key, default)
}
internal fun SignalStoreValues.floatValue(key: String, default: Float): SignalStoreValueDelegate<Float> {
return FloatValue(key, default)
}
internal fun SignalStoreValues.blobValue(key: String, default: ByteArray): SignalStoreValueDelegate<ByteArray> {
return BlobValue(key, default)
}
/**
* Kotlin delegate that serves as a base for all other value types. This allows us to only expose this sealed
* class to callers and protect the individual implementations as private behind the various extension functions.
*/
sealed class SignalStoreValueDelegate<T> {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
return getValue(thisRef as SignalStoreValues)
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
setValue(thisRef as SignalStoreValues, value)
}
internal abstract fun getValue(values: SignalStoreValues): T
internal abstract fun setValue(values: SignalStoreValues, value: T)
}
private class LongValue(private val key: String, private val default: Long) : SignalStoreValueDelegate<Long>() {
override fun getValue(values: SignalStoreValues): Long {
return values.getLong(key, default)
}
override fun setValue(values: SignalStoreValues, value: Long) {
values.putLong(key, value)
}
}
private class BooleanValue(private val key: String, private val default: Boolean) : SignalStoreValueDelegate<Boolean>() {
override fun getValue(values: SignalStoreValues): Boolean {
return values.getBoolean(key, default)
}
override fun setValue(values: SignalStoreValues, value: Boolean) {
values.putBoolean(key, value)
}
}
private class StringValue<T : String?>(private val key: String, private val default: T) : SignalStoreValueDelegate<T>() {
override fun getValue(values: SignalStoreValues): T {
return values.getString(key, default) as T
}
override fun setValue(values: SignalStoreValues, value: T) {
values.putString(key, value)
}
}
private class IntValue(private val key: String, private val default: Int) : SignalStoreValueDelegate<Int>() {
override fun getValue(values: SignalStoreValues): Int {
return values.getInteger(key, default)
}
override fun setValue(values: SignalStoreValues, value: Int) {
values.putInteger(key, value)
}
}
private class FloatValue(private val key: String, private val default: Float) : SignalStoreValueDelegate<Float>() {
override fun getValue(values: SignalStoreValues): Float {
return values.getFloat(key, default)
}
override fun setValue(values: SignalStoreValues, value: Float) {
values.putFloat(key, value)
}
}
private class BlobValue(private val key: String, private val default: ByteArray) : SignalStoreValueDelegate<ByteArray>() {
override fun getValue(values: SignalStoreValues): ByteArray {
return values.getBlob(key, default)
}
override fun setValue(values: SignalStoreValues, value: ByteArray) {
values.putBlob(key, value)
}
}