From a137fcb03637960dfecd6776437f8040251371f0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 7 Sep 2019 17:59:09 +0800 Subject: [PATCH] up --- .../java/io/legado/app/base/BaseActivity.kt | 2 +- .../main/java/io/legado/app/lib/theme/ATH.kt | 28 +++++++++---------- .../java/io/legado/app/ui/readbook/Help.kt | 19 ++++++++++--- .../app/ui/readbook/ReadBookActivity.kt | 2 +- .../ui/readbook/config/BgTextConfigDialog.kt | 6 ++-- .../ui/readbook/config/MoreConfigDialog.kt | 6 ++-- .../ui/readbook/config/PaddingConfigDialog.kt | 6 ++-- .../app/ui/readbook/config/ReadAloudDialog.kt | 6 ++-- .../app/ui/readbook/config/ReadStyleDialog.kt | 6 ++-- 9 files changed, 51 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 094ec93c0..c02f4731a 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -85,7 +85,7 @@ abstract class BaseActivity(private val layoutID: Int, private val fullScreen: B window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE } - ATH.setStatusbarColorAuto(this, fullScreen) + ATH.setStatusBarColorAuto(this, fullScreen) } open fun observeLiveBus() { diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index 53de3a488..a09750b2a 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -35,16 +35,16 @@ object ATH { ) > since } - fun setStatusbarColorAuto(activity: Activity, fullScreen: Boolean) { + fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) { val isTransparentStatusBar = activity.isTransparentStatusBar - setStatusbarColor( + setStatusBarColor( activity, ThemeStore.statusBarColor(activity, isTransparentStatusBar), isTransparentStatusBar, fullScreen ) } - fun setStatusbarColor( + fun setStatusBarColor( activity: Activity, color: Int, isTransparentStatusBar: Boolean, @@ -55,14 +55,14 @@ object ATH { } else { activity.window.statusBarColor = color } - setLightStatusbarAuto(activity, color) + setLightStatusBarAuto(activity, color) } - fun setLightStatusbarAuto(activity: Activity, bgColor: Int) { - setLightStatusbar(activity, ColorUtils.isColorLight(bgColor)) + fun setLightStatusBarAuto(activity: Activity, bgColor: Int) { + setLightStatusBar(activity, ColorUtils.isColorLight(bgColor)) } - fun setLightStatusbar(activity: Activity, enabled: Boolean) { + fun setLightStatusBar(activity: Activity, enabled: Boolean) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val decorView = activity.window.decorView val systemUiVisibility = decorView.systemUiVisibility @@ -74,7 +74,7 @@ object ATH { } } - fun setLightNavigationbar(activity: Activity, enabled: Boolean) { + fun setLightNavigationBar(activity: Activity, enabled: Boolean) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val decorView = activity.window.decorView var systemUiVisibility = decorView.systemUiVisibility @@ -87,18 +87,18 @@ object ATH { } } - fun setLightNavigationbarAuto(activity: Activity, bgColor: Int) { - setLightNavigationbar(activity, ColorUtils.isColorLight(bgColor)) + fun setLightNavigationBarAuto(activity: Activity, bgColor: Int) { + setLightNavigationBar(activity, ColorUtils.isColorLight(bgColor)) } - fun setNavigationbarColorAuto(activity: Activity) { - setNavigationbarColor(activity, ThemeStore.navigationBarColor(activity)) + fun setNavigationBarColorAuto(activity: Activity) { + setNavigationBarColor(activity, ThemeStore.navigationBarColor(activity)) } - fun setNavigationbarColor(activity: Activity, color: Int) { + fun setNavigationBarColor(activity: Activity, color: Int) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { activity.window.navigationBarColor = color - setLightNavigationbarAuto(activity, color) + setLightNavigationBarAuto(activity, color) } } 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 index 2828c9f05..eaf448006 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/Help.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/Help.kt @@ -4,16 +4,19 @@ import android.app.Activity import android.view.View import android.view.View.NO_ID import android.view.ViewGroup -import android.view.Window import io.legado.app.App +import io.legado.app.help.ReadBookConfig +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.getPrefBoolean +import io.legado.app.utils.isTransparentStatusBar object Help { private const val NAVIGATION = "navigationBarBackground" - fun upSystemUiVisibility(window: Window, hide: Boolean = true) { + fun upSystemUiVisibility(activity: Activity, toolBarHide: Boolean = true) { var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_IMMERSIVE @@ -22,7 +25,7 @@ object Help { if (hideNavigationBar) { flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION } - if (hide) { + if (toolBarHide) { if (App.INSTANCE.getPrefBoolean("hideStatusBar")) { flag = flag or View.SYSTEM_UI_FLAG_FULLSCREEN } @@ -30,7 +33,15 @@ object Help { flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION } } - window.decorView.systemUiVisibility = flag + activity.window.decorView.systemUiVisibility = flag + if (toolBarHide) { + ATH.setLightStatusBar(activity, ReadBookConfig.getConfig().statusIconDark()) + } else { + ATH.setLightStatusBarAuto( + activity, + ThemeStore.statusBarColor(activity, activity.isTransparentStatusBar) + ) + } } /** 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 8cbab8ce6..19fd69675 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 @@ -427,7 +427,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } override fun upSystemUiVisibility() { - Help.upSystemUiVisibility(window, !read_menu.isVisible) + Help.upSystemUiVisibility(this, !read_menu.isVisible) } /** diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt index 9ecde4b0e..529654ae2 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt @@ -54,7 +54,10 @@ class BgTextConfigDialog : DialogFragment() { override fun onStart() { super.onStart() val dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) + activity?.let { + Help.upSystemUiVisibility(it) + it.windowManager?.defaultDisplay?.getMetrics(dm) + } dialog?.window?.let { it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) @@ -63,7 +66,6 @@ class BgTextConfigDialog : 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/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt index 02dff931e..3e1652645 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 @@ -30,7 +30,10 @@ class MoreConfigDialog : DialogFragment() { override fun onStart() { super.onStart() val dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) + activity?.let { + Help.upSystemUiVisibility(it) + it.windowManager?.defaultDisplay?.getMetrics(dm) + } dialog?.window?.let { it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) @@ -39,7 +42,6 @@ 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/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt index a814ef6d0..779ba3dab 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt @@ -28,7 +28,10 @@ class PaddingConfigDialog : DialogFragment() { override fun onStart() { super.onStart() val dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) + activity?.let { + Help.upSystemUiVisibility(it) + it.windowManager?.defaultDisplay?.getMetrics(dm) + } dialog?.window?.let { it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) @@ -36,7 +39,6 @@ class PaddingConfigDialog : DialogFragment() { attr.dimAmount = 0.0f it.attributes = attr it.setLayout((dm.widthPixels * 0.9).toInt(), 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 62f7829aa..3922ee122 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 @@ -33,7 +33,10 @@ class ReadAloudDialog : DialogFragment() { override fun onStart() { super.onStart() val dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) + activity?.let { + Help.upSystemUiVisibility(it) + it.windowManager?.defaultDisplay?.getMetrics(dm) + } dialog?.window?.let { it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) @@ -42,7 +45,6 @@ class ReadAloudDialog : 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/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt index a36693ddc..15fa51590 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 @@ -45,7 +45,10 @@ class ReadStyleDialog : DialogFragment() { override fun onStart() { super.onStart() val dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) + activity?.let { + Help.upSystemUiVisibility(it) + it.windowManager?.defaultDisplay?.getMetrics(dm) + } dialog?.window?.let { it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) @@ -54,7 +57,6 @@ class ReadStyleDialog : DialogFragment() { attr.gravity = Gravity.BOTTOM it.attributes = attr it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - Help.upSystemUiVisibility(it) } }