Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jan 7, 2025
1 parent 7b130dd commit 3710e91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -239,13 +240,15 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
binding.customWebView.addView(view)
customWebViewCallback = callback
keepScreenOn(true)
toggleNavigationBar(false)
}

override fun onHideCustomView() {
binding.customWebView.removeAllViews()
binding.llView.visible()
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
keepScreenOn(false)
toggleNavigationBar(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -380,13 +381,15 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
binding.customWebView.addView(view)
customWebViewCallback = callback
keepScreenOn(true)
toggleNavigationBar(false)
}

override fun onHideCustomView() {
binding.customWebView.removeAllViews()
binding.llView.visible()
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
keepScreenOn(false)
toggleNavigationBar(true)
}
}

Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/io/legado/app/utils/ActivityExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()方法中可以得到正确的结果/////

/**
Expand Down

0 comments on commit 3710e91

Please sign in to comment.