aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-07-03 22:06:42 -0700
committerAllan Wang <me@allanwang.ca>2017-07-04 01:17:26 -0400
commit74ab377fdb14b09929d218836186507b60e0b306 (patch)
tree98f8dbf22a47b11ae6127afa093145fb0fad461c
parentfe6162c7d1e60d473735d0a0f5e74084d300c06f (diff)
downloadfrost-74ab377fdb14b09929d218836186507b60e0b306.tar.gz
frost-74ab377fdb14b09929d218836186507b60e0b306.tar.bz2
frost-74ab377fdb14b09929d218836186507b60e0b306.zip
Finalize iab
-rw-r--r--.idea/misc.xml2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt9
3 files changed, 8 insertions, 11 deletions
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 085136f8..7319f021 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -53,7 +53,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
index e67fc949..66c541ed 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
@@ -2,7 +2,6 @@ package com.pitchedapps.frost
import android.content.Intent
import android.os.Bundle
-import android.support.design.widget.Snackbar
import android.view.Menu
import android.view.MenuItem
import ca.allanwang.kau.changelog.showChangelog
@@ -129,10 +128,7 @@ class SettingsActivity : KPrefActivity(), IabBroadcastReceiver.IabBroadcastListe
R.id.action_email -> materialDialogThemed {
title(R.string.subject)
items(Support.values().map { string(it.title) })
- itemsCallback {
- _, _, which, _ ->
- Support.values()[which].sendEmail(this@SettingsActivity)
- }
+ itemsCallback { _, _, which, _ -> Support.values()[which].sendEmail(this@SettingsActivity) }
}
R.id.action_changelog -> showChangelog(R.xml.changelog, Prefs.textColor) { theme() }
else -> return super.onOptionsItemSelected(item)
@@ -141,7 +137,7 @@ class SettingsActivity : KPrefActivity(), IabBroadcastReceiver.IabBroadcastListe
}
override fun onDestroy() {
- if (!IAB.isInProgress) IAB.dispose()
+ IAB.dispose()
super.onDestroy()
}
} \ No newline at end of file
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