diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
4 files changed, 56 insertions, 14 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 7b5eca2a..95642a7a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -71,6 +71,8 @@ object Prefs : KPref() { var tintNavBar: Boolean by kpref("tint_nav_bar", true) + var webTextScaling: Int by kpref("web_text_scaling", 100) + var feedSort: Int by kpref("feed_sort", FeedSort.DEFAULT.ordinal) var showRoundedIcons: Boolean by kpref("rounded_icons", true) @@ -101,4 +103,6 @@ object Prefs : KPref() { var overlayFullScreenSwipe: Boolean by kpref("overlay_full_screen_swipe", true) + var viewpagerSwipe: Boolean by kpref("viewpager_swipe", true) + } 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 9fee3571..6f3459d7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -23,8 +23,8 @@ import com.crashlytics.android.answers.Answers import com.crashlytics.android.answers.CustomEvent import com.pitchedapps.frost.* import com.pitchedapps.frost.dbflow.CookieModel -import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.facebook.FbTab +import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.services.NotificationService /** @@ -51,17 +51,6 @@ fun Activity.cookies(): ArrayList<CookieModel> { return intent?.extras?.getParcelableArrayList<CookieModel>(EXTRA_COOKIES) ?: arrayListOf() } -val String.formattedFbUrl: String - get() { - var url = this - if (url.startsWith("#!/")) url = url.substring(2) - if (url.startsWith('/')) url = FB_URL_BASE + url.substring(1) - url = url.replace("/#!/", "/") - val ref = url.indexOf("?ref") - if (ref != -1) url = url.substring(0, ref) - return url - } - fun Context.launchWebOverlay(url: String) { val argUrl = url.formattedFbUrl L.v("Launch received $url") @@ -172,4 +161,5 @@ fun View.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = {}) fun Activity.frostNavigationBar() { navigationBarColor = if (Prefs.tintNavBar) Prefs.headerColor else Color.BLACK -}
\ No newline at end of file +} + diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt new file mode 100644 index 00000000..67c20a5a --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt @@ -0,0 +1,45 @@ +package com.pitchedapps.frost.utils + +import android.content.Context +import ca.allanwang.kau.utils.copyToClipboard +import ca.allanwang.kau.utils.shareText +import ca.allanwang.kau.utils.string +import com.pitchedapps.frost.MainActivity +import com.pitchedapps.frost.R + +/** + * Created by Allan Wang on 2017-07-07. + */ +fun Context.showWebContextMenu(wc: WebContext) { + + var title = wc.url + title = title.substring(title.indexOf("m/") + 1) //just so if defaults to 0 in case it's not .com/ + if (title.length > 100) title = title.substring(0, 100) + '\u2026' + + materialDialogThemed { + title(title) + items(WebContextType.values.map { this@showWebContextMenu.string(it.textId) }) + itemsCallback { + _, _, position, _ -> + WebContextType[position].onClick(this@showWebContextMenu, wc) + } + dismissListener { + //showing the dialog interrupts the touch down event, so we must ensure that the viewpager's swipe is enabled + (this@showWebContextMenu as? MainActivity)?.viewPager?.enableSwipe = true + } + } +} + +class WebContext(val url: String, val text: String) + +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 -> c.copyToClipboard(wc.text) }), + SHARE_LINK(R.string.share_link, { c, wc -> c.shareText(wc.url) }) + ; + + companion object { + val values = values() + operator fun get(index: Int) = values[index] + } +}
\ 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 a2dc82f3..21326efa 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 @@ -170,7 +170,10 @@ fun Activity.getInventory( helper.queryInventoryAsync { res, inv -> L.d("Inventory query finished") - if (res.isFailure || inv == null) onFailed() + if (res.isFailure || inv == null) { + L.e("Res error ${res.message}") + onFailed() + } else onSuccess(inv, helper) } } |