diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-02 10:36:38 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-07-02 10:36:38 -0700 |
commit | b148feff51d7f2805b1af378ad07740bfbeb53a8 (patch) | |
tree | 044106601debe01402b3572807ecc1d3f08cf0ba /app/src/main/kotlin/com/pitchedapps/frost/utils | |
parent | 0018677886197db4f72d2b49e3d0266526b95435 (diff) | |
download | frost-b148feff51d7f2805b1af378ad07740bfbeb53a8.tar.gz frost-b148feff51d7f2805b1af378ad07740bfbeb53a8.tar.bz2 frost-b148feff51d7f2805b1af378ad07740bfbeb53a8.zip |
Test tagsv1.0.2
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt | 36 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABDialogs.kt | 15 |
2 files changed, 32 insertions, 19 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 ec63cce3..e047e2ff 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 @@ -3,11 +3,13 @@ package com.pitchedapps.frost.utils.iab import android.app.Activity import android.content.Context import ca.allanwang.kau.utils.isFromGooglePlay -import ca.allanwang.kau.utils.startPlayStoreLink import com.crashlytics.android.answers.PurchaseEvent import com.pitchedapps.frost.BuildConfig -import com.pitchedapps.frost.R -import com.pitchedapps.frost.utils.* +import com.pitchedapps.frost.SettingsActivity +import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.frostAnswers +import com.pitchedapps.frost.utils.frostAnswersCustom /** * Created by Allan Wang on 2017-06-23. @@ -48,23 +50,20 @@ private const val FROST_PRO = "frost_pro" val IS_FROST_PRO: Boolean get() = (BuildConfig.DEBUG && Prefs.debugPro) || Prefs.previouslyPro -private fun Context.checkFromPlay(): Boolean { - val isPlay = isFromGooglePlay || BuildConfig.DEBUG - if (!isPlay) materialDialogThemed { - title(R.string.uh_oh) - content(R.string.play_store_not_found) - positiveText(R.string.kau_ok) - neutralText(R.string.kau_play_store) - onNeutral { _, _ -> startPlayStoreLink(R.string.play_store_package_id) } - } - return isPlay +private val Context.isFrostPlay: Boolean + get() = isFromGooglePlay || BuildConfig.DEBUG + +fun SettingsActivity.restorePurchases() { + } -fun Activity.openPlayProPurchase(code: Int) = openPlayPurchase(FROST_PRO, code) +fun Activity.openPlayProPurchase(code: Int) = openPlayPurchase(FROST_PRO, code) { + Prefs.previouslyPro = true +} -fun Activity.openPlayPurchase(key: String, code: Int) { +fun Activity.openPlayPurchase(key: String, code: Int, onSuccess: (key: String) -> Unit) { L.d("Open play purchase $key $code") - if (!checkFromPlay()) return + if (!isFrostPlay) return playStoreNotFound() frostAnswersCustom("PLAY_PURCHASE") { putCustomAttribute("Key", key) } @@ -79,7 +78,10 @@ fun Activity.openPlayPurchase(key: String, code: Int) { L.d("IAB: inventory ${inv.allOwnedSkus}") IAB.helper!!.launchPurchaseFlow(this@openPlayPurchase, key, code) { result, _ -> - if (result.isSuccess) playStorePurchasedSuccessfully(key) + if (result.isSuccess) { + onSuccess(key) + playStorePurchasedSuccessfully(key) + } frostAnswers { logPurchase(PurchaseEvent() .putItemId(key) 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 f0a544f7..08958480 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 @@ -40,8 +40,19 @@ fun Activity.playStoreNoLongerPro() { } } -fun Activity.playStoreNotAvailable() { - playStoreLog("Store not available") +fun Activity.playStoreNotFound() { + L.d("Play store not found") + materialDialogThemed { + title(R.string.uh_oh) + content(R.string.play_store_not_found) + positiveText(R.string.kau_ok) + neutralText(R.string.kau_play_store) + onNeutral { _, _ -> startPlayStoreLink(R.string.play_store_package_id) } + } +} + +fun Activity.playStoreProNotAvailable() { + playStoreLog("Pro found; store not available") materialDialogThemed { title(R.string.uh_oh) content(R.string.play_store_not_found) |