From e8c52e6ab127dae71d51b7b54c98bfd724568de3 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 13 Apr 2019 19:52:24 -0400 Subject: Update user agent (#1400) * Rename user agent and update chrome for desktop, resolves #1387 * Rename more basic to desktop * Apply spotless --- app/src/main/AndroidManifest.xml | 2 +- .../frost/activities/WebOverlayActivity.kt | 12 ++++++------ .../com/pitchedapps/frost/debugger/OfflineWebsite.kt | 4 ++-- .../kotlin/com/pitchedapps/frost/facebook/FbConst.kt | 8 ++++---- .../pitchedapps/frost/facebook/requests/FbRequest.kt | 4 ++-- .../kotlin/com/pitchedapps/frost/utils/Downloader.kt | 6 +++--- .../main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 8 ++++---- .../com/pitchedapps/frost/views/FrostWebView.kt | 10 +++++----- .../kotlin/com/pitchedapps/frost/web/DebugWebView.kt | 4 ++-- .../frost/web/FrostUrlOverlayValidator.kt | 20 ++++++++++---------- .../kotlin/com/pitchedapps/frost/web/LoginWebView.kt | 1 - docs/Changelog.md | 4 ++++ 12 files changed, 43 insertions(+), 40 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ad1fcbdc..5656860c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,7 +48,7 @@ android:launchMode="singleTop" android:theme="@style/FrostTheme.Overlay.Slide" /> >.withEmptyData(vararg key: String): List Context.launchWebOverlay fun Context.launchWebOverlay(url: String) = launchWebOverlayImpl(url) -fun Context.launchWebOverlayBasic(url: String) = launchWebOverlayImpl(url) +fun Context.launchWebOverlayDesktop(url: String) = launchWebOverlayImpl(url) private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation( this, @@ -393,7 +393,7 @@ fun frostJsoup(cookie: String?, url: String) = Jsoup.connect(url).run { if (cookie.isNullOrBlank()) this else cookie(FACEBOOK_COM, cookie) - }.userAgent(USER_AGENT_BASIC).get()!! + }.userAgent(USER_AGENT_DESKTOP).get()!! fun Element.first(vararg select: String): Element? { select.forEach { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt index 37b2234d..cc8e3fbc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -29,8 +29,8 @@ import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.facebook.FB_HOME_URL import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.facebook.USER_AGENT_BASIC -import com.pitchedapps.frost.facebook.USER_AGENT_FULL +import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP +import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE import com.pitchedapps.frost.fragments.WebFragment import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.frostDownload @@ -38,7 +38,7 @@ import com.pitchedapps.frost.web.FrostChromeClient import com.pitchedapps.frost.web.FrostJSI import com.pitchedapps.frost.web.FrostWebViewClient import com.pitchedapps.frost.web.NestedWebView -import com.pitchedapps.frost.web.shouldUseBasicAgent +import com.pitchedapps.frost.web.shouldUseDesktopAgent /** * Created by Allan Wang on 2017-05-29. @@ -66,8 +66,8 @@ class FrostWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") override fun bind(container: FrostContentContainer): View { userAgentString = - if (parent.baseEnum == FbItem.MESSAGES || parent.baseUrl.shouldUseBasicAgent) USER_AGENT_BASIC - else USER_AGENT_FULL + if (parent.baseEnum == FbItem.MESSAGES || parent.baseUrl.shouldUseDesktopAgent) USER_AGENT_DESKTOP + else USER_AGENT_MOBILE with(settings) { javaScriptEnabled = true mediaPlaybackRequiresUserGesture = false // TODO check if we need this diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt index e278db80..6511ef9f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt @@ -24,7 +24,7 @@ import android.util.AttributeSet import android.view.View import android.webkit.WebView import ca.allanwang.kau.utils.withAlpha -import com.pitchedapps.frost.facebook.USER_AGENT_FULL +import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L @@ -55,7 +55,7 @@ class DebugWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") private fun setupWebview() { settings.javaScriptEnabled = true - settings.userAgentString = USER_AGENT_FULL + settings.userAgentString = USER_AGENT_MOBILE setLayerType(View.LAYER_TYPE_HARDWARE, null) webViewClient = DebugClient() isDrawingCacheEnabled = true 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 24885fdf..81ade98f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt @@ -22,7 +22,7 @@ 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_BASIC +import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs @@ -32,7 +32,7 @@ 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.launchWebOverlayBasic +import com.pitchedapps.frost.utils.launchWebOverlayDesktop import com.pitchedapps.frost.views.FrostWebView /** @@ -76,15 +76,15 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean { if (!Prefs.overlayEnabled) return false if (context is WebOverlayActivityBase) { L.v { "Check web request from overlay" } - val shouldUseBasic = url.formattedFbUrl.shouldUseBasicAgent + val shouldUseDesktop = url.formattedFbUrl.shouldUseDesktopAgent //already overlay; manage user agent - if (userAgentString != USER_AGENT_BASIC && shouldUseBasic) { - L.i { "Switch to basic agent overlay" } - context.launchWebOverlayBasic(url) + if (userAgentString != USER_AGENT_DESKTOP && shouldUseDesktop) { + L.i { "Switch to desktop agent overlay" } + context.launchWebOverlayDesktop(url) return true } - if (userAgentString == USER_AGENT_BASIC && !shouldUseBasic) { - L.i { "Switch from basic agent" } + if (userAgentString == USER_AGENT_DESKTOP && !shouldUseDesktop) { + L.i { "Switch from desktop agent" } context.launchWebOverlay(url) return true } @@ -103,9 +103,9 @@ val messageWhitelist: Set = setOf(FbItem.MESSAGES, FbItem.CHAT, FbItem.FEED_MOST_RECENT, FbItem.FEED_TOP_STORIES) .mapTo(mutableSetOf(), FbItem::url) -val String.shouldUseBasicAgent: Boolean +val String.shouldUseDesktopAgent: Boolean get() = when { - contains("story.php") -> false // do not use basic for comment section + contains("story.php") -> false // do not use desktop for comment section contains("/events/") -> false // do not use for events (namely the map) contains("/messages") -> true // must use for messages else -> false // default to normal user agent diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index 1c300b03..c27385fc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -35,7 +35,6 @@ import com.pitchedapps.frost.facebook.FB_USER_MATCHER import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.injectors.CssHider -import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs diff --git a/docs/Changelog.md b/docs/Changelog.md index 78f796d6..7a6bbfab 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -2,6 +2,9 @@ ## v2.2.4 * Show top bar to allow sharing posts +* Fix unmuting videos when autoplay is enabled +* Add shortcut to toggle autoplay in settings > behaviour +* Update theme ## v2.2.3 * Add ability to hide stories @@ -9,6 +12,7 @@ * Apply notification keyword filter to title as well * Remove round icon settings as they are the default in Facebook * Update theme +* Update translations ## v2.2.2 * New marketplace shortcut -- cgit v1.2.3