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 0fafab3b3..64dffaa2a 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 @@ -8,6 +8,7 @@ import android.graphics.Color import android.os.Build import android.view.View import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR +import android.view.Window import android.widget.EdgeEffect import android.widget.ScrollView import androidx.annotation.ColorInt @@ -15,6 +16,7 @@ import androidx.appcompat.app.AlertDialog import androidx.recyclerview.widget.RecyclerView import androidx.viewpager.widget.ViewPager import com.google.android.material.bottomnavigation.BottomNavigationView +import io.legado.app.App import io.legado.app.R import io.legado.app.utils.getCompatColor import io.legado.app.utils.isNightTheme @@ -36,36 +38,36 @@ object ATH { ) > since } - fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) { - val isTransparentStatusBar = activity.isTransparentStatusBar + fun setStatusBarColorAuto(window: Window, fullScreen: Boolean) { + val isTransparentStatusBar = App.INSTANCE.isTransparentStatusBar setStatusBarColor( - activity, - ThemeStore.statusBarColor(activity, isTransparentStatusBar), + window, + ThemeStore.statusBarColor(App.INSTANCE, isTransparentStatusBar), isTransparentStatusBar, fullScreen ) } fun setStatusBarColor( - activity: Activity, + window: Window, color: Int, isTransparentStatusBar: Boolean, fullScreen: Boolean ) { if (fullScreen && isTransparentStatusBar) { - activity.window.statusBarColor = Color.TRANSPARENT + window.statusBarColor = Color.TRANSPARENT } else { - activity.window.statusBarColor = color + window.statusBarColor = color } - setLightStatusBarAuto(activity, color) + setLightStatusBarAuto(window, color) } - fun setLightStatusBarAuto(activity: Activity, bgColor: Int) { - setLightStatusBar(activity, ColorUtils.isColorLight(bgColor)) + fun setLightStatusBarAuto(window: Window, bgColor: Int) { + setLightStatusBar(window, ColorUtils.isColorLight(bgColor)) } - fun setLightStatusBar(activity: Activity, enabled: Boolean) { + fun setLightStatusBar(window: Window, enabled: Boolean) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - val decorView = activity.window.decorView + val decorView = window.decorView val systemUiVisibility = decorView.systemUiVisibility if (enabled) { decorView.systemUiVisibility = 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 72d65da5f..1bc10c1db 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,6 +4,7 @@ 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 @@ -16,7 +17,7 @@ object Help { private const val NAVIGATION = "navigationBarBackground" - fun upSystemUiVisibility(activity: Activity, toolBarHide: Boolean = true) { + fun upSystemUiVisibility(window: Window, toolBarHide: Boolean = true) { var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_IMMERSIVE @@ -33,13 +34,13 @@ object Help { flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION } } - activity.window.decorView.systemUiVisibility = flag + window.decorView.systemUiVisibility = flag if (toolBarHide) { - ATH.setLightStatusBar(activity, ReadBookConfig.getConfig().statusIconDark()) + ATH.setLightStatusBar(window, ReadBookConfig.getConfig().statusIconDark()) } else { ATH.setLightStatusBarAuto( - activity, - ThemeStore.statusBarColor(activity, activity.isTransparentStatusBar) + window, + ThemeStore.statusBarColor(App.INSTANCE, App.INSTANCE.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 3e45d65d2..65417911c 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 @@ -437,7 +437,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } override fun upSystemUiVisibility() { - Help.upSystemUiVisibility(this, !read_menu.isVisible) + Help.upSystemUiVisibility(window, !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 98abc2dd2..80a3a93b4 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 @@ -55,10 +55,10 @@ class BgTextConfigDialog : DialogFragment() { super.onStart() val dm = DisplayMetrics() activity?.let { - Help.upSystemUiVisibility(it) it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { + Help.upSystemUiVisibility(it) it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) val attr = it.attributes @@ -103,7 +103,7 @@ class BgTextConfigDialog : DialogFragment() { sw_dark_status_icon.onCheckedChange { buttonView, isChecked -> if (buttonView?.isPressed == true) { setStatusIconDark(isChecked) - activity?.let { + activity?.window?.let { 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 3e1652645..a5c5e2980 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 @@ -31,10 +31,10 @@ class MoreConfigDialog : DialogFragment() { super.onStart() val dm = DisplayMetrics() activity?.let { - Help.upSystemUiVisibility(it) it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { + Help.upSystemUiVisibility(it) it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) val attr = it.attributes 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 779ba3dab..ac0c6eef7 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 @@ -29,10 +29,10 @@ class PaddingConfigDialog : DialogFragment() { super.onStart() val dm = DisplayMetrics() activity?.let { - Help.upSystemUiVisibility(it) it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { + Help.upSystemUiVisibility(it) it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) val attr = it.attributes 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 3922ee122..46f2dae92 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 @@ -34,10 +34,10 @@ class ReadAloudDialog : DialogFragment() { super.onStart() val dm = DisplayMetrics() activity?.let { - Help.upSystemUiVisibility(it) it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { + Help.upSystemUiVisibility(it) it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) val attr = it.attributes 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 15fa51590..dbe571869 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 @@ -46,10 +46,10 @@ class ReadStyleDialog : DialogFragment() { super.onStart() val dm = DisplayMetrics() activity?.let { - Help.upSystemUiVisibility(it) it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { + Help.upSystemUiVisibility(it) it.setBackgroundDrawableResource(R.color.transparent) it.decorView.setPadding(0, 0, 0, 0) val attr = it.attributes