Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.simplecityapps.shuttle.ui.screens.trial

import android.app.Dialog
import android.os.Bundle
import android.widget.Toast
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
Expand Down Expand Up @@ -58,8 +59,16 @@ class PurchaseDialogFragment : DialogFragment() {
productDetails,
object : SkuBinder.Listener {
override fun onClick(productDetails: ProductDetails) {
billingManager.launchPurchaseFlow(requireActivity(), productDetails)
dismiss()
val launched = billingManager.launchPurchaseFlow(requireActivity(), productDetails)
if (launched) {
dismiss()
} else {
Toast.makeText(
requireContext(),
"Unable to connect to Google Play. Please try again.",
Toast.LENGTH_SHORT
).show()
}
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class TrialDialogFragment : DialogFragment() {
var touchTime = 0L
icon.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_UP) {
if (touchTime == 0L || System.currentTimeMillis() - touchTime > 2000) {
touchTime = System.currentTimeMillis()
val now = System.currentTimeMillis()
if (touchTime == 0L || now - touchTime > 2000) {
touchTime = now
touchCount = 1
} else {
touchCount++
Expand All @@ -60,7 +61,8 @@ class TrialDialogFragment : DialogFragment() {
dismiss()
}
}
true
// Only consume if we're in an active tap sequence
touchCount > 0 && System.currentTimeMillis() - touchTime <= 2000
}

val upgradeButton: Button = view.findViewById(R.id.upgradeButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ class BillingManager(
fun launchPurchaseFlow(
activity: FragmentActivity,
productDetails: ProductDetails
) {
): Boolean {
if (!billingClient.isReady) {
Timber.e("Failed to launch purchase flow: BillingClient not ready")
return
return false
}

val productDetailsParamsList = listOf(
Expand All @@ -137,6 +137,7 @@ class BillingManager(
.setProductDetailsParamsList(productDetailsParamsList)
.build()
)
return true
}

suspend fun queryProductDetails() {
Expand Down