diff options
author | Allan Wang <me@allanwang.ca> | 2019-09-28 23:53:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-28 23:53:47 -0700 |
commit | c9fec8cc993f159eb81803e8c0cd5855d2a9abd3 (patch) | |
tree | c3ae5a6890b0797110f397b99812362312c07ff6 /app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt | |
parent | f5ae18fc0d824dbdce5523128f9ded86bdfa6d08 (diff) | |
parent | 73e16427879908e8b46b7c9fe1e87b0df838fa78 (diff) | |
download | frost-c9fec8cc993f159eb81803e8c0cd5855d2a9abd3.tar.gz frost-c9fec8cc993f159eb81803e8c0cd5855d2a9abd3.tar.bz2 frost-c9fec8cc993f159eb81803e8c0cd5855d2a9abd3.zip |
Merge pull request #1559 from AllanWang/desktop-url-convert
Convert desktop urls to mobile ones
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt | 28 |
1 files changed, 24 insertions, 4 deletions
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 24608a8b..3df3b2c2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt @@ -22,15 +22,19 @@ import com.pitchedapps.frost.activities.WebOverlayActivityBase import com.pitchedapps.frost.contracts.VideoViewHolder import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem +import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP_CONST import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.isFacebookUrl import com.pitchedapps.frost.utils.isImageUrl import com.pitchedapps.frost.utils.isIndependent import com.pitchedapps.frost.utils.isIndirectImageUrl import com.pitchedapps.frost.utils.isVideoUrl import com.pitchedapps.frost.utils.launchImageActivity import com.pitchedapps.frost.utils.launchWebOverlay +import com.pitchedapps.frost.utils.launchWebOverlayDesktop +import com.pitchedapps.frost.utils.launchWebOverlayMobile import com.pitchedapps.frost.views.FrostWebView /** @@ -50,21 +54,22 @@ import com.pitchedapps.frost.views.FrostWebView * as we have no need of sending a new intent to the same activity */ fun FrostWebView.requestWebOverlay(url: String): Boolean { + @Suppress("NAME_SHADOWING") val url = url.formattedFbUrl L.v { "Request web overlay: $url" } val context = context // finalize reference if (url.isVideoUrl && context is VideoViewHolder) { L.d { "Found video through overlay" } - context.runOnUiThread { context.showVideo(url.formattedFbUrl) } + context.runOnUiThread { context.showVideo(url) } return true } if (url.isImageUrl) { L.d { "Found fb image" } - context.launchImageActivity(url.formattedFbUrl) + context.launchImageActivity(url) return true } if (url.isIndirectImageUrl) { L.d { "Found indirect fb image" } - context.launchImageActivity(url.formattedFbUrl, cookie = FbCookie.webCookie) + context.launchImageActivity(url, cookie = FbCookie.webCookie) return true } if (!url.isIndependent) { @@ -72,7 +77,22 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean { return false } if (!Prefs.overlayEnabled) return false - if (context is WebOverlayActivityBase) return false + if (context is WebOverlayActivityBase) { + val shouldUseDesktop = url.isFacebookUrl + //already overlay; manage user agent + if (userAgentString != USER_AGENT_DESKTOP_CONST && shouldUseDesktop) { + L._i { "Switch to desktop agent overlay" } + context.launchWebOverlayDesktop(url) + return true + } + if (userAgentString == USER_AGENT_DESKTOP_CONST && !shouldUseDesktop) { + L._i { "Switch from desktop agent" } + context.launchWebOverlayMobile(url) + return true + } + L._i { "return false switch" } + return false + } L.v { "Request web overlay passed" } context.launchWebOverlay(url) return true |