Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jan 6, 2025
1 parent 5209aef commit 7b130dd
Show file tree
Hide file tree
Showing 3 changed files with 17 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 @@ -37,6 +37,7 @@ import io.legado.app.ui.file.HandleFileContract
import io.legado.app.utils.ACache
import io.legado.app.utils.gone
import io.legado.app.utils.invisible
import io.legado.app.utils.keepScreenOn
import io.legado.app.utils.longSnackbar
import io.legado.app.utils.openUrl
import io.legado.app.utils.sendToClip
Expand Down Expand Up @@ -237,12 +238,14 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
binding.llView.invisible()
binding.customWebView.addView(view)
customWebViewCallback = callback
keepScreenOn(true)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import io.legado.app.utils.get
import io.legado.app.utils.gone
import io.legado.app.utils.invisible
import io.legado.app.utils.isTrue
import io.legado.app.utils.keepScreenOn
import io.legado.app.utils.longSnackbar
import io.legado.app.utils.openUrl
import io.legado.app.utils.setDarkeningAllowed
Expand Down Expand Up @@ -378,12 +379,14 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
binding.llView.invisible()
binding.customWebView.addView(view)
customWebViewCallback = callback
keepScreenOn(true)
}

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

Expand Down
11 changes: 11 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 @@ -162,6 +162,17 @@ fun Activity.setNavigationBarColorAuto(@ColorInt color: Int) {
}
}

fun Activity.keepScreenOn(on: Boolean) {
val isScreenOn =
(window.attributes.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0
if (on == isScreenOn) return
if (on) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}

/////以下方法需要在View完全被绘制出来之后调用,否则判断不了,在比如 onWindowFocusChanged()方法中可以得到正确的结果/////

/**
Expand Down

0 comments on commit 7b130dd

Please sign in to comment.