mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Remove deprecated LevelConfiguration#name.
Co-authored-by: Alex Hart <alex@signal.org>
This commit is contained in:
committed by
Greyson Parrelli
parent
200132e623
commit
ba34a74e2d
@@ -24,7 +24,7 @@ private const val SEPA_DEBIT = "SEPA_DEBIT"
|
||||
* PAYPAL - PayPal
|
||||
*
|
||||
* @param level The subscription level to get amounts for
|
||||
* @param paymentMethodAvailability Predicate object which checks whether different payment methods are availble.
|
||||
* @param paymentMethodAvailability Predicate object which checks whether different payment methods are available.
|
||||
*/
|
||||
fun SubscriptionsConfiguration.getSubscriptionAmounts(
|
||||
level: Int,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.subscription
|
||||
|
||||
import android.content.Context
|
||||
import org.signal.donations.InAppPaymentType
|
||||
import org.signal.donations.PaymentSourceType
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentReceiptRecord
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.util.Environment
|
||||
@@ -100,4 +103,32 @@ object InAppDonations {
|
||||
fun isIDEALAvailbleForDonateToSignalType(inAppPaymentType: InAppPaymentType): Boolean {
|
||||
return inAppPaymentType != InAppPaymentType.ONE_TIME_GIFT && isIDEALAvailable()
|
||||
}
|
||||
|
||||
/**
|
||||
* Labels are utilized when displaying Google Play sheet and when displaying receipts.
|
||||
*/
|
||||
fun resolveLabel(context: Context, inAppPaymentType: InAppPaymentType, level: Long): String {
|
||||
return when (inAppPaymentType) {
|
||||
InAppPaymentType.UNKNOWN -> error("Unsupported type.")
|
||||
InAppPaymentType.ONE_TIME_GIFT -> context.getString(R.string.DonationReceiptListFragment__donation_for_a_friend)
|
||||
InAppPaymentType.ONE_TIME_DONATION -> context.getString(R.string.DonationReceiptListFragment__one_time)
|
||||
InAppPaymentType.RECURRING_DONATION -> context.getString(R.string.InAppDonations__recurring_d, level)
|
||||
InAppPaymentType.RECURRING_BACKUP -> error("Unsupported type.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Labels are utilized when displaying Google Play sheet and when displaying receipts.
|
||||
*/
|
||||
fun resolveLabel(context: Context, inAppPaymentReceiptRecord: InAppPaymentReceiptRecord): String {
|
||||
val level = inAppPaymentReceiptRecord.subscriptionLevel
|
||||
val type: InAppPaymentType = when (inAppPaymentReceiptRecord.type) {
|
||||
InAppPaymentReceiptRecord.Type.RECURRING_BACKUP -> InAppPaymentType.RECURRING_BACKUP
|
||||
InAppPaymentReceiptRecord.Type.RECURRING_DONATION -> InAppPaymentType.RECURRING_DONATION
|
||||
InAppPaymentReceiptRecord.Type.ONE_TIME_DONATION -> InAppPaymentType.ONE_TIME_DONATION
|
||||
InAppPaymentReceiptRecord.Type.ONE_TIME_GIFT -> InAppPaymentType.ONE_TIME_GIFT
|
||||
}
|
||||
|
||||
return resolveLabel(context, type, level.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,6 @@ object RecurringInAppPaymentRepository {
|
||||
Subscription(
|
||||
id = level.toString(),
|
||||
level = level,
|
||||
name = levelConfig.name,
|
||||
badge = Badges.fromServiceBadge(levelConfig.badge),
|
||||
prices = config.getSubscriptionAmounts(level)
|
||||
)
|
||||
|
||||
@@ -206,7 +206,6 @@ class DonateToSignalViewModel(
|
||||
endOfPeriod = null,
|
||||
inAppPaymentData = InAppPaymentData(
|
||||
badge = snapshot.badge?.let { Badges.toDatabaseBadge(it) },
|
||||
label = snapshot.badge?.description ?: "",
|
||||
amount = amount.toFiatValue(),
|
||||
level = snapshot.level.toLong(),
|
||||
recipientId = Recipient.self().id.serialize(),
|
||||
|
||||
@@ -160,7 +160,7 @@ class InAppPaymentCheckoutDelegate(
|
||||
viewModel.provideGatewayRequestForGooglePay(inAppPayment)
|
||||
inAppPaymentComponent.stripeRepository.requestTokenFromGooglePay(
|
||||
price = inAppPayment.data.amount!!.toFiatMoney(),
|
||||
label = inAppPayment.data.label,
|
||||
label = InAppDonations.resolveLabel(fragment.requireContext(), inAppPayment.type, inAppPayment.data.level),
|
||||
requestCode = InAppPaymentsRepository.getGooglePayRequestCode(inAppPayment.type)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ data class Stripe3DSData(
|
||||
InAppPaymentType.RECURRING_BACKUP -> ExternalLaunchTransactionState.GatewayRequest.InAppPaymentType.RECURRING_BACKUPS
|
||||
},
|
||||
badge = inAppPayment.data.badge,
|
||||
label = inAppPayment.data.label,
|
||||
price = inAppPayment.data.amount!!.amount,
|
||||
currencyCode = inAppPayment.data.amount.currencyCode,
|
||||
level = inAppPayment.data.level,
|
||||
@@ -92,7 +91,6 @@ data class Stripe3DSData(
|
||||
data = InAppPaymentData(
|
||||
paymentMethodType = PaymentSourceType.fromCode(proto.paymentSourceType).toPaymentMethodType(),
|
||||
badge = proto.gatewayRequest.badge,
|
||||
label = proto.gatewayRequest.label,
|
||||
amount = FiatValue(amount = proto.gatewayRequest.price, currencyCode = proto.gatewayRequest.currencyCode),
|
||||
level = proto.gatewayRequest.level,
|
||||
recipientId = null,
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.thoughtcrime.securesms.components.SignalProgressDialog
|
||||
import org.thoughtcrime.securesms.components.settings.DSLConfiguration
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsFragment
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsText
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppDonations
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.receipts.ReceiptImageRenderer
|
||||
import org.thoughtcrime.securesms.components.settings.configure
|
||||
import org.thoughtcrime.securesms.components.settings.models.SplashImage
|
||||
@@ -38,10 +39,9 @@ class DonationReceiptDetailFragment : DSLSettingsFragment(layoutId = R.layout.do
|
||||
|
||||
viewModel.state.observe(viewLifecycleOwner) { state ->
|
||||
if (state.inAppPaymentReceiptRecord != null) {
|
||||
adapter.submitList(getConfiguration(state.inAppPaymentReceiptRecord, state.subscriptionName).toMappingModelList())
|
||||
}
|
||||
val subscriptionName = InAppDonations.resolveLabel(requireContext(), state.inAppPaymentReceiptRecord)
|
||||
adapter.submitList(getConfiguration(state.inAppPaymentReceiptRecord, subscriptionName).toMappingModelList())
|
||||
|
||||
if (state.inAppPaymentReceiptRecord != null && state.subscriptionName != null) {
|
||||
sharePngButton.isEnabled = true
|
||||
sharePngButton.setOnClickListener {
|
||||
progressDialog = SignalProgressDialog.show(requireContext())
|
||||
@@ -49,7 +49,7 @@ class DonationReceiptDetailFragment : DSLSettingsFragment(layoutId = R.layout.do
|
||||
context = requireContext(),
|
||||
lifecycleOwner = viewLifecycleOwner,
|
||||
record = state.inAppPaymentReceiptRecord,
|
||||
subscriptionName = state.subscriptionName,
|
||||
subscriptionName = InAppDonations.resolveLabel(requireContext(), state.inAppPaymentReceiptRecord),
|
||||
callback = object : ReceiptImageRenderer.Callback {
|
||||
override fun onBitmapRendered() {
|
||||
progressDialog.dismiss()
|
||||
|
||||
@@ -2,26 +2,10 @@ package org.thoughtcrime.securesms.components.settings.app.subscription.receipts
|
||||
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.getSubscriptionLevels
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentReceiptRecord
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import java.util.Locale
|
||||
|
||||
class DonationReceiptDetailRepository {
|
||||
fun getSubscriptionLevelName(subscriptionLevel: Int): Single<String> {
|
||||
return Single
|
||||
.fromCallable {
|
||||
AppDependencies
|
||||
.donationsService
|
||||
.getDonationsConfiguration(Locale.getDefault())
|
||||
}
|
||||
.flatMap { it.flattenResult() }
|
||||
.map { it.getSubscriptionLevels()[subscriptionLevel] ?: throw Exception("Subscription level $subscriptionLevel not found") }
|
||||
.map { it.name }
|
||||
.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
fun getDonationReceiptRecord(id: Long): Single<InAppPaymentReceiptRecord> {
|
||||
return Single.fromCallable<InAppPaymentReceiptRecord> {
|
||||
SignalDatabase.donationReceipts.getReceipt(id)!!
|
||||
|
||||
@@ -3,6 +3,5 @@ package org.thoughtcrime.securesms.components.settings.app.subscription.receipts
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentReceiptRecord
|
||||
|
||||
data class DonationReceiptDetailState(
|
||||
val inAppPaymentReceiptRecord: InAppPaymentReceiptRecord? = null,
|
||||
val subscriptionName: String? = null
|
||||
val inAppPaymentReceiptRecord: InAppPaymentReceiptRecord? = null
|
||||
)
|
||||
|
||||
@@ -5,61 +5,32 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentReceiptRecord
|
||||
import org.thoughtcrime.securesms.util.InternetConnectionObserver
|
||||
import org.thoughtcrime.securesms.util.livedata.Store
|
||||
|
||||
class DonationReceiptDetailViewModel(id: Long, private val repository: DonationReceiptDetailRepository) : ViewModel() {
|
||||
|
||||
private val store = Store(DonationReceiptDetailState())
|
||||
private val disposables = CompositeDisposable()
|
||||
private var networkDisposable: Disposable
|
||||
private val cachedRecord: Single<InAppPaymentReceiptRecord> = repository.getDonationReceiptRecord(id).cache()
|
||||
|
||||
val state: LiveData<DonationReceiptDetailState> = store.stateLiveData
|
||||
|
||||
init {
|
||||
networkDisposable = InternetConnectionObserver
|
||||
.observe()
|
||||
.distinctUntilChanged()
|
||||
.subscribe { isConnected ->
|
||||
if (isConnected) {
|
||||
retry()
|
||||
}
|
||||
}
|
||||
|
||||
refresh()
|
||||
}
|
||||
|
||||
private fun retry() {
|
||||
if (store.state.subscriptionName == null) {
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
disposables.clear()
|
||||
|
||||
disposables += cachedRecord.subscribe { record ->
|
||||
store.update { it.copy(inAppPaymentReceiptRecord = record) }
|
||||
}
|
||||
|
||||
disposables += cachedRecord.flatMap {
|
||||
if (it.subscriptionLevel > 0) {
|
||||
repository.getSubscriptionLevelName(it.subscriptionLevel)
|
||||
} else {
|
||||
Single.just("")
|
||||
}
|
||||
}.subscribe { name ->
|
||||
store.update { it.copy(subscriptionName = name) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
disposables.clear()
|
||||
networkDisposable.dispose()
|
||||
}
|
||||
|
||||
class Factory(private val id: Long, private val repository: DonationReceiptDetailRepository) : ViewModelProvider.Factory {
|
||||
|
||||
Reference in New Issue
Block a user