pull/32/head
kunfei 5 years ago
parent e426e87753
commit 630ceb613f
  1. 31
      app/src/main/java/io/legado/app/ui/readbook/Help.kt
  2. 41
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt
  4. 19
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt
  5. 2
      app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt

@ -0,0 +1,31 @@
package io.legado.app.ui.readbook
import android.view.View
import android.view.Window
import io.legado.app.App
import io.legado.app.utils.getPrefBoolean
object Help {
fun upSystemUiVisibility(window: Window, hide: Boolean = true) {
var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
val hideNavigationBar = App.INSTANCE.getPrefBoolean("hideNavigationBar")
if (hideNavigationBar) {
flag =
flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
if (hide) {
if (App.INSTANCE.getPrefBoolean("hideStatusBar")) {
flag = flag or View.SYSTEM_UI_FLAG_FULLSCREEN
}
if (hideNavigationBar) {
flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}
}
window.decorView.systemUiVisibility = flag
}
}

@ -4,7 +4,10 @@ import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.*
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import io.legado.app.R
@ -61,9 +64,14 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
setScreenBrightness(getPrefInt("brightness", 100))
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
Help.upSystemUiVisibility(window, !read_menu.isVisible)
}
override fun onResume() {
super.onResume()
upBar()
Help.upSystemUiVisibility(window, !read_menu.isVisible)
timeElectricityReceiver = TimeElectricityReceiver.register(this)
}
@ -73,7 +81,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
unregisterReceiver(it)
timeElectricityReceiver = null
}
upBar()
Help.upSystemUiVisibility(window, !read_menu.isVisible)
}
private fun initView() {
@ -135,11 +143,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
override fun menuShow() {
upBar()
Help.upSystemUiVisibility(window, !read_menu.isVisible)
}
override fun menuHide() {
upBar()
Help.upSystemUiVisibility(window, !read_menu.isVisible)
}
})
}
@ -294,26 +302,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
window.attributes = params
}
private fun upBar() {
var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
if (getPrefBoolean("hideNavigationBar")) {
flag =
flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
if (!read_menu.isVisible) {
if (getPrefBoolean("hideStatusBar")) {
flag = flag or View.SYSTEM_UI_FLAG_FULLSCREEN
}
if (getPrefBoolean("hideNavigationBar")) {
flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}
}
window.decorView.systemUiVisibility = flag
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
@ -322,6 +310,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
}
override fun observeLiveBus() {
super.observeLiveBus()
observeEvent<Int>(Bus.ALOUD_STATE) { readAloudStatus = it }
@ -332,7 +321,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
observeEvent<BookChapter>(Bus.OPEN_CHAPTER) { viewModel.openChapter(it) }
observeEventSticky<Boolean>(Bus.READ_ALOUD) { onClickReadAloud() }
observeEvent<Boolean>(Bus.UP_CONFIG) {
upBar()
Help.upSystemUiVisibility(window, !read_menu.isVisible)
page_view.upBg()
content_view.upStyle()
page_view.upStyle()

@ -9,6 +9,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import io.legado.app.R
import io.legado.app.ui.readbook.Help
class MoreConfigDialog : DialogFragment() {
@ -38,6 +39,7 @@ class MoreConfigDialog : DialogFragment() {
attr.gravity = Gravity.BOTTOM
it.attributes = attr
it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
Help.upSystemUiVisibility(it)
}
}

@ -1,11 +1,14 @@
package io.legado.app.ui.readbook.config
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import io.legado.app.R
import io.legado.app.ui.readbook.Help
import kotlinx.android.synthetic.main.dialog_read_aloud.*
class ReadAloudDialog : DialogFragment() {
@ -23,6 +26,22 @@ class ReadAloudDialog : DialogFragment() {
initData()
}
override fun onStart() {
super.onStart()
val dm = DisplayMetrics()
activity?.windowManager?.defaultDisplay?.getMetrics(dm)
dialog?.window?.let {
it.setBackgroundDrawableResource(R.color.transparent)
it.decorView.setPadding(0, 0, 0, 0)
val attr = it.attributes
attr.dimAmount = 0.0f
attr.gravity = Gravity.BOTTOM
it.attributes = attr
it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
Help.upSystemUiVisibility(it)
}
}
private fun initData() {
seek_tts_SpeechRate.setProgress(0)

@ -13,6 +13,7 @@ import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.readbook.Help
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.dialog_read_book_style.*
import org.jetbrains.anko.sdk27.listeners.onClick
@ -41,6 +42,7 @@ class ReadStyleDialog : DialogFragment() {
attr.gravity = Gravity.BOTTOM
it.attributes = attr
it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
Help.upSystemUiVisibility(it)
}
}

Loading…
Cancel
Save