Skip to content

Commit 5f7be92

Browse files
authored
Merge pull request #213 from timusus/rejection-fix
Potential fix for google update rejection shenanigans
2 parents 01eeb38 + 20932f6 commit 5f7be92

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

android/app/src/main/java/com/simplecityapps/shuttle/ui/screens/trial/PurchaseDialogFragment.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.simplecityapps.shuttle.ui.screens.trial
22

33
import android.app.Dialog
44
import android.os.Bundle
5+
import android.widget.Toast
56
import androidx.core.content.res.ResourcesCompat
67
import androidx.fragment.app.DialogFragment
78
import androidx.fragment.app.FragmentManager
@@ -58,8 +59,16 @@ class PurchaseDialogFragment : DialogFragment() {
5859
productDetails,
5960
object : SkuBinder.Listener {
6061
override fun onClick(productDetails: ProductDetails) {
61-
billingManager.launchPurchaseFlow(requireActivity(), productDetails)
62-
dismiss()
62+
val launched = billingManager.launchPurchaseFlow(requireActivity(), productDetails)
63+
if (launched) {
64+
dismiss()
65+
} else {
66+
Toast.makeText(
67+
requireContext(),
68+
"Unable to connect to Google Play. Please try again.",
69+
Toast.LENGTH_SHORT
70+
).show()
71+
}
6372
}
6473
}
6574
)

android/app/src/main/java/com/simplecityapps/shuttle/ui/screens/trial/TrialDialogFragment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ class TrialDialogFragment : DialogFragment() {
4545
var touchTime = 0L
4646
icon.setOnTouchListener { v, event ->
4747
if (event.action == MotionEvent.ACTION_UP) {
48-
if (touchTime == 0L || System.currentTimeMillis() - touchTime > 2000) {
49-
touchTime = System.currentTimeMillis()
48+
val now = System.currentTimeMillis()
49+
if (touchTime == 0L || now - touchTime > 2000) {
50+
touchTime = now
5051
touchCount = 1
5152
} else {
5253
touchCount++
@@ -60,7 +61,8 @@ class TrialDialogFragment : DialogFragment() {
6061
dismiss()
6162
}
6263
}
63-
true
64+
// Only consume if we're in an active tap sequence
65+
touchCount > 0 && System.currentTimeMillis() - touchTime <= 2000
6466
}
6567

6668
val upgradeButton: Button = view.findViewById(R.id.upgradeButton)

android/trial/src/main/java/com/simplecityapps/trial/BillingManager.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ class BillingManager(
119119
fun launchPurchaseFlow(
120120
activity: FragmentActivity,
121121
productDetails: ProductDetails
122-
) {
122+
): Boolean {
123123
if (!billingClient.isReady) {
124124
Timber.e("Failed to launch purchase flow: BillingClient not ready")
125-
return
125+
return false
126126
}
127127

128128
val productDetailsParamsList = listOf(
@@ -137,6 +137,7 @@ class BillingManager(
137137
.setProductDetailsParamsList(productDetailsParamsList)
138138
.build()
139139
)
140+
return true
140141
}
141142

142143
suspend fun queryProductDetails() {

0 commit comments

Comments
 (0)