Skip to content

Commit

Permalink
Hide overlay before actions and add workaround for webview absent
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Apr 7, 2022
1 parent 155bec4 commit 5820928
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
14 changes: 10 additions & 4 deletions app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -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())
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ 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

class CommonWebFragment: NavigationFragment.SubFragment(), CelestiaJavascriptInterface.MessageHandler {
private lateinit var uri: Uri
private lateinit var matchingQueryKeys: List<String>
private var contextDirectory: File? = null
private lateinit var webView: WebView

private var listener: Listener? = null

Expand All @@ -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<TextView>(R.id.hint)
hint.text = CelestiaString("WebView is not available.", "")
view
}
}

private fun configureWebView(view: View) {
val loadingIndicator = view.findViewById<CircularProgressIndicator>(R.id.loading_indicator)
webView = view.findViewById(R.id.webview)
val webView = view.findViewById<WebView>(R.id.webview)
webView.setBackgroundColor(Color.TRANSPARENT)
webView.isHorizontalScrollBarEnabled = false

Expand All @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_toolbar_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".toolbar.ToolbarFragment"
android:clickable="true"
style="@style/SecondaryBackground" />
24 changes: 24 additions & 0 deletions app/src/main/res/layout/layout_empty_hint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ layout_empty_hint.xml
~
~ Copyright (C) 2001-2022, Celestia Development Team
~
~ This program is free software; you can redistribute it and/or
~ modify it under the terms of the GNU General Public License
~ as published by the Free Software Foundation; either version 2
~ of the License, or (at your option) any later version.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/Background">

<TextView
android:id="@+id/hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="@style/EmptyHint"/>
</FrameLayout>
7 changes: 4 additions & 3 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@
<item name="android:textAlignment">viewStart</item>
</style>

<style name="ResourceItemTitleLabel" parent="HeadlineLabel"/>

<style name="ResourceItemContentLabel" parent="BodyLabel"/>
<style name="EmptyHint" parent="PrimaryLabel">
<item name="android:textAppearance">@style/TextAppearance.Material3.LabelLarge</item>
<item name="android:textAlignment">center</item>
</style>

<style name="TextInputLayout" parent="Widget.Material3.TextInputLayout.OutlinedBox">
</style>
Expand Down

0 comments on commit 5820928

Please sign in to comment.