pull/1395/head
gedoor 3 years ago
parent 65abc0c666
commit cffce34d1d
  1. 8
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 66
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  4. 58
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt

@ -160,11 +160,13 @@ abstract class BaseActivity<VB : ViewBinding>(
if (fullScreen && !isInMultiWindow) { if (fullScreen && !isInMultiWindow) {
ATH.fullScreen(this) ATH.fullScreen(this)
} }
ATH.setStatusBarColorAuto(this, fullScreen) val isTransparentStatusBar = AppConfig.isTransparentStatusBar
val statusBarColor = ThemeStore.statusBarColor(this, isTransparentStatusBar)
setStatusBarColorAuto(statusBarColor, isTransparentStatusBar, fullScreen)
if (toolBarTheme == Theme.Dark) { if (toolBarTheme == Theme.Dark) {
ATH.setLightStatusBar(this, false) setLightStatusBar(false)
} else if (toolBarTheme == Theme.Light) { } else if (toolBarTheme == Theme.Light) {
ATH.setLightStatusBar(this, true) setLightStatusBar(true)
} }
upNavigationBarColor() upNavigationBarColor()
} }

@ -4,11 +4,9 @@ import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.ActivityManager import android.app.ActivityManager
import android.content.Context import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.os.Build import android.os.Build
import android.view.View import android.view.View
import android.view.WindowInsetsController
import android.view.WindowManager import android.view.WindowManager
import android.widget.EdgeEffect import android.widget.EdgeEffect
import android.widget.ScrollView import android.widget.ScrollView
@ -16,11 +14,9 @@ import androidx.annotation.ColorInt
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.R
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dp
import io.legado.app.utils.getCompatColor
import splitties.init.appCtx import splitties.init.appCtx
/** /**
@ -55,68 +51,6 @@ object ATH {
) )
} }
fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) {
val isTransparentStatusBar = AppConfig.isTransparentStatusBar
val statusBarColor = ThemeStore.statusBarColor(activity, isTransparentStatusBar)
setStatusBarColor(activity, statusBarColor, isTransparentStatusBar, fullScreen)
}
fun setStatusBarColor(
activity: Activity,
color: Int,
isTransparentStatusBar: Boolean,
fullScreen: Boolean
) {
if (fullScreen) {
if (isTransparentStatusBar) {
activity.window.statusBarColor = Color.TRANSPARENT
} else {
activity.window.statusBarColor = activity.getCompatColor(R.color.status_bar_bag)
}
} else {
activity.window.statusBarColor = color
}
setLightStatusBarAuto(activity, color)
}
fun setLightStatusBarAuto(activity: Activity, bgColor: Int) {
setLightStatusBar(activity, ColorUtils.isColorLight(bgColor))
}
fun setLightStatusBar(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.window.insetsController?.let {
if (enabled) {
it.setSystemBarsAppearance(
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
} else {
it.setSystemBarsAppearance(
0,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
}
}
}
setLightStatusBarO(activity, enabled)
}
@Suppress("DEPRECATION")
private fun setLightStatusBarO(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val decorView = activity.window.decorView
val systemUiVisibility = decorView.systemUiVisibility
if (enabled) {
decorView.systemUiVisibility =
systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
decorView.systemUiVisibility =
systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
}
}
}
fun setTaskDescriptionColorAuto(activity: Activity) { fun setTaskDescriptionColorAuto(activity: Activity) {
setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity)) setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity))
} }

@ -21,7 +21,6 @@ import io.legado.app.help.LocalConfig
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
@ -105,12 +104,10 @@ abstract class ReadBookBaseActivity :
} }
upSystemUiVisibilityO(isInMultiWindow, toolBarHide) upSystemUiVisibilityO(isInMultiWindow, toolBarHide)
if (toolBarHide) { if (toolBarHide) {
ATH.setLightStatusBar(this, ReadBookConfig.durConfig.curStatusIconDark()) setLightStatusBar(ReadBookConfig.durConfig.curStatusIconDark())
} else { } else {
ATH.setLightStatusBarAuto( val statusBarColor = ThemeStore.statusBarColor(this, AppConfig.isTransparentStatusBar)
this, setLightStatusBar(ColorUtils.isColorLight(statusBarColor))
ThemeStore.statusBarColor(this, AppConfig.isTransparentStatusBar)
)
} }
} }

@ -1,6 +1,7 @@
package io.legado.app.utils package io.legado.app.utils
import android.app.Activity import android.app.Activity
import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
@ -9,6 +10,7 @@ import android.widget.FrameLayout
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.legado.app.R
inline fun <reified T : DialogFragment> AppCompatActivity.showDialogFragment( inline fun <reified T : DialogFragment> AppCompatActivity.showDialogFragment(
arguments: Bundle.() -> Unit = {} arguments: Bundle.() -> Unit = {}
@ -40,7 +42,60 @@ val Activity.windowSize: DisplayMetrics
return displayMetrics return displayMetrics
} }
@Suppress("DEPRECATION") /**
* 设置状态栏颜色
*/
fun Activity.setStatusBarColorAuto(
@ColorInt color: Int,
isTransparent: Boolean,
fullScreen: Boolean
) {
val isLightBar = ColorUtils.isColorLight(color)
if (fullScreen) {
if (isTransparent) {
window.statusBarColor = Color.TRANSPARENT
} else {
window.statusBarColor = getCompatColor(R.color.status_bar_bag)
}
} else {
window.statusBarColor = color
}
setLightStatusBar(isLightBar)
}
fun Activity.setLightStatusBar(isLightBar: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.let {
if (isLightBar) {
it.setSystemBarsAppearance(
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
} else {
it.setSystemBarsAppearance(
0,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
}
}
}
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val decorView = window.decorView
val systemUiVisibility = decorView.systemUiVisibility
if (isLightBar) {
decorView.systemUiVisibility =
systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
decorView.systemUiVisibility =
systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
}
}
}
/**
* 设置导航栏颜色
*/
fun Activity.setNavigationBarColorAuto(@ColorInt color: Int) { fun Activity.setNavigationBarColorAuto(@ColorInt color: Int) {
val isLightBor = ColorUtils.isColorLight(color) val isLightBor = ColorUtils.isColorLight(color)
window.navigationBarColor = color window.navigationBarColor = color
@ -59,6 +114,7 @@ fun Activity.setNavigationBarColorAuto(@ColorInt color: Int) {
} }
} }
} }
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val decorView = window.decorView val decorView = window.decorView
var systemUiVisibility = decorView.systemUiVisibility var systemUiVisibility = decorView.systemUiVisibility

Loading…
Cancel
Save