Fix checkout flow activity close on error.

This commit is contained in:
Alex Hart
2024-08-08 15:21:02 -03:00
committed by mtang-signal
parent 385ba3590c
commit c880db0f4a
6 changed files with 26 additions and 3 deletions

View File

@@ -273,4 +273,8 @@ class MessageBackupsFlowFragment : ComposeFragment(), InAppPaymentCheckoutDelega
override fun navigateToDonationPending(inAppPayment: InAppPaymentTable.InAppPayment) {
// TODO [message-backups] What do? Are we even supporting bank transfers?
}
override fun exitCheckoutFlow() {
requireActivity().finishAfterTransition()
}
}

View File

@@ -313,4 +313,8 @@ class GiftFlowConfirmationFragment :
override fun onUserLaunchedAnExternalApplication() = error("Not supported for gifts.")
override fun navigateToDonationPending(inAppPayment: InAppPaymentTable.InAppPayment) = error("Not supported for gifts")
override fun exitCheckoutFlow() {
requireActivity().finishAfterTransition()
}
}

View File

@@ -528,4 +528,8 @@ class DonateToSignalFragment :
override fun navigateToDonationPending(inAppPayment: InAppPaymentTable.InAppPayment) {
findNavController().safeNavigate(DonateToSignalFragmentDirections.actionDonateToSignalFragmentToDonationPendingBottomSheet(inAppPayment))
}
override fun exitCheckoutFlow() {
requireActivity().finishAffinity()
}
}

View File

@@ -8,7 +8,6 @@ import androidx.fragment.app.setFragmentResultListener
import androidx.fragment.app.viewModels
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.fragment.findNavController
import androidx.navigation.navGraphViewModels
import com.google.android.gms.wallet.PaymentData
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@@ -139,7 +138,7 @@ class InAppPaymentCheckoutDelegate(
.setTitle(R.string.DonationsErrors__failed_to_cancel_subscription)
.setMessage(R.string.DonationsErrors__subscription_cancellation_requires_an_internet_connection)
.setPositiveButton(android.R.string.ok) { _, _ ->
fragment.findNavController().popBackStack(R.id.checkout_flow, true)
callback.exitCheckoutFlow()
}
.show()
} else {
@@ -285,14 +284,17 @@ class InAppPaymentCheckoutDelegate(
is DonationError.UserCancelledPaymentError -> {
Log.d(TAG, "User cancelled out of payment flow.", true)
}
is DonationError.BadgeRedemptionError.DonationPending -> {
Log.d(TAG, "User launched an external application.", true)
errorHandlerCallback?.onUserLaunchedAnExternalApplication()
}
is DonationError.UserLaunchedExternalApplication -> {
Log.d(TAG, "Long-running donation is still pending.", true)
errorHandlerCallback?.navigateToDonationPending(inAppPayment)
}
else -> {
Log.d(TAG, "Displaying donation error dialog.", true)
errorDialog = DonationErrorDialogs.show(
@@ -353,7 +355,7 @@ class InAppPaymentCheckoutDelegate(
errorDialog = null
if (!tryAgain) {
tryAgain = false
fragment?.findNavController()?.popBackStack(R.id.checkout_flow, true)
errorHandlerCallback?.exitCheckoutFlow()
}
}
}
@@ -362,6 +364,7 @@ class InAppPaymentCheckoutDelegate(
interface ErrorHandlerCallback {
fun onUserLaunchedAnExternalApplication()
fun navigateToDonationPending(inAppPayment: InAppPaymentTable.InAppPayment)
fun exitCheckoutFlow()
}
interface Callback : ErrorHandlerCallback {

View File

@@ -163,6 +163,10 @@ class BankTransferDetailsFragment : ComposeFragment(), InAppPaymentCheckoutDeleg
}
})
}
override fun exitCheckoutFlow() {
requireActivity().finishAfterTransition()
}
}
@Preview

View File

@@ -194,6 +194,10 @@ class IdealTransferDetailsFragment : ComposeFragment(), InAppPaymentCheckoutDele
}
})
}
override fun exitCheckoutFlow() {
requireActivity().finishAfterTransition()
}
}
@Preview