summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt19
1 files changed, 18 insertions, 1 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt
index 5a50e80401..82efd5d722 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt
@@ -1,9 +1,11 @@
package net.mullvad.mullvadvpn.usecase
import android.app.Activity
+import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.flow.transform
import net.mullvad.mullvadvpn.constant.VERIFICATION_BACK_OFF_FACTOR
import net.mullvad.mullvadvpn.constant.VERIFICATION_INITIAL_BACK_OFF_MILLISECONDS
import net.mullvad.mullvadvpn.constant.VERIFICATION_MAX_ATTEMPTS
@@ -35,7 +37,15 @@ class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : Pay
override val purchaseResult = _purchaseResult.asStateFlow()
override suspend fun purchaseProduct(productId: ProductId, activityProvider: () -> Activity) {
- paymentRepository.purchaseProduct(productId, activityProvider).collect(_purchaseResult)
+ paymentRepository
+ .purchaseProduct(productId, activityProvider)
+ .transform {
+ emit(it)
+ if (it.shouldDelayLoading()) {
+ delay(EXTRA_LOADING_DELAY_MS)
+ }
+ }
+ .collect(_purchaseResult)
}
override suspend fun queryPaymentAvailability() {
@@ -64,6 +74,13 @@ class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : Pay
}
}
}
+
+ private fun PurchaseResult?.shouldDelayLoading() =
+ this is PurchaseResult.FetchingProducts || this is PurchaseResult.VerificationStarted
+
+ companion object {
+ const val EXTRA_LOADING_DELAY_MS = 300L
+ }
}
class EmptyPaymentUseCase : PaymentUseCase {