Skip to content

Commit

Permalink
#1274 feat: show dialog if an error is encountered while purchasing
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Nov 7, 2024
1 parent 48aac71 commit 5b232f2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ fun Error.getFullMessage(resourceProvider: ResourceProvider) = when (this) {
Error.CantDetectKeyEventsInPhoneCall -> resourceProvider.getString(R.string.trigger_error_cant_detect_in_phone_call_explanation)
Error.GestureStrokeCountTooHigh -> resourceProvider.getString(R.string.trigger_error_gesture_stroke_count_too_high)
Error.GestureDurationTooHigh -> resourceProvider.getString(R.string.trigger_error_gesture_duration_too_high)

Error.PurchasingError.Cancelled -> resourceProvider.getString(R.string.purchasing_error_cancelled)
Error.PurchasingError.NetworkError -> resourceProvider.getString(R.string.purchasing_error_network)
Error.PurchasingError.ProductNotFound -> resourceProvider.getString(R.string.purchasing_error_product_not_found)
Error.PurchasingError.StoreProblem -> resourceProvider.getString(R.string.purchasing_error_store_problem)
is Error.PurchasingError.Unexpected -> this.message
}

val Error.isFixable: Boolean
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/io/github/sds100/keymapper/util/Result.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ sealed class Error : Result<Nothing>() {

data object ShizukuNotStarted : Error()
data object CantDetectKeyEventsInPhoneCall : Error()

sealed class PurchasingError : Error() {
data object ProductNotFound : PurchasingError()
data object Cancelled : PurchasingError()
data object StoreProblem : PurchasingError()
data object NetworkError : PurchasingError()

/**
* This handles errors that haven't been
*/
data class Unexpected(val message: String) : PurchasingError()
}
}

inline fun <T> Result<T>.onSuccess(f: (T) -> Unit): Result<T> {
Expand Down Expand Up @@ -156,6 +168,15 @@ inline infix fun <T> Result<T>.otherwise(f: (error: Error) -> Result<T>) =
is Error -> f(this)
}

inline fun <T, U> Result<T>.resolve(
onSuccess: (value: T) -> U,
onFailure: (error: Error) -> U,
) =
when (this) {
is Success -> onSuccess(this.value)
is Error -> onFailure(this)
}

inline infix fun <T> Result<T>.valueIfFailure(f: (error: Error) -> T): T =
when (this) {
is Success -> this.value
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1382,5 +1382,16 @@
<string name="advanced_triggers_sheet_text">The developer doesn\'t believe ads are a sustainable or user-friendly form of monetization so these paid triggers help support development ❤️. You will be given priority support as well.</string>
<string name="assistant_trigger_product_title">Assistant trigger</string>
<string name="assistant_trigger_product_description">Did you know you can remap your device assistant? Instead of launching Google Assistant or Bixby, your device can perform an action of your choice. It works even when the screen is off!</string>

<!-- Purchasing -->
<string name="unlock_product_button">Unlock (%s)</string>
<string name="use_product_button">Use</string>
<string name="loading_product_button">Loading…</string>
<string name="retry_loading_price_button">Retry fetching price</string>
<string name="purchasing_error_cancelled">Purchase cancelled.</string>
<string name="purchasing_error_network">Network error encountered. Do you have an internet connection?</string>
<string name="purchasing_error_product_not_found">This product was not found.</string>
<string name="purchasing_error_store_problem">Google Play encountered an error.</string>
<string name="purchasing_error_dialog_title">Something went wrong 😕</string>
<string name="purchasing_error_dialog_button_retry">Retry</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.mockito.kotlin.whenever

@ExperimentalCoroutinesApi
@RunWith(MockitoJUnitRunner::class)
class GetActionErrorUseCaseTest {
class GetActionFailedUseCaseTest {

private val testDispatcher = StandardTestDispatcher()
private val testScope = TestScope(testDispatcher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ConfigTriggerViewModelTest {
onBlocking { getTriggerErrors(any()) }.thenReturn(emptyList())
},
fakeResourceProvider,
purchasingManager = mock(),
)
}

Expand Down

0 comments on commit 5b232f2

Please sign in to comment.