File tree Expand file tree Collapse file tree
app/src/main/java/com/simplecityapps/shuttle/ui/screens/trial
trial/src/main/java/com/simplecityapps/trial Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package com.simplecityapps.shuttle.ui.screens.trial
22
33import android.app.Dialog
44import android.os.Bundle
5+ import android.widget.Toast
56import androidx.core.content.res.ResourcesCompat
67import androidx.fragment.app.DialogFragment
78import 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 )
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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 () {
You can’t perform that action at this time.
0 commit comments