Add server-based localization of subscription names and badge information.

This commit is contained in:
Alex Hart
2021-11-03 09:38:42 -03:00
committed by Greyson Parrelli
parent 56c502c9bf
commit 70355aa70e
10 changed files with 40 additions and 29 deletions

View File

@@ -10,6 +10,7 @@ import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription
import org.whispersystems.signalservice.api.subscriptions.SubscriptionLevels
import org.whispersystems.signalservice.internal.ServiceResponse
import java.util.Currency
import java.util.Locale
/**
* Repository which can query for the user's active subscription as well as a list of available subscriptions,
@@ -27,12 +28,13 @@ class SubscriptionsRepository(private val donationsService: DonationsService) {
}
}
fun getSubscriptions(currency: Currency): Single<List<Subscription>> = donationsService.subscriptionLevels
fun getSubscriptions(currency: Currency): Single<List<Subscription>> = donationsService.getSubscriptionLevels(Locale.getDefault())
.flatMap(ServiceResponse<SubscriptionLevels>::flattenResult)
.map { subscriptionLevels ->
subscriptionLevels.levels.map { (code, level) ->
Subscription(
id = code,
name = level.name,
badge = Badges.fromServiceBadge(level.badge),
price = FiatMoney(level.currencies[currency.currencyCode]!!, currency),
level = code.toInt()

View File

@@ -56,7 +56,7 @@ class BoostFragment : DSLSettingsBottomSheetFragment(
.append(" ")
.append(
SpanUtil.learnMore(requireContext(), ContextCompat.getColor(requireContext(), R.color.signal_accent_primary)) {
CommunicationActions.openBrowserLink(requireContext(), R.string.sustainer_boost_and_badges)
CommunicationActions.openBrowserLink(requireContext(), getString(R.string.sustainer_boost_and_badges))
}
)
}

View File

@@ -9,6 +9,7 @@ import org.whispersystems.signalservice.api.services.DonationsService
import org.whispersystems.signalservice.internal.ServiceResponse
import java.math.BigDecimal
import java.util.Currency
import java.util.Locale
class BoostRepository(private val donationsService: DonationsService) {
@@ -22,7 +23,7 @@ class BoostRepository(private val donationsService: DonationsService) {
}
fun getBoostBadge(): Single<Badge> {
return donationsService.boostBadge
return donationsService.getBoostBadge(Locale.getDefault())
.flatMap(ServiceResponse<SignalServiceProfile.Badge>::flattenResult)
.map(Badges::fromServiceBadge)
}

View File

@@ -45,7 +45,7 @@ object ActiveSubscriptionPreference {
override fun bind(model: Model) {
badge.setBadge(model.subscription.badge)
title.text = model.subscription.getTitle(context)
title.text = model.subscription.name
price.text = context.getString(
R.string.MySupportPreference__s_per_month,

View File

@@ -199,7 +199,7 @@ class SubscribeViewModel(
store.update { it.copy(stage = SubscribeState.Stage.TOKEN_REQUEST) }
subscriptionToPurchase = snapshot.selectedSubscription
donationPaymentRepository.requestTokenFromGooglePay(snapshot.selectedSubscription.price, snapshot.selectedSubscription.getTitle(context), fetchTokenRequestCode)
donationPaymentRepository.requestTokenFromGooglePay(snapshot.selectedSubscription.price, snapshot.selectedSubscription.name, fetchTokenRequestCode)
}
fun setSelectedSubscription(subscription: Subscription) {

View File

@@ -1,6 +1,5 @@
package org.thoughtcrime.securesms.subscription
import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
@@ -21,20 +20,12 @@ import java.util.Locale
*/
data class Subscription(
val id: String,
val name: String,
val badge: Badge,
val price: FiatMoney,
val level: Int,
) {
fun getTitle(context: Context): String {
return when (level) {
500 -> context.getString(R.string.SubscribeFragment__sustainer_i)
1000 -> context.getString(R.string.SubscribeFragment__sustainer_ii)
2000 -> context.getString(R.string.SubscribeFragment__sustainer_iii)
else -> ""
}
}
companion object {
fun register(adapter: MappingAdapter) {
adapter.registerFactory(Model::class.java, MappingAdapter.LayoutFactory({ ViewHolder(it) }, R.layout.subscription_preference))
@@ -90,7 +81,7 @@ data class Subscription(
badge.setBadge(model.subscription.badge)
}
title.text = model.subscription.getTitle(context)
title.text = model.subscription.name
tagline.text = context.getString(R.string.Subscription__earn_a_s_badge, model.subscription.badge.name)
val formattedPrice = FiatMoneyUtil.format(