Skip to content

Commit 9657a55

Browse files
committed
fix: do not crash when cancelling purchase
1 parent 1f65e9a commit 9657a55

File tree

1 file changed

+35
-0
lines changed
  • base/src/main/java/io/github/sds100/keymapper/base/utils

1 file changed

+35
-0
lines changed

base/src/main/java/io/github/sds100/keymapper/base/utils/ErrorUtils.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package io.github.sds100.keymapper.base.utils
22

33
import android.content.pm.PackageManager
44
import io.github.sds100.keymapper.base.R
5+
import io.github.sds100.keymapper.base.purchasing.ProductId
6+
import io.github.sds100.keymapper.base.purchasing.PurchasingError
57
import io.github.sds100.keymapper.base.utils.ui.ResourceProvider
68
import io.github.sds100.keymapper.common.utils.BuildUtils
79
import io.github.sds100.keymapper.common.utils.KMError
@@ -173,6 +175,39 @@ fun KMError.getFullMessage(resourceProvider: ResourceProvider): String {
173175
KMError.InvalidBackup -> resourceProvider.getString(R.string.error_invalid_backup)
174176
KMError.MalformedUrl -> resourceProvider.getString(R.string.error_malformed_url)
175177
KMError.UiElementNotFound -> resourceProvider.getString(R.string.error_ui_element_not_found)
178+
179+
PurchasingError.PurchasingProcessError.Cancelled -> resourceProvider.getString(
180+
R.string.purchasing_error_cancelled,
181+
)
182+
183+
PurchasingError.PurchasingProcessError.NetworkError -> resourceProvider.getString(
184+
R.string.purchasing_error_network,
185+
)
186+
187+
PurchasingError.PurchasingProcessError.ProductNotFound -> resourceProvider.getString(
188+
R.string.purchasing_error_product_not_found,
189+
)
190+
191+
PurchasingError.PurchasingProcessError.StoreProblem -> resourceProvider.getString(
192+
R.string.purchasing_error_store_problem,
193+
)
194+
195+
PurchasingError.PurchasingProcessError.PaymentPending -> resourceProvider.getString(
196+
R.string.purchasing_error_payment_pending,
197+
)
198+
199+
PurchasingError.PurchasingProcessError.PurchaseInvalid -> resourceProvider.getString(
200+
R.string.purchasing_error_purchase_invalid,
201+
)
202+
203+
is PurchasingError.PurchasingProcessError.Unexpected -> message
204+
205+
is PurchasingError.ProductNotPurchased -> when (product) {
206+
ProductId.ASSISTANT_TRIGGER -> resourceProvider.getString(R.string.purchasing_error_assistant_not_purchased_home_screen)
207+
ProductId.FLOATING_BUTTONS -> resourceProvider.getString(R.string.purchasing_error_floating_buttons_not_purchased_home_screen)
208+
}
209+
210+
PurchasingError.PurchasingNotImplemented -> resourceProvider.getString(R.string.purchasing_error_not_implemented)
176211
else -> throw IllegalArgumentException("Unknown error $this")
177212
}
178213
}

0 commit comments

Comments
 (0)