diff --git a/app/src/main/java/io/legado/app/ui/readbook/Help.kt b/app/src/main/java/io/legado/app/ui/readbook/Help.kt new file mode 100644 index 000000000..3f5a4cd2f --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/readbook/Help.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 + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 10b8e2ac1..18dde4e00 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -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(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(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(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(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(R.layout.activity_rea } } } + override fun observeLiveBus() { super.observeLiveBus() observeEvent(Bus.ALOUD_STATE) { readAloudStatus = it } @@ -332,7 +321,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea observeEvent(Bus.OPEN_CHAPTER) { viewModel.openChapter(it) } observeEventSticky(Bus.READ_ALOUD) { onClickReadAloud() } observeEvent(Bus.UP_CONFIG) { - upBar() + Help.upSystemUiVisibility(window, !read_menu.isVisible) page_view.upBg() content_view.upStyle() page_view.upStyle() diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt index 4e9676a1a..02dff931e 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt index 945ccc251..dde061329 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt index 530fa4a8a..f3f81f433 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt @@ -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) } }