From 3ebe6d37c8e647b17c31a1cd0b3a1675e183a9cd Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Tue, 1 Mar 2022 10:26:45 +0100 Subject: [PATCH] 3.5.1.2 --- Habitica/build.gradle | 4 ++-- .../habitica/helpers/PurchaseHandler.kt | 11 ++++++++++ .../purchases/SubscriptionFragment.kt | 22 ++++++++++--------- habitica.properties.travis | 5 ----- 4 files changed, 25 insertions(+), 17 deletions(-) delete mode 100644 habitica.properties.travis diff --git a/Habitica/build.gradle b/Habitica/build.gradle index 9dc344c90..32b957395 100644 --- a/Habitica/build.gradle +++ b/Habitica/build.gradle @@ -159,8 +159,8 @@ android { buildConfigField "String", "TESTING_LEVEL", "\"production\"" resConfigs 'en', 'bg', 'de', 'en-rGB', 'es', 'fr', 'hr-rHR', 'in', 'it', 'iw', 'ja', 'ko', 'lt', 'nl', 'pl', 'pt-rBR', 'pt-rPT', 'ru', 'tr', 'zh', 'zh-rTW' - versionCode 3253 - versionName "3.5.1" + versionCode 3262 + versionName "3.5.1.2" targetSdkVersion 32 diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/PurchaseHandler.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/PurchaseHandler.kt index 3ee39e898..4ef73ed8f 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/PurchaseHandler.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/PurchaseHandler.kt @@ -9,6 +9,7 @@ import androidx.core.content.edit import androidx.core.os.bundleOf import com.android.billingclient.api.* import com.android.billingclient.api.BillingClient.ConnectionState.DISCONNECTED +import com.google.api.Billing import com.google.firebase.analytics.FirebaseAnalytics import com.google.firebase.crashlytics.FirebaseCrashlytics import com.habitrpg.android.habitica.HabiticaBaseApplication @@ -271,6 +272,16 @@ open class PurchaseHandler( FirebaseCrashlytics.getInstance().recordException(throwable) } + suspend fun checkForSubscription(): Purchase? { + val result = withContext(Dispatchers.IO) { + billingClient.queryPurchasesAsync(BillingClient.SkuType.SUBS) + } + if (result.billingResult.responseCode == BillingClient.BillingResponseCode.OK) { + return result.purchasesList.sortedByDescending { it.purchaseTime }.firstOrNull { it.isAcknowledged } + } + return null + } + fun cancelSubscription(): Flowable { return apiClient.cancelSubscription() .flatMap { userViewModel.userRepository.retrieveUser(false, true) } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/purchases/SubscriptionFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/purchases/SubscriptionFragment.kt index 420ca00c9..795bb089a 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/purchases/SubscriptionFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/purchases/SubscriptionFragment.kt @@ -59,7 +59,6 @@ class SubscriptionFragment : BaseFragment() { private var user: User? = null private var hasLoadedSubscriptionOptions: Boolean = false - private var purchasedSubscription: Purchase? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -229,15 +228,18 @@ class SubscriptionFragment : BaseFragment() { } private fun checkIfNeedsCancellation() { - if (user?.purchased?.plan?.paymentMethod == "Google" && - user?.purchased?.plan?.isActive == true && - user?.purchased?.plan?.dateTerminated == null && - (purchasedSubscription?.isAutoRenewing == false || purchasedSubscription == null) - ) { - compositeSubscription.add( - purchaseHandler.cancelSubscription() - .subscribe({ }, RxErrorHandler.handleEmptyError()) - ) + CoroutineScope(Dispatchers.IO).launch { + val newestSubscription = purchaseHandler.checkForSubscription() + if (user?.purchased?.plan?.paymentMethod == "Google" && + user?.purchased?.plan?.isActive == true && + user?.purchased?.plan?.dateTerminated == null && + (newestSubscription?.isAutoRenewing == false) + ) { + compositeSubscription.add( + purchaseHandler.cancelSubscription() + .subscribe({ }, RxErrorHandler.handleEmptyError()) + ) + } } } diff --git a/habitica.properties.travis b/habitica.properties.travis deleted file mode 100644 index cac583d71..000000000 --- a/habitica.properties.travis +++ /dev/null @@ -1,5 +0,0 @@ -PORT=3000 -BASE_URL=http://localhost:3000 -STAGING_KEY= -ANDROID_TESTING_UUID= -APPLE_AUTH_CLIENT_ID=