aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-09-28 23:26:22 -0700
committerAllan Wang <me@allanwang.ca>2019-09-28 23:26:22 -0700
commit9b32e6c884797985e72deb18c05ea3d434a966ac (patch)
treefd0429f4a7eacad1e7827ba494f9cf30f9efe0f0 /app/src/main/kotlin
parent8fb903398a3692e42d4ea8ddcf047937841f5901 (diff)
downloadfrost-9b32e6c884797985e72deb18c05ea3d434a966ac.tar.gz
frost-9b32e6c884797985e72deb18c05ea3d434a966ac.tar.bz2
frost-9b32e6c884797985e72deb18c05ea3d434a966ac.zip
Use mobile agent for non facebook urls
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt18
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt28
4 files changed, 50 insertions, 7 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
index 2f49b235..9d7d6e76 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
@@ -59,6 +59,9 @@ import com.pitchedapps.frost.enums.OverlayContext
import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
+import com.pitchedapps.frost.facebook.USER_AGENT
+import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP_CONST
+import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE_CONST
import com.pitchedapps.frost.facebook.formattedFbUrl
import com.pitchedapps.frost.kotlin.subscribeDuringJob
import com.pitchedapps.frost.utils.ARG_URL
@@ -140,12 +143,24 @@ class FrostWebActivity : WebOverlayActivityBase() {
}
/**
+ * Variant that forces a mobile user agent. This is largely internal,
+ * and is only necessary when we are launching from an existing [WebOverlayActivityBase]
+ */
+class WebOverlayMobileActivity : WebOverlayActivityBase(USER_AGENT_MOBILE_CONST)
+
+/**
+ * Variant that forces a desktop user agent. This is largely internal,
+ * and is only necessary when we are launching from an existing [WebOverlayActivityBase]
+ */
+class WebOverlayDesktopActivity : WebOverlayActivityBase(USER_AGENT_DESKTOP_CONST)
+
+/**
* Internal overlay for the app; this is tied with the main task and is singleTop as opposed to singleInstance
*/
class WebOverlayActivity : WebOverlayActivityBase()
@UseExperimental(ExperimentalCoroutinesApi::class)
-abstract class WebOverlayActivityBase : BaseActivity(),
+abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT) : BaseActivity(),
ActivityContract, FrostContentContainer,
VideoViewHolder, FileChooserContract by FileChooserDelegate() {
@@ -207,6 +222,7 @@ abstract class WebOverlayActivityBase : BaseActivity(),
}
with(web) {
+ userAgentString = userAgent
Prefs.prevId = Prefs.userId
val authDefer = BiometricUtils.authenticate(this@WebOverlayActivityBase)
launch {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
index 733349b7..8139bebc 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
@@ -37,10 +37,10 @@ const val FB_HOME_URL = "${FB_URL_BASE}home.php"
*/
// Default user agent
-private const val USER_AGENT_MOBILE_CONST =
+const val USER_AGENT_MOBILE_CONST =
"Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A3000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Mobile Safari/537.36"
// Desktop agent, for pages like messages
-private const val USER_AGENT_DESKTOP_CONST =
+const val USER_AGENT_DESKTOP_CONST =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Safari/537.36"
const val USER_AGENT = USER_AGENT_DESKTOP_CONST
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 c2f28a4b..e4aa5d45 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -57,6 +57,7 @@ import com.pitchedapps.frost.activities.SettingsActivity
import com.pitchedapps.frost.activities.TabCustomizerActivity
import com.pitchedapps.frost.activities.WebOverlayActivity
import com.pitchedapps.frost.activities.WebOverlayActivityBase
+import com.pitchedapps.frost.activities.WebOverlayMobileActivity
import com.pitchedapps.frost.db.CookieEntity
import com.pitchedapps.frost.facebook.FACEBOOK_COM
import com.pitchedapps.frost.facebook.FBCDN_NET
@@ -138,6 +139,12 @@ private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlay
fun Context.launchWebOverlay(url: String) = launchWebOverlayImpl<WebOverlayActivity>(url)
+// TODO Currently, default is overlay. Switch this if default changes
+fun Context.launchWebOverlayDesktop(url: String) = launchWebOverlay(url)
+
+fun Context.launchWebOverlayMobile(url: String) =
+ launchWebOverlayImpl<WebOverlayMobileActivity>(url)
+
private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation(
this,
android.R.anim.fade_in, android.R.anim.fade_out
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