From 2586e947f769740dd8cb8bf8b1dd0473b51e50e4 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 6 Jul 2017 17:13:04 -0400 Subject: Dev 1.1.4 - fixes for donations (#31) * Remove cookie from error log * Remove null check on login as it isn't possible * Add exception to profile loading * Remap billing logic * Display snackbar only for user prompts * Private disposed caller --- .travis.yml | 3 +- .../kotlin/com/pitchedapps/frost/LoginActivity.kt | 14 ++++---- .../kotlin/com/pitchedapps/frost/utils/iab/IAB.kt | 40 +++++++++++++++------- .../com/pitchedapps/frost/web/LoginWebView.kt | 15 +++----- app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4c247eda..50015adb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,10 +18,11 @@ before_install: - tar xvf frost.tar - chmod +x gradlew after_success: -- ./gradlew androidGitVersion - if [[ "$TRAVIS_BRANCH" != "master" ]]; then chmod +x ./generate-apk-release.sh; ./generate-apk-release.sh; fi script: - cd $TRAVIS_BUILD_DIR/ +- printf "Starting script\n" +- ./gradlew --quiet androidGitVersion - if [[ "$TRAVIS_BRANCH" == "master" ]]; then ./gradlew publishRelease; else ./gradlew assembleReleaseTest; fi notifications: email: false diff --git a/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt index da70714d..9b79b996 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt @@ -86,12 +86,13 @@ class LoginActivity : BaseActivity() { .observeOn(AndroidSchedulers.mainThread()).subscribe { (foundImage, name) -> refresh = false - if (!foundImage) L.eThrow("Could not get profile photo; Invalid userId?\n\t$cookie") + if (!foundImage) { + L.eThrow("Could not get profile photo; Invalid userId?") + L.i("-\t$cookie") + } textview.text = String.format(getString(R.string.welcome), name) textview.fadeIn() - frostAnswers { - logLogin(LoginEvent().putMethod("frost_browser").putSuccess(true)) - } + frostAnswers { logLogin(LoginEvent().putMethod("frost_browser").putSuccess(true)) } /* * The user may have logged into an account that is already in the database * We will let the db handle duplicates and load it now after the new account has been saved @@ -117,6 +118,7 @@ class LoginActivity : BaseActivity() { } override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { + if (e != null) L.e(e, "Profile loading exception") profileObservable.onSuccess(false) return false } @@ -124,8 +126,6 @@ class LoginActivity : BaseActivity() { } fun loadUsername(cookie: CookieModel) { - cookie.fetchUsername { - usernameObservable.onSuccess(it) - } + cookie.fetchUsername { usernameObservable.onSuccess(it) } } } \ 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 da735430..a2dc82f3 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 @@ -34,9 +34,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) { + operator fun invoke(activity: Activity, + mustHavePlayStore: Boolean = true, + userRequest: Boolean = true, + onFailed: () -> Unit = {}, + onStart: (helper: IabHelper) -> Unit) { with(activity) { - if (helper?.mDisposed ?: helper?.mDisposeAfterAsync ?: true) { + if (isInProgress) if (userRequest) snackbar(R.string.iab_still_in_progress, Snackbar.LENGTH_LONG) + else if (helper?.disposed ?: true) { helper = null L.d("IAB setup async") if (!isFrostPlay) { @@ -80,16 +85,27 @@ object IAB { */ fun dispose() { helper?.disposeWhenFinished() - helper?.flagEndAsync() helper = null } + /** + * Dispose given helper and check if it matches with our own helper + */ + fun dispose(helper: IabHelper) { + helper.disposeWhenFinished() + if (IAB.helper?.disposed ?: true) + this.helper = null + } + val isInProgress: Boolean get() = helper?.mAsyncInProgress ?: false } private const val FROST_PRO = "frost_pro" +private val IabHelper.disposed: Boolean + get() = mDisposed || mDisposeAfterAsync + val IS_FROST_PRO: Boolean get() = (BuildConfig.DEBUG && Prefs.debugPro) || Prefs.pro @@ -109,8 +125,8 @@ fun SettingsActivity.restorePurchases() { } finishRestore(restore, false) } - getInventory(false, reset) { - inv, _ -> + getInventory(false, true, reset) { + inv, helper -> val proSku = inv.hasPurchase(FROST_PRO) Prefs.pro = proSku L.d("Restore found: ${Prefs.pro}") @@ -126,7 +142,6 @@ private fun SettingsActivity.finishRestore(snackbar: Snackbar, hasPro: Boolean) positiveText(R.string.reload) dismissListener { adapter.notifyAdapterDataSetChanged() } } - IAB.dispose() } /** @@ -135,21 +150,22 @@ private fun SettingsActivity.finishRestore(snackbar: Snackbar, hasPro: Boolean) */ fun Activity.validatePro() { L.d("Validate pro") - getInventory(Prefs.pro, { if (Prefs.pro) playStoreNoLongerPro() }) { - inv, _ -> + getInventory(Prefs.pro, false, { if (Prefs.pro) playStoreNoLongerPro() }) { + inv, helper -> val proSku = inv.hasPurchase(FROST_PRO) L.d("Validation finished: ${Prefs.pro} should be $proSku") if (!proSku && Prefs.pro) playStoreNoLongerPro() else if (proSku && !Prefs.pro) playStoreFoundPro() - IAB.dispose() + helper.disposeWhenFinished() } } fun Activity.getInventory( mustHavePlayStore: Boolean = true, + userRequest: Boolean = true, onFailed: () -> Unit = {}, onSuccess: (inv: Inventory, helper: IabHelper) -> Unit) { - IAB(this, mustHavePlayStore, onFailed) { + IAB(this, mustHavePlayStore, userRequest, onFailed) { helper -> helper.queryInventoryAsync { res, inv -> @@ -170,12 +186,11 @@ fun Activity.openPlayProPurchase(code: Int) { fun Activity.openPlayPurchase(key: String, code: Int, onSuccess: (key: String) -> Unit) { L.d("Open play purchase $key $code") - getInventory(true, { playStoreGenericError("Query res error") }) { + getInventory(true, true, { playStoreGenericError("Query res error") }) { inv, helper -> if (inv.hasPurchase(key)) { playStoreAlreadyPurchased(key) onSuccess(key) - IAB.dispose() return@getInventory } L.d("IAB: inventory ${inv.allOwnedSkus}") @@ -184,7 +199,6 @@ fun Activity.openPlayPurchase(key: String, code: Int, onSuccess: (key: String) - if (result.isSuccess) { onSuccess(key) playStorePurchasedSuccessfully(key) - IAB.dispose() } frostAnswers { logPurchase(PurchaseEvent() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index a42ee4fb..38d4ad8c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -44,17 +44,10 @@ class LoginWebView @JvmOverloads constructor( .subscribe { (url, cookie) -> L.d("Checking cookie for login", "$url\n\t$cookie") - val id = userMatcher.find(cookie!!)?.groups?.get(1)?.value - if (id != null) { - try { - FbCookie.save(id.toLong()) - //TODO proceed to next view - cookieObservable.onComplete() - loginObservable.onSuccess(CookieModel(id.toLong(), "", cookie)) - } catch (e: NumberFormatException) { - //todo send report that userId has changed - } - } + val id = userMatcher.find(cookie!!)?.groups?.get(1)?.value!! + FbCookie.save(id.toLong()) + cookieObservable.onComplete() + loginObservable.onSuccess(CookieModel(id.toLong(), "", cookie)) } setupWebview() }) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b79c6823..a67861ef 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -88,4 +88,6 @@ com.raizlabs.android.dbflow mit + Login failed; id not found + IAB query is still in progress -- cgit v1.2.3