From 355d8ae26840d7c00faed2b9b1188b43c2a68377 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 25 Sep 2021 18:45:27 -0700 Subject: Remove resolveActivity --- app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 14 ++++++++------ .../com/pitchedapps/frost/web/FrostWebViewClients.kt | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'app/src/main') 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 4ba87209..896dd6aa 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -19,6 +19,7 @@ package com.pitchedapps.frost.utils import android.annotation.SuppressLint import android.app.Activity import android.app.ActivityOptions +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.graphics.Color @@ -135,7 +136,7 @@ private inline fun Context.launchWebOverlay ctxCoroutine.launch { fbCookie.logout(this@launchWebOverlayImpl, deleteCookie = false) } - } else if (!(prefs.linksInDefaultApp && resolveActivityForUri(Uri.parse(argUrl)))) { + } else if (!(prefs.linksInDefaultApp && startActivityForUri(Uri.parse(argUrl)))) { startActivity( false, intentBuilder = { @@ -308,7 +309,7 @@ fun Context.createPrivateMediaFile(extension: String) = createPrivateMediaFile(" * returns [true] if activity is resolved, [false] otherwise * For safety, any uri that [isFacebookUrl] without [isExplicitIntent] will return [false] */ -fun Context.resolveActivityForUri(uri: Uri): Boolean { +fun Context.startActivityForUri(uri: Uri): Boolean { val url = uri.toString() if (url.isFacebookUrl && !url.isExplicitIntent) { return false @@ -317,11 +318,12 @@ fun Context.resolveActivityForUri(uri: Uri): Boolean { Intent.ACTION_VIEW, uri.formattedFbUri ) - if (intent.resolveActivity(packageManager) == null) { - return false + return try { + startActivity(intent) + true + } catch (e: ActivityNotFoundException) { + false } - startActivity(intent) - return true } /** diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index 1495b2e0..a6603f01 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -50,7 +50,7 @@ import com.pitchedapps.frost.utils.isImageUrl import com.pitchedapps.frost.utils.isIndirectImageUrl import com.pitchedapps.frost.utils.isMessengerUrl import com.pitchedapps.frost.utils.launchImageActivity -import com.pitchedapps.frost.utils.resolveActivityForUri +import com.pitchedapps.frost.utils.startActivityForUri import com.pitchedapps.frost.views.FrostWebView import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.launch @@ -253,7 +253,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { v { "Url path $path" } val url = request.url.toString() if (url.isExplicitIntent) { - view.context.resolveActivityForUri(request.url) + view.context.startActivityForUri(request.url) return true } if (path.startsWith("/composer/")) { @@ -265,7 +265,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { if (url.isImageUrl) { return launchImage(url.formattedFbUrl) } - if (prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) { + if (prefs.linksInDefaultApp && view.context.startActivityForUri(request.url)) { return true } // Convert desktop urls to mobile ones -- cgit v1.2.3 From 749ebe31d0d23d7097a7c989a8324714aa28d996 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 28 Sep 2021 23:06:34 -0700 Subject: Remove laziness in blankResource --- app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt | 1 + .../main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt index 124a75df..c30ee199 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt @@ -175,6 +175,7 @@ abstract class FrostContentViewBase( } refreshChannel.subscribeDuringJob(scope, ContextHelper.coroutineContext) { r -> + L.v { "Refreshing $r" } refresh.isRefreshing = r } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt index 5586d479..defdcae1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt @@ -30,13 +30,12 @@ import java.io.ByteArrayInputStream * Handler to decide when a request should be done by us * This is the crux of Frost's optimizations for the web browser */ -private val blankResource: WebResourceResponse by lazy { +private val blankResource: WebResourceResponse = WebResourceResponse( "text/plain", "utf-8", ByteArrayInputStream("".toByteArray()) ) -} fun WebView.shouldFrostInterceptRequest(request: WebResourceRequest): WebResourceResponse? { val requestUrl = request.url?.toString() ?: return null -- cgit v1.2.3