diff --git a/app/src/main/java/io/timelimit/android/ui/payment/PurchaseFragment.kt b/app/src/main/java/io/timelimit/android/ui/payment/PurchaseFragment.kt index 15c0981..fc65771 100644 --- a/app/src/main/java/io/timelimit/android/ui/payment/PurchaseFragment.kt +++ b/app/src/main/java/io/timelimit/android/ui/payment/PurchaseFragment.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2021 Jonas Lochmann + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,13 +22,14 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import io.timelimit.android.R import io.timelimit.android.databinding.FragmentPurchaseBinding import io.timelimit.android.livedata.liveDataFromNullableValue import io.timelimit.android.livedata.mergeLiveData import io.timelimit.android.ui.MainActivity +import io.timelimit.android.ui.diagnose.DiagnoseExceptionDialogFragment import io.timelimit.android.ui.main.FragmentWithCustomTitle +import java.lang.RuntimeException class PurchaseFragment : Fragment(), FragmentWithCustomTitle { private val activityModel: ActivityPurchaseModel by lazy { (activity as MainActivity).purchaseModel } @@ -87,7 +88,7 @@ class PurchaseFragment : Fragment(), FragmentWithCustomTitle { binding.errorReason = when (fragmentStatus) { PurchaseFragmentErrorBillingNotSupportedByDevice -> getString(R.string.purchase_error_not_supported_by_device) PurchaseFragmentErrorBillingNotSupportedByAppVariant -> getString(R.string.purchase_error_not_supported_by_app_variant) - PurchaseFragmentNetworkError -> getString(R.string.error_network) + is PurchaseFragmentNetworkError -> getString(R.string.error_network) PurchaseFragmentExistingPaymentError -> getString(R.string.purchase_error_existing_payment) PurchaseFragmentServerRejectedError -> getString(R.string.purchase_error_server_rejected) PurchaseFragmentServerHasDifferentPublicKey -> getString(R.string.purchase_error_server_different_key) @@ -97,6 +98,12 @@ class PurchaseFragment : Fragment(), FragmentWithCustomTitle { is PurchaseFragmentRecoverableError -> true is PurchaseFragmentUnrecoverableError -> false } + + binding.showErrorDetailsButton = when (fragmentStatus) { + is PurchaseFragmentNetworkError -> true + else -> false + } + processingPurchaseError = false } }.let { } @@ -114,6 +121,17 @@ class PurchaseFragment : Fragment(), FragmentWithCustomTitle { } } + override fun showErrorDetails() { + val status = model.status.value + + val exception = when (status) { + is PurchaseFragmentNetworkError -> status.exception + else -> RuntimeException("other error") + } + + DiagnoseExceptionDialogFragment.newInstance(exception).show(parentFragmentManager) + } + override fun buyForOneMonth() { activityModel.startPurchase(PurchaseIds.SKU_MONTH, checkAtBackend = true, activity = requireActivity()) } @@ -131,6 +149,7 @@ class PurchaseFragment : Fragment(), FragmentWithCustomTitle { interface PurchaseFragmentHandlers { fun retryAtErrorScreenClicked() + fun showErrorDetails() fun buyForOneMonth() fun buyForOneYear() } diff --git a/app/src/main/java/io/timelimit/android/ui/payment/PurchaseModel.kt b/app/src/main/java/io/timelimit/android/ui/payment/PurchaseModel.kt index a296980..a42739e 100644 --- a/app/src/main/java/io/timelimit/android/ui/payment/PurchaseModel.kt +++ b/app/src/main/java/io/timelimit/android/ui/payment/PurchaseModel.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2021 Jonas Lochmann + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -78,7 +78,7 @@ class PurchaseModel(application: Application): AndroidViewModel(application) { } catch (ex: BillingNotSupportedException) { statusInternal.value = PurchaseFragmentErrorBillingNotSupportedByDevice } catch (ex: Exception) { - statusInternal.value = PurchaseFragmentNetworkError + statusInternal.value = PurchaseFragmentNetworkError(ex) } } } @@ -95,7 +95,7 @@ sealed class PurchaseFragmentRecoverableError: PurchaseFragmentError() object PurchaseFragmentErrorBillingNotSupportedByDevice: PurchaseFragmentUnrecoverableError() object PurchaseFragmentErrorBillingNotSupportedByAppVariant: PurchaseFragmentUnrecoverableError() -object PurchaseFragmentNetworkError: PurchaseFragmentRecoverableError() +data class PurchaseFragmentNetworkError(val exception: Exception): PurchaseFragmentRecoverableError() object PurchaseFragmentExistingPaymentError: PurchaseFragmentUnrecoverableError() object PurchaseFragmentServerRejectedError: PurchaseFragmentUnrecoverableError() object PurchaseFragmentServerHasDifferentPublicKey: PurchaseFragmentUnrecoverableError() \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_purchase.xml b/app/src/main/res/layout/fragment_purchase.xml index d149c34..540f47a 100644 --- a/app/src/main/res/layout/fragment_purchase.xml +++ b/app/src/main/res/layout/fragment_purchase.xml @@ -1,5 +1,5 @@