mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-15 10:46:12 -04:00
Improve upgrade UI
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package eu.darken.capod.common.upgrade.core
|
||||
|
||||
import android.app.Activity
|
||||
import android.widget.Toast
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.coroutine.AppScope
|
||||
import eu.darken.capod.common.coroutine.DispatcherProvider
|
||||
import eu.darken.capod.common.debug.logging.Logging.Priority.VERBOSE
|
||||
import eu.darken.capod.common.debug.logging.asLog
|
||||
import eu.darken.capod.common.debug.logging.log
|
||||
@@ -19,15 +21,17 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.time.Instant
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class UpgradeRepoGplay @Inject constructor(
|
||||
@AppScope private val scope: CoroutineScope,
|
||||
private val dispatcherProvider: DispatcherProvider,
|
||||
private val billingDataRepo: BillingDataRepo,
|
||||
private val billingCache: BillingCache,
|
||||
@AppScope private val scope: CoroutineScope,
|
||||
) : UpgradeRepo {
|
||||
|
||||
private var lastProStateAt: Long
|
||||
@@ -57,7 +61,7 @@ class UpgradeRepoGplay @Inject constructor(
|
||||
.catch {
|
||||
// Ignore Google Play errors if the last pro state was recent
|
||||
val now = System.currentTimeMillis()
|
||||
log(TAG) { "now=$now, lastProStateAt=$lastProStateAt, error=${it.toString()}" }
|
||||
log(TAG) { "now=$now, lastProStateAt=$lastProStateAt, error=$it" }
|
||||
if ((now - lastProStateAt) < 6 * 60 * 60 * 1000L) { // 6 hours
|
||||
log(TAG, VERBOSE) { "We are not pro, but were recently, and just and an error, what is GPlay doing???" }
|
||||
emit(Info(gracePeriod = true, billingData = null))
|
||||
@@ -78,19 +82,32 @@ class UpgradeRepoGplay @Inject constructor(
|
||||
billingDataRepo.startIapFlow(activity, CapodSku.PRO_UPGRADE.sku)
|
||||
} catch (e: Exception) {
|
||||
log(TAG) { "startIapFlow failed:${e.asLog()}" }
|
||||
e.asErrorDialogBuilder(activity).show()
|
||||
withContext(dispatcherProvider.Main) {
|
||||
e.asErrorDialogBuilder(activity).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setNeutralButton(R.string.general_check_action) { _, _ ->
|
||||
setNeutralButton(R.string.general_check_action) { dialog, _ ->
|
||||
log(TAG) { "recheck()" }
|
||||
scope.launch {
|
||||
try {
|
||||
val data = billingDataRepo.getIapData()
|
||||
log(TAG) { "Recheck successful: $data" }
|
||||
withContext(dispatcherProvider.Main) {
|
||||
if (data.purchases.isEmpty()) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
R.string.upgrades_no_purchases_found_check_account,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log(TAG) { "Recheck failed:${e.asLog()}" }
|
||||
e.asErrorDialogBuilder(activity).show()
|
||||
withContext(dispatcherProvider.Main) {
|
||||
e.asErrorDialogBuilder(activity).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ class GplayServiceUnavailableException(cause: Throwable) : Exception("Google Pla
|
||||
return LocalizedError(
|
||||
throwable = this,
|
||||
label = "Google Play Services Unavailable",
|
||||
description = context.getString(R.string.upgrades_iap_gplay_unavailable_error)
|
||||
description = context.getString(R.string.upgrades_gplay_unavailable_error)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -30,14 +29,10 @@ class BillingDataRepo @Inject constructor(
|
||||
|
||||
private val connectionProvider = billingClientConnectionProvider.connection
|
||||
.replayingShare(scope)
|
||||
private val purchaseData = connectionProvider.flatMapLatest { it.purchases }
|
||||
|
||||
val billingData: Flow<BillingData> = purchaseData
|
||||
.map {
|
||||
BillingData(
|
||||
purchases = it
|
||||
)
|
||||
}
|
||||
val billingData: Flow<BillingData> = connectionProvider
|
||||
.flatMapLatest { it.purchases }
|
||||
.map { BillingData(purchases = it) }
|
||||
.setupCommonEventHandlers(TAG) { "iapData" }
|
||||
.replayingShare(scope)
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="upgrades_iap_gplay_unavailable_error">Google Play services are unavailable.</string>
|
||||
<string name="upgrades_gplay_unavailable_error">Google Play services are unavailable.</string>
|
||||
<string name="upgrades_no_purchases_found_check_account">No purchases found. Are you using the right account?</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user