From 8a9ecfcbf40f0d1fd8a347a66b08a262b1d7a82c Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 3 Jul 2017 22:33:19 -0400 Subject: Dev (#15) * Allow file access * Log all to phone * Rework billing logic * Simplify travis process * More logging * Fix purchasing --- app/build.gradle | 1 + .../kotlin/com/pitchedapps/frost/AboutActivity.kt | 1 + .../kotlin/com/pitchedapps/frost/utils/iab/IAB.kt | 20 +++++++++++++------- .../com/pitchedapps/frost/utils/iab/IABDialogs.kt | 3 +++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 13060352..169c0a77 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,6 +4,7 @@ plugins { apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: 'io.fabric' apply plugin: 'com.github.triplet.play' diff --git a/app/src/main/kotlin/com/pitchedapps/frost/AboutActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/AboutActivity.kt index 2875edcb..7aa4eac3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/AboutActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/AboutActivity.kt @@ -42,6 +42,7 @@ class AboutActivity : AboutActivityBase(R.string::class.java, configBuilder = { "glide", "jsoup" ) + /* * These are great libraries, but either aren't used directly or are too common to be listed * Give more emphasis on the unique libs! 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, _ -> diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt index 58c21be4..1d5abdd6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt @@ -87,6 +87,7 @@ fun Activity.playStoreGenericError(text: String? = "Store generic error") { } fun Activity.playStoreAlreadyPurchased(key: String) { + L.d("Play store already purchased $key") materialDialogThemed { title(R.string.play_already_purchased) content(String.format(string(R.string.play_already_purchased_content), key)) @@ -98,6 +99,7 @@ fun Activity.playStoreAlreadyPurchased(key: String) { } fun Activity.playStorePurchasedSuccessfully(key: String) { + L.d("Play store purchased $key successfully") materialDialogThemed { title(R.string.play_thank_you) content(R.string.play_purchased_pro) @@ -106,6 +108,7 @@ fun Activity.playStorePurchasedSuccessfully(key: String) { } fun SettingsActivity.purchaseRestored() { + L.d("Purchase restored") materialDialogThemed { title(R.string.play_thank_you) content(R.string.play_purchased_pro) -- cgit v1.2.3