mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-08 20:12:39 +01:00
Format fb urls before intent
This commit is contained in:
parent
2eacc8cb77
commit
de7b70da17
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.pitchedapps.frost.facebook
|
package com.pitchedapps.frost.facebook
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import com.pitchedapps.frost.utils.L
|
import com.pitchedapps.frost.utils.L
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
@ -28,6 +29,12 @@ import java.nio.charset.StandardCharsets
|
|||||||
inline val String.formattedFbUrl: String
|
inline val String.formattedFbUrl: String
|
||||||
get() = FbUrlFormatter(this).toString()
|
get() = FbUrlFormatter(this).toString()
|
||||||
|
|
||||||
|
inline val Uri.formattedFbUri: Uri
|
||||||
|
get() {
|
||||||
|
val url = toString()
|
||||||
|
return if (url.startsWith("http")) Uri.parse(url.formattedFbUrl) else this
|
||||||
|
}
|
||||||
|
|
||||||
class FbUrlFormatter(url: String) {
|
class FbUrlFormatter(url: String) {
|
||||||
private val queries = mutableMapOf<String, String>()
|
private val queries = mutableMapOf<String, String>()
|
||||||
private val cleaned: String
|
private val cleaned: String
|
||||||
@ -72,7 +79,10 @@ class FbUrlFormatter(url: String) {
|
|||||||
}
|
}
|
||||||
discardableQueries.forEach { queries.remove(it) }
|
discardableQueries.forEach { queries.remove(it) }
|
||||||
if (cleanedUrl.startsWith("/")) cleanedUrl = FB_URL_BASE + cleanedUrl.substring(1)
|
if (cleanedUrl.startsWith("/")) cleanedUrl = FB_URL_BASE + cleanedUrl.substring(1)
|
||||||
cleanedUrl = cleanedUrl.replaceFirst(".facebook.com//", ".facebook.com/") //sometimes we are given a bad url
|
cleanedUrl = cleanedUrl.replaceFirst(
|
||||||
|
".facebook.com//",
|
||||||
|
".facebook.com/"
|
||||||
|
) //sometimes we are given a bad url
|
||||||
L.v { "Formatted url from $url to $cleanedUrl" }
|
L.v { "Formatted url from $url to $cleanedUrl" }
|
||||||
return cleanedUrl
|
return cleanedUrl
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ import com.pitchedapps.frost.facebook.FbCookie
|
|||||||
import com.pitchedapps.frost.facebook.FbItem
|
import com.pitchedapps.frost.facebook.FbItem
|
||||||
import com.pitchedapps.frost.facebook.FbUrlFormatter.Companion.VIDEO_REDIRECT
|
import com.pitchedapps.frost.facebook.FbUrlFormatter.Companion.VIDEO_REDIRECT
|
||||||
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
||||||
|
import com.pitchedapps.frost.facebook.formattedFbUri
|
||||||
import com.pitchedapps.frost.facebook.formattedFbUrl
|
import com.pitchedapps.frost.facebook.formattedFbUrl
|
||||||
import com.pitchedapps.frost.injectors.CssAssets
|
import com.pitchedapps.frost.injectors.CssAssets
|
||||||
import com.pitchedapps.frost.injectors.JsAssets
|
import com.pitchedapps.frost.injectors.JsAssets
|
||||||
@ -270,9 +271,16 @@ fun Context.createPrivateMediaFile(extension: String) = createPrivateMediaFile("
|
|||||||
*/
|
*/
|
||||||
fun Context.resolveActivityForUri(uri: Uri): Boolean {
|
fun Context.resolveActivityForUri(uri: Uri): Boolean {
|
||||||
val url = uri.toString()
|
val url = uri.toString()
|
||||||
if (url.isFacebookUrl && !url.isExplicitIntent) return false
|
if (url.isFacebookUrl && !url.isExplicitIntent) {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
return false
|
||||||
if (intent.resolveActivity(packageManager) == null) return false
|
}
|
||||||
|
val intent = Intent(
|
||||||
|
Intent.ACTION_VIEW,
|
||||||
|
uri.formattedFbUri
|
||||||
|
)
|
||||||
|
if (intent.resolveActivity(packageManager) == null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,10 @@ import kotlinx.coroutines.channels.SendChannel
|
|||||||
*/
|
*/
|
||||||
open class BaseWebViewClient : WebViewClient() {
|
open class BaseWebViewClient : WebViewClient() {
|
||||||
|
|
||||||
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? =
|
override fun shouldInterceptRequest(
|
||||||
|
view: WebView,
|
||||||
|
request: WebResourceRequest
|
||||||
|
): WebResourceResponse? =
|
||||||
view.shouldFrostInterceptRequest(request)
|
view.shouldFrostInterceptRequest(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,12 +176,18 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() {
|
|||||||
view.context.resolveActivityForUri(request.url)
|
view.context.resolveActivityForUri(request.url)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (path.startsWith("/composer/")) return launchRequest(request)
|
if (path.startsWith("/composer/")) {
|
||||||
if (url.isImageUrl)
|
return launchRequest(request)
|
||||||
return launchImage(url.formattedFbUrl)
|
}
|
||||||
if (url.isIndirectImageUrl)
|
if (url.isIndirectImageUrl) {
|
||||||
return launchImage(url.formattedFbUrl, cookie = FbCookie.webCookie)
|
return launchImage(url.formattedFbUrl, cookie = FbCookie.webCookie)
|
||||||
if (Prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) return true
|
}
|
||||||
|
if (url.isImageUrl) {
|
||||||
|
return launchImage(url.formattedFbUrl)
|
||||||
|
}
|
||||||
|
if (Prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return super.shouldOverrideUrlLoading(view, request)
|
return super.shouldOverrideUrlLoading(view, request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user