mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Implement the majority of the Donor UI.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package org.thoughtcrime.securesms.keyvalue
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||
import io.reactivex.rxjava3.subjects.Subject
|
||||
import org.signal.donations.StripeApi
|
||||
import java.util.Currency
|
||||
import java.util.Locale
|
||||
|
||||
internal class DonationsValues internal constructor(store: KeyValueStore) : SignalStoreValues(store) {
|
||||
|
||||
companion object {
|
||||
private const val KEY_CURRENCY_CODE = "donation.currency.code"
|
||||
}
|
||||
|
||||
override fun onFirstEverAppLaunch() = Unit
|
||||
|
||||
override fun getKeysToIncludeInBackup(): MutableList<String> = mutableListOf(KEY_CURRENCY_CODE)
|
||||
|
||||
private val currencyPublisher: Subject<Currency> = BehaviorSubject.createDefault(getCurrency())
|
||||
val observableCurrency: Observable<Currency> = currencyPublisher
|
||||
|
||||
fun getCurrency(): Currency {
|
||||
val currencyCode = getString(KEY_CURRENCY_CODE, null)
|
||||
val currency = if (currencyCode == null) {
|
||||
Currency.getInstance(Locale.getDefault())
|
||||
} else {
|
||||
Currency.getInstance(currencyCode)
|
||||
}
|
||||
|
||||
return if (StripeApi.Validation.supportedCurrencyCodes.contains(currency.currencyCode)) {
|
||||
currency
|
||||
} else {
|
||||
Currency.getInstance("USD")
|
||||
}
|
||||
}
|
||||
|
||||
fun setCurrency(currency: Currency) {
|
||||
putString(KEY_CURRENCY_CODE, currency.currencyCode)
|
||||
currencyPublisher.onNext(currency)
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ public final class SignalStore {
|
||||
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;
|
||||
@@ -57,6 +58,7 @@ public final class SignalStore {
|
||||
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);
|
||||
@@ -80,6 +82,7 @@ public final class SignalStore {
|
||||
onboarding().onFirstEverAppLaunch();
|
||||
wallpaper().onFirstEverAppLaunch();
|
||||
paymentsValues().onFirstEverAppLaunch();
|
||||
donationsValues().onFirstEverAppLaunch();
|
||||
proxy().onFirstEverAppLaunch();
|
||||
rateLimit().onFirstEverAppLaunch();
|
||||
chatColorsValues().onFirstEverAppLaunch();
|
||||
@@ -104,6 +107,7 @@ public final class SignalStore {
|
||||
keys.addAll(onboarding().getKeysToIncludeInBackup());
|
||||
keys.addAll(wallpaper().getKeysToIncludeInBackup());
|
||||
keys.addAll(paymentsValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(donationsValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(proxy().getKeysToIncludeInBackup());
|
||||
keys.addAll(rateLimit().getKeysToIncludeInBackup());
|
||||
keys.addAll(chatColorsValues().getKeysToIncludeInBackup());
|
||||
@@ -184,6 +188,10 @@ public final class SignalStore {
|
||||
return INSTANCE.paymentsValues;
|
||||
}
|
||||
|
||||
public static @NonNull DonationsValues donationsValues() {
|
||||
return INSTANCE.donationsValues;
|
||||
}
|
||||
|
||||
public static @NonNull ProxyValues proxy() {
|
||||
return INSTANCE.proxyValues;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user