aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt14
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt40
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt15
-rw-r--r--app/src/main/res/values/strings.xml2
4 files changed, 40 insertions, 31 deletions
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<Drawable>?, 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 @@
<string name="library_dbflow_classPath">com.raizlabs.android.dbflow</string>
<!-- License section -->
<string name="library_dbflow_licenseId">mit</string>
+ <string name="login_id_failed">Login failed; id not found</string>
+ <string name="iab_still_in_progress">IAB query is still in progress</string>
</resources>