From 5e9ed54c90f994f99deb105d57f4d5b3ca1db8cd Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 16 Sep 2017 18:18:28 -0400 Subject: Fix/messaging overlay (#291) * Create base switcher * Add intent blacklist * Revert extra overlay * Add user agent enum * Test per link user agents * Test extra overlays once again * Fix up messaging overlays --- .../frost/web/FrostUrlOverlayValidator.kt | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt index 29d2e991..2d9915be 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt @@ -1,7 +1,10 @@ package com.pitchedapps.frost.web -import android.content.Context +import com.pitchedapps.frost.activities.WebOverlayBasicActivity +import com.pitchedapps.frost.activities.WebOverlayActivity +import com.pitchedapps.frost.activities.WebOverlayActivityBase import com.pitchedapps.frost.facebook.FbItem +import com.pitchedapps.frost.facebook.USER_AGENT_BASIC import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.isFacebookUrl @@ -14,15 +17,36 @@ import com.pitchedapps.frost.utils.launchWebOverlay * cannot be resolved on a new window and must instead * by loaded in the current page * This helper method will collect all known cases and launch the overlay accordingly - * Returns {@code true} (default) if overlay is launcher, {@code false} otherwise + * Returns {@code true} (default) if overlay is launched, {@code false} otherwise + * + * If the request already comes from an instance of [WebOverlayActivity], we will then judge + * whether the user agent string should be changed. All propagated results will return false, + * as we have no need of sending a new intent to the same activity */ -fun Context.requestWebOverlay(url: String): Boolean { +fun FrostWebViewCore.requestWebOverlay(url: String): Boolean { if (url == "#") return false + + if (context is WebOverlayActivityBase) { + L.v("Check web request from overlay", url) + //already overlay; manage user agent + if (userAgentString != USER_AGENT_BASIC && url.formattedFbUrl.shouldUseBasicAgent) { + L.i("Switch to basic agent overlay") + context.launchWebOverlay(url, WebOverlayBasicActivity::class.java) + return true + } + if (context is WebOverlayBasicActivity && !url.formattedFbUrl.shouldUseBasicAgent) { + L.i("Switch from basic agent") + context.launchWebOverlay(url) + return true + } + L.i("return false switch") + return false + } /* * Non facebook urls can be loaded */ if (!url.formattedFbUrl.isFacebookUrl) { - launchWebOverlay(url) + context.launchWebOverlay(url) L.d("Request web overlay is not a facebook url", url) return true } @@ -39,7 +63,7 @@ fun Context.requestWebOverlay(url: String): Boolean { if (!url.contains("?tid=id") && !url.contains("?tid=mid")) return false } L.v("Request web overlay passed", url) - launchWebOverlay(url) + context.launchWebOverlay(url) return true } @@ -48,6 +72,9 @@ fun Context.requestWebOverlay(url: String): Boolean { */ val messageWhitelist = setOf(FbItem.MESSAGES.url, FbItem.CHAT.url) +val String.shouldUseBasicAgent + get() = (messageWhitelist.any { contains(it) }) + /** * The following components should never be launched in a new overlay */ -- cgit v1.2.3