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> {
|
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) {
|
return when (tier) {
|
||||||
MessageBackupTier.FREE -> getFreeType()
|
MessageBackupTier.FREE -> getFreeType()
|
||||||
MessageBackupTier.PAID -> getPaidType()
|
MessageBackupTier.PAID -> getPaidType()
|
||||||
|
@ -901,12 +901,12 @@ object BackupRepository {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getPaidType(): MessageBackupsType {
|
private suspend fun getPaidType(): MessageBackupsType? {
|
||||||
val config = getSubscriptionsConfiguration()
|
val config = getSubscriptionsConfiguration()
|
||||||
val product = AppDependencies.billingApi.queryProduct()
|
val product = AppDependencies.billingApi.queryProduct() ?: return null
|
||||||
|
|
||||||
return MessageBackupsType.Paid(
|
return MessageBackupsType.Paid(
|
||||||
pricePerMonth = product!!.price,
|
pricePerMonth = product.price,
|
||||||
storageAllowanceBytes = config.backupConfiguration.backupLevelConfigurationMap[SubscriptionsConfiguration.BACKUPS_LEVEL]!!.storageAllowanceBytes
|
storageAllowanceBytes = config.backupConfiguration.backupLevelConfigurationMap[SubscriptionsConfiguration.BACKUPS_LEVEL]!!.storageAllowanceBytes
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,7 @@ internal class BillingApiImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun queryProduct(): BillingProduct? {
|
override suspend fun queryProduct(): BillingProduct? {
|
||||||
|
try {
|
||||||
val products = queryProductsInternal()
|
val products = queryProductsInternal()
|
||||||
|
|
||||||
val details: ProductDetails? = products.productDetailsList?.firstOrNull { it.productId == billingDependencies.getProductId() }
|
val details: ProductDetails? = products.productDetailsList?.firstOrNull { it.productId == billingDependencies.getProductId() }
|
||||||
|
@ -176,6 +177,10 @@ internal class BillingApiImpl(
|
||||||
return BillingProduct(
|
return BillingProduct(
|
||||||
price = FiatMoney(BigDecimal.valueOf(pricing.priceAmountMicros, 6), Currency.getInstance(pricing.priceCurrencyCode))
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun queryPurchases() {
|
override suspend fun queryPurchases() {
|
||||||
|
@ -291,7 +296,7 @@ internal class BillingApiImpl(
|
||||||
billingResponseCode = billingResult.responseCode
|
billingResponseCode = billingResult.responseCode
|
||||||
)
|
)
|
||||||
trySend(State.Failure(billingError))
|
trySend(State.Failure(billingError))
|
||||||
cancel(CancellationException("Failed to connect to Google Play Billing", billingError))
|
channel.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue