diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-03 22:33:19 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-03 22:33:19 -0400 |
commit | 8a9ecfcbf40f0d1fd8a347a66b08a262b1d7a82c (patch) | |
tree | a41468ba861b4e9207b22bd26ca2fb3c9e59d896 /app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt | |
parent | bde1c74e57b34b3395fe4741d8188fe2704662ce (diff) | |
download | frost-8a9ecfcbf40f0d1fd8a347a66b08a262b1d7a82c.tar.gz frost-8a9ecfcbf40f0d1fd8a347a66b08a262b1d7a82c.tar.bz2 frost-8a9ecfcbf40f0d1fd8a347a66b08a262b1d7a82c.zip |
Dev (#15)
* Allow file access
* Log all to phone
* Rework billing logic
* Simplify travis process
* More logging
* Fix purchasing
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt index 645a6218..3b6eb53b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt @@ -40,14 +40,16 @@ object IAB { } try { helper = IabHelper(applicationContext, PUBLIC_BILLING_KEY) - helper!!.enableDebugLogging(BuildConfig.DEBUG, "Frost:") + helper!!.enableDebugLogging(BuildConfig.DEBUG || Prefs.verboseLogging, "Frost:") helper!!.startSetup { result -> L.d("IAB setup finished; ${result.isSuccess}") if (result.isSuccess) { + L.d("IAB setup success") if (onStart(helper!!)) helper!!.disposeWhenFinished() } else { + L.d("IAB setup fail") if (mustHavePlayStore) activity.playStoreGenericError("Setup error: ${result.response} ${result.message}") onFailed() @@ -103,8 +105,8 @@ fun SettingsActivity.restorePurchases() { } getInventory(false, true, reset) { inv, _ -> - val proSku = inv.getSkuDetails(FROST_PRO) - Prefs.pro = proSku != null + val proSku = inv.hasPurchase(FROST_PRO) + Prefs.pro = proSku L.d("Restore found: ${Prefs.pro}") finishRestore(restore, Prefs.pro) } @@ -128,9 +130,9 @@ fun Activity.validatePro() { L.d("Validate pro") getInventory(Prefs.pro, true, { if (Prefs.pro) playStoreNoLongerPro() }) { inv, _ -> - val proSku = inv.getSkuDetails(FROST_PRO) - if (proSku == null && Prefs.pro) playStoreNoLongerPro() - else if (proSku != null && !Prefs.pro) playStoreFoundPro() + val proSku = inv.hasPurchase(FROST_PRO) + if (!proSku && Prefs.pro) playStoreNoLongerPro() + else if (proSku && !Prefs.pro) playStoreFoundPro() } } @@ -163,7 +165,11 @@ fun Activity.openPlayPurchase(key: String, code: Int, onSuccess: (key: String) - L.d("Open play purchase $key $code") getInventory(true, false, { playStoreGenericError("Query res error") }) { inv, helper -> - if (inv.getSkuDetails(key) != null) return@getInventory playStoreAlreadyPurchased(key) + if (inv.hasPurchase(key)) { + playStoreAlreadyPurchased(key) + onSuccess(key) + return@getInventory + } L.d("IAB: inventory ${inv.allOwnedSkus}") helper.launchPurchaseFlow(this@openPlayPurchase, key, code) { result, _ -> |