diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
5 files changed, 106 insertions, 20 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/AnimatedVectorDelegate.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/AnimatedVectorDelegate.kt new file mode 100644 index 00000000..a530df32 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/AnimatedVectorDelegate.kt @@ -0,0 +1,82 @@ +package com.pitchedapps.frost.utils + +import android.graphics.drawable.AnimatedVectorDrawable +import android.support.annotation.DrawableRes +import android.widget.ImageView +import ca.allanwang.kau.utils.drawable + +/** + * Created by Allan Wang on 2017-07-29. + * + * Delegate for animated vector drawables with two states (start and end) + * Drawables are added lazily depending on the animation direction, and are verified upon load + * Should the bounded view not have an animated drawable upon animating, it is assumed + * that the user has switched the resource themselves and the delegate will not switch the resource + */ +interface AnimatedVectorContract { + fun animate() + fun animateReverse() + fun animateToggle() + val isAtStart: Boolean + fun bind(view: ImageView) + var animatedVectorListener: ((avd: AnimatedVectorDrawable, forwards: Boolean) -> Unit)? +} + +class AnimatedVectorDelegate( + /** + * The res for the starting resource; must have parent tag animated-vector + */ + @param:DrawableRes val avdStart: Int, + /** + * The res for the ending resource; must have parent tag animated-vector + */ + @param:DrawableRes val avdEnd: Int, + /** + * The delegate will automatically set the start resource when bound + * If [emitOnBind] is true, it will also trigger the listener + */ + val emitOnBind: Boolean = true, + /** + * The optional listener that will be triggered every time the avd is switched by the delegate + */ + override var animatedVectorListener: ((avd: AnimatedVectorDrawable, forwards: Boolean) -> Unit)? = null +) : AnimatedVectorContract { + + lateinit var view: ImageView + + private var atStart = true + + override val isAtStart: Boolean + get() = atStart + + private val avd: AnimatedVectorDrawable? + get() = view.drawable as? AnimatedVectorDrawable + + override fun bind(view: ImageView) { + this.view = view + view.context.drawable(avdStart) as? AnimatedVectorDrawable ?: throw IllegalArgumentException("AnimatedVectorDelegate has a starting drawable that isn't an avd") + view.context.drawable(avdEnd) as? AnimatedVectorDrawable ?: throw IllegalArgumentException("AnimatedVectorDelegate has an ending drawable that isn't an avd") + view.setImageResource(avdStart) + if (emitOnBind) animatedVectorListener?.invoke(avd!!, false) + } + + override fun animate() = animateImpl(false) + + override fun animateReverse() = animateImpl(true) + + override fun animateToggle() = animateImpl(!atStart) + + private fun animateImpl(toStart: Boolean) { + if ((atStart == toStart)) return L.d("AVD already at ${if (toStart) "start" else "end"}") + if (avd == null) return L.d("AVD null resource")//no longer using animated vector; do not modify + avd?.stop() + view.setImageResource(if (toStart) avdEnd else avdStart) + animatedVectorListener?.invoke(avd!!, !toStart) + atStart = toStart + avd?.start() + } + +} + + + diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt index 57cbef7e..b3601dfb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt @@ -14,6 +14,8 @@ object Showcase : KPref() { //check if this is the first time launching the web overlay; show snackbar if true val firstWebOverlay: Boolean by kprefSingle("first_web_overlay") + val intro: Boolean by kprefSingle("intro_pages") + //not a showcase but cannot be in the same file as Prefs var experimentalDefault: Boolean by kpref("experimental_by_default", false) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index 442216fb..40e16f20 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -20,10 +20,7 @@ import com.crashlytics.android.answers.Answers import com.crashlytics.android.answers.CustomEvent import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.R -import com.pitchedapps.frost.activities.ImageActivity -import com.pitchedapps.frost.activities.LoginActivity -import com.pitchedapps.frost.activities.SelectorActivity -import com.pitchedapps.frost.activities.WebOverlayActivity +import com.pitchedapps.frost.activities.* import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.facebook.FbTab import com.pitchedapps.frost.facebook.formattedFbUrl @@ -68,6 +65,9 @@ fun Context.launchImageActivity(imageUrl: String, text: String?) { }) } +fun Activity.launchIntroActivity(cookieList: ArrayList<CookieModel>) + = launchNewTask(IntroActivity::class.java, cookieList, true) + fun WebOverlayActivity.url(): String { return intent.extras?.getString(ARG_URL) ?: FbTab.FEED.url } @@ -140,4 +140,4 @@ fun Activity.frostNavigationBar() { navigationBarColor = if (Prefs.tintNavBar) Prefs.headerColor else Color.BLACK } -fun <T> RequestBuilder<T>.withRoundIcon() = apply(RequestOptions().transform(CircleCrop()))
\ No newline at end of file +fun <T> RequestBuilder<T>.withRoundIcon() = apply(RequestOptions().transform(CircleCrop()))!!
\ No newline at end of file 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 ab9e37d1..b3992ff4 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 @@ -34,7 +34,7 @@ abstract class IABBinder : FrostBilling { override fun Activity.onCreateBilling() { activity = this bp = BillingProcessor.newBillingProcessor(this, PUBLIC_BILLING_KEY, this@IABBinder) - bp!!.initialize() + bp?.initialize() } override fun onDestroyBilling() { @@ -79,10 +79,10 @@ abstract class IABBinder : FrostBilling { L.eThrow("IAB null bp on purchase attempt") return } - if (!bp!!.isOneTimePurchaseSupported) - activity!!.playStorePurchaseUnsupported() + if (!(bp?.isOneTimePurchaseSupported ?: false)) + activity?.playStorePurchaseUnsupported() else - bp!!.purchase(activity, FROST_PRO) + bp?.purchase(activity, FROST_PRO) } } @@ -104,14 +104,14 @@ class IABSettings : IABBinder() { */ override fun restorePurchases() { if (bp == null) return - val load = bp!!.loadOwnedPurchasesFromGoogle() + val load = bp?.loadOwnedPurchasesFromGoogle() ?: return L.d("IAB settings load from google $load") - if (!bp!!.isPurchased(FROST_PRO)) { - if (Prefs.pro) activity!!.playStoreNoLongerPro() + if (!(bp?.isPurchased(FROST_PRO) ?: return)) { + if (Prefs.pro) activity.playStoreNoLongerPro() else purchasePro() } else { - if (!Prefs.pro) activity!!.playStoreFoundPro() - else activity!!.purchaseRestored() + if (!Prefs.pro) activity.playStoreFoundPro() + else activity?.purchaseRestored() } } } @@ -138,12 +138,12 @@ class IABMain : IABBinder() { override fun restorePurchases() { if (restored || bp == null) return restored = true - val load = bp!!.loadOwnedPurchasesFromGoogle() + val load = bp?.loadOwnedPurchasesFromGoogle() ?: false L.d("IAB main load from google $load") - if (!bp!!.isPurchased(FROST_PRO)) { - if (Prefs.pro) activity!!.playStoreNoLongerPro() + if (!(bp?.isPurchased(FROST_PRO) ?: false)) { + if (Prefs.pro) activity.playStoreNoLongerPro() } else { - if (!Prefs.pro) activity!!.playStoreFoundPro() + if (!Prefs.pro) activity.playStoreFoundPro() } onDestroyBilling() } 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 d2f22829..df0f04fd 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 @@ -31,7 +31,7 @@ private fun Activity.playRestart() { } else restart() } -fun Activity.playStoreNoLongerPro() { +fun Activity?.playStoreNoLongerPro() { Prefs.pro = false L.d("IAB No longer pro") frostAnswers { @@ -39,6 +39,7 @@ fun Activity.playStoreNoLongerPro() { .putCustomAttribute("result", "no longer pro") .putSuccess(false)) } + if (this == null) return materialDialogThemed { title(R.string.uh_oh) content(R.string.play_store_not_pro) @@ -49,9 +50,10 @@ fun Activity.playStoreNoLongerPro() { } } -fun Activity.playStoreFoundPro() { +fun Activity?.playStoreFoundPro() { Prefs.pro = true L.d("Found pro") + if (this == null) return materialDialogThemed { title(R.string.found_pro) content(R.string.found_pro_desc) |