diff --git a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt index f7f749dd..1c5bf41b 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt @@ -928,8 +928,10 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), } } ToolbarAction.Home -> { - renderer.enqueueTask { - appCore.charEnter(CelestiaAction.Home.value) + hideOverlay { + renderer.enqueueTask { + appCore.charEnter(CelestiaAction.Home.value) + } } } ToolbarAction.Event -> { @@ -950,12 +952,16 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), ToolbarAction.NewsArchive -> { val baseURL = "https://celestia.mobi/resources/guides" val uri = Uri.parse(baseURL).buildUpon().appendQueryParameter("type", "news").appendQueryParameter("lang", AppCore.getLanguage()).build() - openURL(uri.toString()) + hideOverlay { + openURL(uri.toString()) + } } ToolbarAction.Download -> { val baseURL = "https://celestia.mobi/resources/categories" val uri = Uri.parse(baseURL).buildUpon().appendQueryParameter("lang", AppCore.getLanguage()).build() - openURL(uri.toString()) + hideOverlay { + openURL(uri.toString()) + } } } } diff --git a/app/src/main/java/space/celestia/mobilecelestia/resource/CommonWebFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/resource/CommonWebFragment.kt index f86971c9..231bbc14 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/resource/CommonWebFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/resource/CommonWebFragment.kt @@ -13,12 +13,14 @@ import android.view.ViewGroup import android.webkit.WebResourceRequest import android.webkit.WebView import android.webkit.WebViewClient +import android.widget.TextView import androidx.core.view.isVisible import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewFeature import com.google.android.material.progressindicator.CircularProgressIndicator import space.celestia.mobilecelestia.R import space.celestia.mobilecelestia.common.NavigationFragment +import space.celestia.mobilecelestia.utils.CelestiaString import java.io.File import java.lang.ref.WeakReference @@ -26,7 +28,6 @@ class CommonWebFragment: NavigationFragment.SubFragment(), CelestiaJavascriptInt private lateinit var uri: Uri private lateinit var matchingQueryKeys: List private var contextDirectory: File? = null - private lateinit var webView: WebView private var listener: Listener? = null @@ -50,9 +51,21 @@ class CommonWebFragment: NavigationFragment.SubFragment(), CelestiaJavascriptInt container: ViewGroup?, savedInstanceState: Bundle? ): View? { - val view = inflater.inflate(R.layout.fragment_common_web, container, false) + return try { + val view = inflater.inflate(R.layout.fragment_common_web, container, false) + configureWebView(view) + view + } catch (ignored: Throwable) { + val view = inflater.inflate(R.layout.layout_empty_hint, container, false) + val hint = view.findViewById(R.id.hint) + hint.text = CelestiaString("WebView is not available.", "") + view + } + } + + private fun configureWebView(view: View) { val loadingIndicator = view.findViewById(R.id.loading_indicator) - webView = view.findViewById(R.id.webview) + val webView = view.findViewById(R.id.webview) webView.setBackgroundColor(Color.TRANSPARENT) webView.isHorizontalScrollBarEnabled = false @@ -74,7 +87,7 @@ class CommonWebFragment: NavigationFragment.SubFragment(), CelestiaJavascriptInt return shouldOverrideUrl(request?.url.toString()) } - @SuppressWarnings("deprecation") + @Deprecated("Deprecated in Java") override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { return shouldOverrideUrl(url) } @@ -110,10 +123,8 @@ class CommonWebFragment: NavigationFragment.SubFragment(), CelestiaJavascriptInt } webView.loadUrl(uri.toString()) - return view } - override fun onAttach(context: Context) { super.onAttach(context) if (context is Listener) { diff --git a/app/src/main/res/layout/fragment_toolbar_list.xml b/app/src/main/res/layout/fragment_toolbar_list.xml index b9b3a080..5697d0cd 100644 --- a/app/src/main/res/layout/fragment_toolbar_list.xml +++ b/app/src/main/res/layout/fragment_toolbar_list.xml @@ -17,5 +17,4 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".toolbar.ToolbarFragment" - android:clickable="true" style="@style/SecondaryBackground" /> \ No newline at end of file diff --git a/app/src/main/res/layout/layout_empty_hint.xml b/app/src/main/res/layout/layout_empty_hint.xml new file mode 100644 index 00000000..cf189563 --- /dev/null +++ b/app/src/main/res/layout/layout_empty_hint.xml @@ -0,0 +1,24 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index a59589e4..8b0fa479 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -145,9 +145,10 @@ viewStart -