From 3710e917b2be26a20b80099cf234af40e6ccab3f Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Tue, 7 Jan 2025 12:16:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/browser/WebViewActivity.kt | 3 +++ .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 3 +++ .../io/legado/app/utils/ActivityExtensions.kt | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt index 67f712a3634c..e222718c987c 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt @@ -43,6 +43,7 @@ import io.legado.app.utils.openUrl import io.legado.app.utils.sendToClip import io.legado.app.utils.setDarkeningAllowed import io.legado.app.utils.startActivity +import io.legado.app.utils.toggleNavigationBar import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.visible import java.net.URLDecoder @@ -239,6 +240,7 @@ class WebViewActivity : VMBaseActivity() { binding.customWebView.addView(view) customWebViewCallback = callback keepScreenOn(true) + toggleNavigationBar(false) } override fun onHideCustomView() { @@ -246,6 +248,7 @@ class WebViewActivity : VMBaseActivity() { binding.llView.visible() requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED keepScreenOn(false) + toggleNavigationBar(true) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 8748ca7c4d15..b033dae05d46 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -60,6 +60,7 @@ import io.legado.app.utils.splitNotBlank import io.legado.app.utils.startActivity import io.legado.app.utils.textArray import io.legado.app.utils.toastOnUi +import io.legado.app.utils.toggleNavigationBar import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.visible import kotlinx.coroutines.launch @@ -380,6 +381,7 @@ class ReadRssActivity : VMBaseActivity binding.customWebView.addView(view) customWebViewCallback = callback keepScreenOn(true) + toggleNavigationBar(false) } override fun onHideCustomView() { @@ -387,6 +389,7 @@ class ReadRssActivity : VMBaseActivity binding.llView.visible() requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED keepScreenOn(false) + toggleNavigationBar(true) } } diff --git a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt index 60eaecd1d439..72552b5b7142 100644 --- a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt @@ -16,6 +16,10 @@ import android.view.WindowMetrics import android.widget.FrameLayout import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.WindowCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_DEFAULT +import androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE import androidx.fragment.app.DialogFragment import io.legado.app.R import io.legado.app.ui.widget.dialog.TextDialog @@ -173,6 +177,18 @@ fun Activity.keepScreenOn(on: Boolean) { } } +fun Activity.toggleNavigationBar(show: Boolean) { + WindowCompat.getInsetsController(window, window.decorView).run { + if (show) { + show(WindowInsetsCompat.Type.navigationBars()) + systemBarsBehavior = BEHAVIOR_DEFAULT + } else { + hide(WindowInsetsCompat.Type.navigationBars()) + systemBarsBehavior = BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } + } +} + /////以下方法需要在View完全被绘制出来之后调用,否则判断不了,在比如 onWindowFocusChanged()方法中可以得到正确的结果///// /**