From 2d502bcf17a57522393c89ea8167cb74b0d657f1 Mon Sep 17 00:00:00 2001 From: Fedir Tsapana Date: Tue, 2 May 2023 14:49:54 +0300 Subject: [PATCH] show toast when can not find app to open unknown link --- .../com/phlox/tvwebbrowser/activity/main/MainActivity.kt | 6 +++--- .../tvwebbrowser/webengine/{common => webview}/Scripts.kt | 2 +- .../com/phlox/tvwebbrowser/webengine/webview/WebViewEx.kt | 1 - .../tvwebbrowser/webengine/webview/WebViewWebEngine.kt | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 6 insertions(+), 5 deletions(-) rename app/src/main/java/com/phlox/tvwebbrowser/webengine/{common => webview}/Scripts.kt (88%) diff --git a/app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt b/app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt index fef32d2..21a69ef 100644 --- a/app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt +++ b/app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt @@ -49,7 +49,6 @@ import com.phlox.tvwebbrowser.utils.activemodel.ActiveModelsRepository import com.phlox.tvwebbrowser.webengine.WebEngine import com.phlox.tvwebbrowser.webengine.WebEngineFactory import com.phlox.tvwebbrowser.webengine.WebEngineWindowProviderCallback -import com.phlox.tvwebbrowser.webengine.common.Scripts import com.phlox.tvwebbrowser.webengine.gecko.GeckoWebEngine import com.phlox.tvwebbrowser.widgets.NotificationView import kotlinx.coroutines.* @@ -1153,6 +1152,9 @@ open class MainActivity : AppCompatActivity(), ActionBar.Callback { true } else { Log.d(TAG, "shouldOverrideUrlLoading: no activity to handle intent") + runOnUiThread { + Utils.showToast(applicationContext, getString(R.string.err_no_app_to_handle_url)) + } false } } catch (e: Exception) { @@ -1203,8 +1205,6 @@ open class MainActivity : AppCompatActivity(), ActionBar.Callback { } } } - - tab.webEngine.evaluateJavascript(Scripts.INITIAL_SCRIPT) } override fun onPageCertificateError(url: String?) { diff --git a/app/src/main/java/com/phlox/tvwebbrowser/webengine/common/Scripts.kt b/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/Scripts.kt similarity index 88% rename from app/src/main/java/com/phlox/tvwebbrowser/webengine/common/Scripts.kt rename to app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/Scripts.kt index 1fd0f16..876db52 100644 --- a/app/src/main/java/com/phlox/tvwebbrowser/webengine/common/Scripts.kt +++ b/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/Scripts.kt @@ -1,4 +1,4 @@ -package com.phlox.tvwebbrowser.webengine.common +package com.phlox.tvwebbrowser.webengine.webview object Scripts { val INITIAL_SCRIPT = """ diff --git a/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/WebViewEx.kt b/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/WebViewEx.kt index f2c2e5c..1a4066c 100644 --- a/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/WebViewEx.kt +++ b/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/WebViewEx.kt @@ -30,7 +30,6 @@ import com.phlox.tvwebbrowser.Config import com.phlox.tvwebbrowser.R import com.phlox.tvwebbrowser.TVBro import com.phlox.tvwebbrowser.utils.LogUtils -import com.phlox.tvwebbrowser.webengine.common.Scripts import java.net.URLEncoder import java.util.* diff --git a/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/WebViewWebEngine.kt b/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/WebViewWebEngine.kt index b9855f2..99ddcfb 100644 --- a/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/WebViewWebEngine.kt +++ b/app/src/main/java/com/phlox/tvwebbrowser/webengine/webview/WebViewWebEngine.kt @@ -265,6 +265,7 @@ class WebViewWebEngine(val tab: WebTabState) : WebEngine { override fun onPageFinished(url: String?) { callback?.onPageFinished(url) + evaluateJavascript(Scripts.INITIAL_SCRIPT) } override fun onPageCertificateError(url: String?) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 32ecea3..365f0bb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -196,4 +196,5 @@ Hello! TV Bro changes engine. All this time, TV Bro has been using the WebView system component to display web content. But this all the time led to various problems due to the fact that the WebView is updated independently and often has own bugs. Now TV Bro is changing the engine to GeckoView which can be built in so there will be no such problems. Unfortunately, the internal data format of these engines is not compatible, so the data of open sessions will be lost during the transition. Therefore, for some time TV Bro will still support both engines (you can switch in the settings).\n\nSo are you ready to use the GeckoView version or want to stay on the WebView for now? Yes, let\'s start using new engine No, use old one for now + Can not find suitable application to handle this URL