diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-25 15:18:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-25 15:18:12 -0700 |
commit | d94bc858c8a0c273d87d705eb06d35cfd9cf9e08 (patch) | |
tree | 05220a36a87a73388b89901f4fe5cd09d3fd48d5 /app/src/main/kotlin/com/pitchedapps/frost/utils | |
parent | 913eaf7ea029030d7354a3969dc6aa87b0a51b1a (diff) | |
download | frost-d94bc858c8a0c273d87d705eb06d35cfd9cf9e08.tar.gz frost-d94bc858c8a0c273d87d705eb06d35cfd9cf9e08.tar.bz2 frost-d94bc858c8a0c273d87d705eb06d35cfd9cf9e08.zip |
Update image downloads , IAB, and many issue reports (#95)v1.4
* Remove iab proguard line
* Remove dup vending aidl
* Fix double calling issue
* Change pro logging
* Remove async call
* Allow for multiple result flags from settings
* Rename restore to get
* Remove remaining async
* Add null checks across web clients
* Do not delete temp file on save
* Implement image logic
* Update file chooser
* Update travis
* Add intent checker
* Update dependencies
* Update dependencies
* Add debugging option
* Switch context for login glide
* Scan newly added files
* Update theme
* Allow image downloading in messages
* Finalize beta release
* Build to beta
* Update strings
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
4 files changed, 87 insertions, 51 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index 63e57554..a20e755f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -119,7 +119,7 @@ object Prefs : KPref() { var analytics: Boolean by kpref("analytics", true) - var searchBar: Boolean by kpref("search_bar", Showcase.experimentalDefault) + var searchBar: Boolean by kpref("search_bar", true) var overlayEnabled: Boolean by kpref("overlay_enabled", true) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt index 40de99bf..ea66030f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt @@ -1,12 +1,14 @@ package com.pitchedapps.frost.utils import android.content.Context +import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.utils.copyToClipboard import ca.allanwang.kau.utils.shareText import ca.allanwang.kau.utils.string import ca.allanwang.kau.utils.toast import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.MainActivity +import com.pitchedapps.frost.facebook.formattedFbUrl /** * Created by Allan Wang on 2017-07-07. @@ -34,12 +36,28 @@ fun Context.showWebContextMenu(wc: WebContext) { } } -class WebContext(val url: String, val text: String?) +class WebContext(val unformattedUrl: String, val text: String?) { + val url = unformattedUrl.formattedFbUrl +} enum class WebContextType(val textId: Int, val onClick: (c: Context, wc: WebContext) -> Unit) { COPY_LINK(R.string.copy_link, { c, wc -> c.copyToClipboard(wc.url) }), COPY_TEXT(R.string.copy_text, { c, wc -> if (wc.text != null) c.copyToClipboard(wc.text) else c.toast(R.string.no_text) }), - SHARE_LINK(R.string.share_link, { c, wc -> c.shareText(wc.url) }) + SHARE_LINK(R.string.share_link, { c, wc -> c.shareText(wc.url) }), + DEBUG_LINK(R.string.debug_link, { c, wc -> + c.materialDialogThemed { + title(R.string.debug_link) + content(R.string.debug_link_desc) + positiveText(R.string.kau_ok) + onPositive { _, _ -> + c.sendEmail(R.string.dev_email, R.string.debug_link_subject) { + message = c.string(R.string.debug_link_content) + addItem("Unformatted url", wc.unformattedUrl) + addItem("Formatted url", wc.url) + } + } + } + }) ; companion object { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABBinder.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABBinder.kt index 53d3e058..ab9e37d1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABBinder.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IABBinder.kt @@ -9,8 +9,6 @@ import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.frostAnswers -import org.jetbrains.anko.doAsync -import org.jetbrains.anko.uiThread /** * Created by Allan Wang on 2017-07-22. @@ -24,18 +22,18 @@ interface FrostBilling : BillingProcessor.IBillingHandler { fun Activity.onCreateBilling() fun onDestroyBilling() fun purchasePro() - fun restorePurchases(once: Boolean) + fun restorePurchases() fun onActivityResultBilling(requestCode: Int, resultCode: Int, data: Intent?): Boolean } -open class IABBinder : FrostBilling { +abstract class IABBinder : FrostBilling { var bp: BillingProcessor? = null var activity: Activity? = null override fun Activity.onCreateBilling() { - bp = BillingProcessor.newBillingProcessor(this, PUBLIC_BILLING_KEY, this@IABBinder) activity = this + bp = BillingProcessor.newBillingProcessor(this, PUBLIC_BILLING_KEY, this@IABBinder) bp!!.initialize() } @@ -45,15 +43,11 @@ open class IABBinder : FrostBilling { activity = null } - override fun onBillingInitialized() { - L.d("IAB initialized") - } + override fun onBillingInitialized() = L.d("IAB initialized") - override fun onPurchaseHistoryRestored() { - L.d("IAB restored") - } + override fun onPurchaseHistoryRestored() = L.d("IAB restored") - override fun onProductPurchased(productId: String, details: TransactionDetails) { + override fun onProductPurchased(productId: String, details: TransactionDetails?) { L.d("IAB $productId purchased") frostAnswers { logPurchase(PurchaseEvent() @@ -63,7 +57,7 @@ open class IABBinder : FrostBilling { } } - override fun onBillingError(errorCode: Int, error: Throwable) { + override fun onBillingError(errorCode: Int, error: Throwable?) { frostAnswers { logPurchase(PurchaseEvent() .putCustomAttribute("result", errorCode.toString()) @@ -76,64 +70,81 @@ open class IABBinder : FrostBilling { = bp?.handleActivityResult(requestCode, resultCode, data) ?: false override fun purchasePro() { - if (bp == null) return + if (bp == null) { + frostAnswers { + logPurchase(PurchaseEvent() + .putCustomAttribute("result", "null bp") + .putSuccess(false)) + } + L.eThrow("IAB null bp on purchase attempt") + return + } if (!bp!!.isOneTimePurchaseSupported) activity!!.playStorePurchaseUnsupported() else bp!!.purchase(activity, FROST_PRO) } - override fun restorePurchases(once: Boolean) { - if (bp == null) return - doAsync { - bp?.loadOwnedPurchasesFromGoogle() - if (bp?.isPurchased(FROST_PRO) ?: false) { - uiThread { - if (Prefs.pro) activity!!.playStoreNoLongerPro() - else if (!once) purchasePro() - if (once) onDestroyBilling() - } - } else { - uiThread { - if (!Prefs.pro) activity!!.playStoreFoundPro() - else if (!once) activity!!.purchaseRestored() - if (once) onDestroyBilling() - } - } - } - } } class IABSettings : IABBinder() { - override fun onBillingInitialized() { - super.onBillingInitialized() - - } - - override fun onPurchaseHistoryRestored() { - super.onPurchaseHistoryRestored() - } - - override fun onProductPurchased(productId: String, details: TransactionDetails) { + override fun onProductPurchased(productId: String, details: TransactionDetails?) { super.onProductPurchased(productId, details) + activity?.playStorePurchasedSuccessfully(productId) } - override fun onBillingError(errorCode: Int, error: Throwable) { + override fun onBillingError(errorCode: Int, error: Throwable?) { super.onBillingError(errorCode, error) activity?.playStoreGenericError(null) } + + /** + * Attempts to get pro, or launch purchase flow if user doesn't have it + */ + override fun restorePurchases() { + if (bp == null) return + val load = bp!!.loadOwnedPurchasesFromGoogle() + L.d("IAB settings load from google $load") + if (!bp!!.isPurchased(FROST_PRO)) { + if (Prefs.pro) activity!!.playStoreNoLongerPro() + else purchasePro() + } else { + if (!Prefs.pro) activity!!.playStoreFoundPro() + else activity!!.purchaseRestored() + } + } } class IABMain : IABBinder() { override fun onBillingInitialized() { super.onBillingInitialized() - restorePurchases(true) + restorePurchases() } override fun onPurchaseHistoryRestored() { super.onPurchaseHistoryRestored() - restorePurchases(true) + restorePurchases() + } + + private var restored = false + + /** + * Checks for pro and only does so once + * A null check is added but it should never happen + * given that this is only called with bp is ready + */ + override fun restorePurchases() { + if (restored || bp == null) return + restored = true + val load = bp!!.loadOwnedPurchasesFromGoogle() + L.d("IAB main load from google $load") + if (!bp!!.isPurchased(FROST_PRO)) { + if (Prefs.pro) activity!!.playStoreNoLongerPro() + } else { + if (!Prefs.pro) activity!!.playStoreFoundPro() + } + onDestroyBilling() } }
\ No newline at end of file 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 4f750b6b..d2f22829 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 @@ -4,11 +4,13 @@ import android.app.Activity import ca.allanwang.kau.utils.restart import ca.allanwang.kau.utils.startPlayStoreLink import ca.allanwang.kau.utils.string +import com.crashlytics.android.answers.PurchaseEvent import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.MainActivity import com.pitchedapps.frost.activities.SettingsActivity import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.frostAnswers import com.pitchedapps.frost.utils.materialDialogThemed /** @@ -16,7 +18,7 @@ import com.pitchedapps.frost.utils.materialDialogThemed */ private fun playStoreLog(text: String) { - L.e(Throwable(text), "Play Store Exception") + L.e(Throwable(text), "IAB Play Store Exception") } /** @@ -31,7 +33,12 @@ private fun Activity.playRestart() { fun Activity.playStoreNoLongerPro() { Prefs.pro = false - playStoreLog("No Longer Pro") + L.d("IAB No longer pro") + frostAnswers { + logPurchase(PurchaseEvent() + .putCustomAttribute("result", "no longer pro") + .putSuccess(false)) + } materialDialogThemed { title(R.string.uh_oh) content(R.string.play_store_not_pro) |