From 74ab377fdb14b09929d218836186507b60e0b306 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 3 Jul 2017 22:06:42 -0700 Subject: Finalize iab --- app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils') 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 a15d0520..da735430 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 @@ -20,6 +20,9 @@ import com.pitchedapps.frost.utils.* * Make sure you call [IAB.dispose] once an operation is done to release the resources * Also make sure that it is called on the very LAST operation if there are a list of async calls. * Otherwise the helper will be prematurely disposed + * + * For the most part, billing is handled in the [SettingsActivity] and will be disposed when it is destroyed + * It may also be handled elsewhere when validating purchases, so those calls should dispose themselves */ object IAB { @@ -30,16 +33,14 @@ object IAB { * * [mustHavePlayStore] decides if dialogs should be shown if play store errors occur * - * */ operator fun invoke(activity: Activity, mustHavePlayStore: Boolean = true, onFailed: () -> Unit = {}, onStart: (helper: IabHelper) -> Unit) { with(activity) { - if (helper?.mDisposed ?: true) { + if (helper?.mDisposed ?: helper?.mDisposeAfterAsync ?: true) { helper = null L.d("IAB setup async") if (!isFrostPlay) { if (mustHavePlayStore) playStoreNotFound() - IAB.dispose() onFailed() return } @@ -183,6 +184,7 @@ fun Activity.openPlayPurchase(key: String, code: Int, onSuccess: (key: String) - if (result.isSuccess) { onSuccess(key) playStorePurchasedSuccessfully(key) + IAB.dispose() } frostAnswers { logPurchase(PurchaseEvent() @@ -190,7 +192,6 @@ fun Activity.openPlayPurchase(key: String, code: Int, onSuccess: (key: String) - .putCustomAttribute("result", result.message) .putSuccess(result.isSuccess)) } - IAB.dispose() } } } \ No newline at end of file -- cgit v1.2.3