Hide paid tier on devices where the billing API is not available.
This commit is contained in:
parent
d88265ede6
commit
d23ef647d8
2 changed files with 20 additions and 15 deletions
|
@ -883,10 +883,10 @@ object BackupRepository {
|
|||
}
|
||||
|
||||
suspend fun getAvailableBackupsTypes(availableBackupTiers: List<MessageBackupTier>): List<MessageBackupsType> {
|
||||
return availableBackupTiers.map { getBackupsType(it) }
|
||||
return availableBackupTiers.mapNotNull { getBackupsType(it) }
|
||||
}
|
||||
|
||||
suspend fun getBackupsType(tier: MessageBackupTier): MessageBackupsType {
|
||||
suspend fun getBackupsType(tier: MessageBackupTier): MessageBackupsType? {
|
||||
return when (tier) {
|
||||
MessageBackupTier.FREE -> getFreeType()
|
||||
MessageBackupTier.PAID -> getPaidType()
|
||||
|
@ -901,12 +901,12 @@ object BackupRepository {
|
|||
)
|
||||
}
|
||||
|
||||
private suspend fun getPaidType(): MessageBackupsType {
|
||||
private suspend fun getPaidType(): MessageBackupsType? {
|
||||
val config = getSubscriptionsConfiguration()
|
||||
val product = AppDependencies.billingApi.queryProduct()
|
||||
val product = AppDependencies.billingApi.queryProduct() ?: return null
|
||||
|
||||
return MessageBackupsType.Paid(
|
||||
pricePerMonth = product!!.price,
|
||||
pricePerMonth = product.price,
|
||||
storageAllowanceBytes = config.backupConfiguration.backupLevelConfigurationMap[SubscriptionsConfiguration.BACKUPS_LEVEL]!!.storageAllowanceBytes
|
||||
)
|
||||
}
|
||||
|
|
|
@ -163,19 +163,24 @@ internal class BillingApiImpl(
|
|||
}
|
||||
|
||||
override suspend fun queryProduct(): BillingProduct? {
|
||||
val products = queryProductsInternal()
|
||||
try {
|
||||
val products = queryProductsInternal()
|
||||
|
||||
val details: ProductDetails? = products.productDetailsList?.firstOrNull { it.productId == billingDependencies.getProductId() }
|
||||
val pricing: ProductDetails.PricingPhase? = details?.subscriptionOfferDetails?.firstOrNull()?.pricingPhases?.pricingPhaseList?.firstOrNull()
|
||||
val details: ProductDetails? = products.productDetailsList?.firstOrNull { it.productId == billingDependencies.getProductId() }
|
||||
val pricing: ProductDetails.PricingPhase? = details?.subscriptionOfferDetails?.firstOrNull()?.pricingPhases?.pricingPhaseList?.firstOrNull()
|
||||
|
||||
if (pricing == null) {
|
||||
Log.d(TAG, "No pricing available.")
|
||||
if (pricing == null) {
|
||||
Log.d(TAG, "No pricing available.")
|
||||
return null
|
||||
}
|
||||
|
||||
return BillingProduct(
|
||||
price = FiatMoney(BigDecimal.valueOf(pricing.priceAmountMicros, 6), Currency.getInstance(pricing.priceCurrencyCode))
|
||||
)
|
||||
} catch (e: BillingError) {
|
||||
Log.w(TAG, "Failed to query product. Returning null. Error code: ${e.billingResponseCode}", e)
|
||||
return null
|
||||
}
|
||||
|
||||
return BillingProduct(
|
||||
price = FiatMoney(BigDecimal.valueOf(pricing.priceAmountMicros, 6), Currency.getInstance(pricing.priceCurrencyCode))
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun queryPurchases() {
|
||||
|
@ -291,7 +296,7 @@ internal class BillingApiImpl(
|
|||
billingResponseCode = billingResult.responseCode
|
||||
)
|
||||
trySend(State.Failure(billingError))
|
||||
cancel(CancellationException("Failed to connect to Google Play Billing", billingError))
|
||||
channel.close()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue