优化界面显示

This commit is contained in:
HapeLee
2025-09-07 02:40:46 +08:00
parent 3e123ab73c
commit 66fefe1253
9 changed files with 107 additions and 65 deletions
@@ -51,6 +51,7 @@ import io.legato.kazusa.ui.book.source.edit.BookSourceEditActivity
import io.legato.kazusa.ui.book.toc.TocActivityResult
import io.legato.kazusa.ui.login.SourceLoginActivity
import io.legato.kazusa.utils.StartActivityContract
import io.legato.kazusa.utils.ToolbarUtils.setAllIconsColor
import io.legato.kazusa.utils.applyNavigationBarPadding
import io.legato.kazusa.utils.gone
import io.legato.kazusa.utils.observeEvent
@@ -437,16 +438,24 @@ class AudioPlayActivity :
MaterialColors.getColor(ctx, com.google.android.material.R.attr.colorOnSurface, -1)
val colorSurface =
MaterialColors.getColor(ctx, com.google.android.material.R.attr.colorSurface, -1)
val colorSurfaceContainer = MaterialColors.getColor(
ctx,
com.google.android.material.R.attr.colorSurfaceContainer,
-1
)
val colorSecondaryContainer = MaterialColors.getColor(
ctx,
com.google.android.material.R.attr.colorSecondaryContainer,
-1
)
val colorSurfaceContainer =
MaterialColors.getColor(
ctx,
com.google.android.material.R.attr.colorSurfaceContainer,
-1
)
val colorSecondaryContainer =
MaterialColors.getColor(
ctx,
com.google.android.material.R.attr.colorSecondaryContainer,
-1
)
val colorOnSurfaceVariant =
MaterialColors.getColor(
ctx,
com.google.android.material.R.attr.colorOnSurfaceVariant,
-1
)
val primaryTransition = ValueAnimator.ofArgb(primaryFinalColor, colorPrimary).apply {
duration = 400L
@@ -456,6 +465,8 @@ class AudioPlayActivity :
binding.settingSlider.trackActiveTintList = ColorStateList.valueOf(color)
binding.playerProgress.thumbTintList = ColorStateList.valueOf(color)
binding.playerProgress.trackActiveTintList = ColorStateList.valueOf(color)
binding.tvDurTime.setTextColor(color)
binding.tvAllTime.setTextColor(color)
}
}
@@ -477,8 +488,6 @@ class AudioPlayActivity :
addUpdateListener { animation ->
val color = animation.animatedValue as Int
binding.vwBg2.setBackgroundColor(color)
binding.cdTimer.setBackgroundColor(color)
binding.cdSpeed.setBackgroundColor(color)
}
}
@@ -486,12 +495,7 @@ class AudioPlayActivity :
duration = 400L
addUpdateListener { animation ->
val color = animation.animatedValue as Int
binding.tvSpeed.setTextColor(color)
binding.tvTimer.setTextColor(color)
binding.tvTitle.setTextColor(color)
binding.tvDurTime.setTextColor(color)
binding.tvAllTime.setTextColor(color)
binding.tvSubTitle.setTextColor(color)
}
}
@@ -508,7 +512,18 @@ class AudioPlayActivity :
primaryFinalColor = colorPrimary
secondaryContainerFinalColor = colorSecondaryContainer
binding.titleBar.toolbar.setAllIconsColor(colorOnSurface)
binding.progressLoading.setIndicatorColor(colorPrimary)
binding.settingSlider.tickActiveTintList = ColorStateList.valueOf(colorSurface)
binding.settingSlider.tickInactiveTintList = ColorStateList.valueOf(colorPrimary)
binding.tvSubTitle.setTextColor(colorOnSurfaceVariant)
binding.btnTimer.imageTintList = ColorStateList.valueOf(colorOnSurface)
binding.tvSpeed.setTextColor(colorOnSurface)
binding.tvTimer.setTextColor(colorOnSurface)
binding.cdTimer.setCardBackgroundColor(colorSurfaceContainer)
binding.cdSpeed.setCardBackgroundColor(colorSurfaceContainer)
val states = arrayOf(
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked),
@@ -74,6 +74,7 @@ import io.legato.kazusa.utils.ConvertUtils
import io.legato.kazusa.utils.FileDoc
import io.legato.kazusa.utils.GSON
import io.legato.kazusa.utils.StartActivityContract
import io.legato.kazusa.utils.ToolbarUtils.setAllIconsColor
import io.legato.kazusa.utils.applyNavigationBarMargin
import io.legato.kazusa.utils.dpToPx
import io.legato.kazusa.utils.gone
@@ -224,7 +225,7 @@ class BookInfoActivity :
else if (scrollY < oldScrollY) binding.btnRead.extend()
}
binding.btnRead.applyNavigationBarMargin()
binding.btnRead.applyNavigationBarMargin(true)
binding.btnShelf.text = getString(R.string.remove_from_bookshelf)
binding.tvToc.text = getString(R.string.toc_s, getString(R.string.loading))
@@ -526,6 +527,8 @@ class BookInfoActivity :
com.google.android.material.R.attr.colorSecondaryContainer,
-1
)
val colorOnTertiary =
MaterialColors.getColor(ctx, com.google.android.material.R.attr.colorOnTertiary, -1)
val surfaceTransition = ValueAnimator.ofArgb(surfaceFinalColor, colorSurface).apply {
duration = 400L
@@ -626,6 +629,10 @@ class BookInfoActivity :
primaryFinalColor = colorPrimary
tertiaryFinalColor = colorTertiary
secondaryContainerFinalColor = colorSecondaryContainer
binding.topBar.setAllIconsColor(colorOnSurface)
binding.btnRead.setTextColor(colorOnTertiary)
binding.btnRead.iconTint = ColorStateList.valueOf(colorOnTertiary)
}
private fun upLoading(isLoading: Boolean, chapterList: List<BookChapter>? = null) {
@@ -52,14 +52,14 @@ class LabelsBar @JvmOverloads constructor(
addView(chip)
}
fun applyColorScheme(colorPrimaryContainer: Int, colorOnPrimaryContainer: Int) {
fun applyColorScheme(backgroundColor: Int, textColor: Int) {
usedChips.forEach { chip ->
chip.chipBackgroundColor = ColorStateList.valueOf(colorPrimaryContainer)
chip.setTextColor(colorOnPrimaryContainer)
chip.chipBackgroundColor = ColorStateList.valueOf(backgroundColor)
chip.setTextColor(textColor)
}
unUsedChips.forEach { chip ->
chip.chipBackgroundColor = ColorStateList.valueOf(colorPrimaryContainer)
chip.setTextColor(colorOnPrimaryContainer)
chip.chipBackgroundColor = ColorStateList.valueOf(backgroundColor)
chip.setTextColor(textColor)
}
}
@@ -5,12 +5,10 @@ import android.content.res.ColorStateList
import android.util.AttributeSet
import android.view.Menu
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.core.view.WindowInsetsCompat
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.MaterialToolbar
import io.legato.kazusa.R
import io.legato.kazusa.help.config.AppConfig
//import io.legado.app.lib.theme.primaryColor
import io.legato.kazusa.utils.activity
import io.legato.kazusa.utils.setOnApplyWindowInsetsListenerCompat
import splitties.views.bottomPadding
@@ -22,7 +20,7 @@ class TitleBar @JvmOverloads constructor(
attrs: AttributeSet? = null
) : AppBarLayout(context, attrs) {
val toolbar: Toolbar
val toolbar: MaterialToolbar
val menu: Menu
get() = toolbar.menu
@@ -1,23 +0,0 @@
@file:Suppress("unused")
package io.legato.kazusa.utils
import android.annotation.SuppressLint
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Build
import android.widget.Toolbar
import androidx.core.content.ContextCompat
import io.legato.kazusa.R
/**
* 设置toolBar更多图标颜色
*/
@SuppressLint("ObsoleteSdkInt")
fun Toolbar.setMoreIconColor(color: Int) {
val moreIcon = ContextCompat.getDrawable(context, R.drawable.ic_more)
if (moreIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
moreIcon.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
overflowIcon = moreIcon
}
}
@@ -0,0 +1,37 @@
package io.legato.kazusa.utils
import android.annotation.SuppressLint
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Build
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.core.view.get
import androidx.core.view.size
import com.google.android.material.appbar.MaterialToolbar
import io.legato.kazusa.R
object ToolbarUtils {
@JvmStatic
fun MaterialToolbar.setAllIconsColor(@ColorInt color: Int) {
// 导航图标
navigationIcon?.setTint(color)
// 溢出图标
overflowIcon = overflowIcon?.apply { setTint(color) }
// 菜单项图标
for (i in 0 until menu.size) {
menu[i].icon?.setTint(color)
}
}
@SuppressLint("ObsoleteSdkInt")
fun MaterialToolbar.setMoreIconColor(color: Int) {
val moreIcon = ContextCompat.getDrawable(context, R.drawable.ic_more)
if (moreIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
moreIcon.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
overflowIcon = moreIcon
}
}
}
@@ -28,11 +28,13 @@ import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuPopupHelper
import androidx.appcompat.widget.PopupMenu
import androidx.core.graphics.createBitmap
import androidx.core.graphics.record
import androidx.core.graphics.withTranslation
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.core.view.marginBottom
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.RecyclerView
@@ -146,7 +148,7 @@ fun View.visible() {
fun View.visible(visible: Boolean) {
if (visible && visibility != VISIBLE) {
visibility = VISIBLE
} else if (!visible && visibility == VISIBLE) {
} else if (!visible && isVisible) {
visibility = INVISIBLE
}
}
@@ -158,7 +160,7 @@ fun View.screenshot(bitmap: Bitmap? = null, canvas: Canvas? = null): Bitmap? {
bitmap
} else {
bitmap?.recycle()
Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
createBitmap(width, height)
}
val c = canvas ?: Canvas()
c.setBitmap(screenshot)
@@ -302,8 +304,8 @@ fun View.canScroll(direction: Int): Boolean {
return canScrollVertically(direction) || canScrollHorizontally(direction)
}
private val requestLayoutBroken = false
|| Build.VERSION.SDK_INT in Build.VERSION_CODES.O..Build.VERSION_CODES.Q
private val requestLayoutBroken =
Build.VERSION.SDK_INT in Build.VERSION_CODES.O..Build.VERSION_CODES.Q
fun View.setOnApplyWindowInsetsListenerCompat(listener: (View, WindowInsetsCompat) -> WindowInsetsCompat) {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->