Skip to content

Commit

Permalink
Show dialog messages when restoring (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro authored Sep 13, 2023
1 parent 6f3d8ae commit d164409
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ fun PaywallScreen(
.setListener(viewModel)
.build(),
)
if (state.displayCompletedPurchaseMessage) {
PurchaseAlertDialog(viewModel, "Purchase was successful")
} else if (state.displayErrorPurchasingMessage) {
PurchaseAlertDialog(viewModel, "There was a purchasing error")
state?.dialogText?.let {
PurchaseAlertDialog(viewModel, it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ sealed class PaywallScreenState {
data class Error(val errorMessage: String) : PaywallScreenState()
data class Loaded(
val offering: Offering,
val displayCompletedPurchaseMessage: Boolean = false,
val displayErrorPurchasingMessage: Boolean = false,
val dialogText: String? = null,
) : PaywallScreenState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,45 @@ class PaywallScreenViewModelImpl(
updateOffering()
}

override fun onRestoreStarted() {
val value = _state.value
if (value is PaywallScreenState.Loaded) {
_state.update {
value.copy(
dialogText = "Restoring purchases...",
)
}
}
}

override fun onRestoreCompleted(customerInfo: CustomerInfo) {
val value = _state.value
if (value is PaywallScreenState.Loaded) {
_state.update {
value.copy(
dialogText = "Restore completed",
)
}
}
}

override fun onRestoreError(error: PurchasesError) {
val value = _state.value
if (value is PaywallScreenState.Loaded) {
_state.update {
value.copy(
dialogText = "There was an error restoring purchases",
)
}
}
}

override fun onPurchaseCompleted(customerInfo: CustomerInfo, storeTransaction: StoreTransaction) {
val value = _state.value
if (value is PaywallScreenState.Loaded) {
_state.update {
value.copy(
displayCompletedPurchaseMessage = true,
displayErrorPurchasingMessage = false,
dialogText = "Purchase was successful",
)
}
}
Expand All @@ -56,8 +88,7 @@ class PaywallScreenViewModelImpl(
if (value is PaywallScreenState.Loaded) {
_state.update {
value.copy(
displayCompletedPurchaseMessage = false,
displayErrorPurchasingMessage = true,
dialogText = "There was an error purchasing",
)
}
}
Expand All @@ -68,8 +99,7 @@ class PaywallScreenViewModelImpl(
if (value is PaywallScreenState.Loaded) {
_state.update {
value.copy(
displayCompletedPurchaseMessage = false,
displayErrorPurchasingMessage = false,
dialogText = null,
)
}
}
Expand Down

0 comments on commit d164409

Please sign in to comment.