From bf2168ee57ded706819d1e4f49d729d4f45e1d29 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 19 Aug 2017 20:31:53 -0700 Subject: Fix link issue and add option to use default browser --- app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt | 4 ++++ app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt | 1 + app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 7 ++++--- .../main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt | 6 +++--- app/src/main/res/values/strings_pref_behaviour.xml | 2 ++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt index bf524835..acdd835e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -23,6 +23,10 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.overlay_full_screen_swipe_desc } + checkbox(R.string.open_links_in_default, { Prefs.linksInDefaultApp }, { Prefs.linksInDefaultApp = it }) { + descRes = R.string.open_links_in_default_desc + } + checkbox(R.string.viewpager_swipe, { Prefs.viewpagerSwipe }, { Prefs.viewpagerSwipe = it }) { descRes = R.string.viewpager_swipe_desc } 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 34257da8..126bd500 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -131,4 +131,5 @@ object Prefs : KPref() { var debugSettings: Boolean by kpref("debug_settings", false) + var linksInDefaultApp: Boolean by kpref("link_in_default_app", 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 469a3951..92d4c109 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -65,9 +65,10 @@ fun Context.launchWebOverlay(url: String) { val argUrl = url.formattedFbUrl L.v("Launch received", url) L.i("Launch web overlay", argUrl) - startActivity(WebOverlayActivity::class.java, false, intentBuilder = { - putExtra(ARG_URL, argUrl) - }) + if (!(Prefs.linksInDefaultApp && resolveActivityForUri(Uri.parse(argUrl)))) + startActivity(WebOverlayActivity::class.java, false, intentBuilder = { + putExtra(ARG_URL, argUrl) + }) } fun Context.launchImageActivity(imageUrl: String, text: String?) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index b1466ee8..22b628e9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -48,7 +48,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) if (url == null) return - L.i("FWV Loading", url) + L.d("FWV Loading", url) refreshObservable.onNext(true) if (!url.isFacebookUrl) return if (url.contains("logout.php")) FbCookie.logout(Prefs.userId, { launchLogin(view.context) }) @@ -81,7 +81,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient override fun onPageFinished(view: WebView, url: String?) { url ?: return - L.i("Page finished", url) + L.d("Page finished", url) if (!url.isFacebookUrl) { refreshObservable.onNext(false) return @@ -141,7 +141,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient if (path.startsWith("/composer/")) return launchRequest(request) if (request.url.toString().contains("scontent-sea1-1.xx.fbcdn.net") && (path.endsWith(".jpg") || path.endsWith(".png"))) return launchImage(request.url.toString()) - if (view.context.resolveActivityForUri(request.url)) return true + if (Prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) return true return super.shouldOverrideUrlLoading(view, request) } diff --git a/app/src/main/res/values/strings_pref_behaviour.xml b/app/src/main/res/values/strings_pref_behaviour.xml index 6563ef69..d768a87f 100644 --- a/app/src/main/res/values/strings_pref_behaviour.xml +++ b/app/src/main/res/values/strings_pref_behaviour.xml @@ -7,6 +7,8 @@ Pressing most links will launch in a new overlay so you can easily swipe back to the original page. Note that this does result in slightly longer loads given that the whole page is reloaded. Overlay Full Screen Swipe to Dismiss Swipe right from anywhere on the overlaying web to close the browser. If disabled, only swiping from the left edge will move it. + Open Links in Default App + When possible, open links in the default app rather than through the Frost web overlay Viewpager Swipe Allow swiping between the pages in the main view to switch tabs. By default, the swiping automatically stops when you long press on an item, such as the like button. Disabling this will prevent page swiping altogether. Search Bar -- cgit v1.2.3