修复详情页书籍简介下部分被裁剪,更新界面

This commit is contained in:
HapeLee
2025-09-06 14:45:38 +08:00
parent 56bd980834
commit 3e123ab73c
3 changed files with 131 additions and 83 deletions
@@ -160,9 +160,12 @@ class BookInfoActivity :
}
private var surfaceFinalColor: Int = 0
private var surfaceContainerFinalColor: Int = 0
private var secondaryFinalColor: Int = 0
private var onSurfaceFinalColor: Int = 0
private var secondaryContainerFinalColor: Int = 0
private var primaryFinalColor: Int = 0
private var tertiaryFinalColor: Int = 0
private var currentJob: Job? = null
private var wrappedContext: Context? = null
private var chapterChanged = false
@@ -190,17 +193,38 @@ class BookInfoActivity :
MaterialColors.getColor(this, com.google.android.material.R.attr.colorSecondary, -1)
onSurfaceFinalColor =
MaterialColors.getColor(this, com.google.android.material.R.attr.colorOnSurface, -1)
surfaceContainerFinalColor = MaterialColors.getColor(
this,
com.google.android.material.R.attr.colorSurfaceContainer,
-1
)
secondaryContainerFinalColor = MaterialColors.getColor(
this,
com.google.android.material.R.attr.colorSecondaryContainer,
-1
)
primaryFinalColor = MaterialColors.getColor(
this,
androidx.appcompat.R.attr.colorPrimary,
-1
)
tertiaryFinalColor = MaterialColors.getColor(
this,
com.google.android.material.R.attr.colorTertiary,
-1
)
binding.cdCov.transitionName = intent.getStringExtra("transitionName")
binding.cdCov.doOnPreDraw {
startPostponedEnterTransition()
}
setSupportActionBar(binding.topBar)
binding.llRead?.applyNavigationBarMargin()
binding.scrollView.setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
if (scrollY > oldScrollY) binding.btnRead.shrink()
else if (scrollY < oldScrollY) binding.btnRead.extend()
}
binding.btnRead.applyNavigationBarMargin()
binding.btnShelf.text = getString(R.string.remove_from_bookshelf)
binding.tvToc.text = getString(R.string.toc_s, getString(R.string.loading))
@@ -480,7 +504,8 @@ class BookInfoActivity :
private suspend fun applyColorScheme() {
val ctx = wrappedContext ?: this
val colorPrimary = MaterialColors.getColor(ctx, androidx.appcompat.R.attr.colorPrimary, -1)
val colorPrimary =
MaterialColors.getColor(ctx, androidx.appcompat.R.attr.colorPrimary, -1)
val colorSecondary =
MaterialColors.getColor(ctx, com.google.android.material.R.attr.colorSecondary, -1)
val colorTertiary =
@@ -489,16 +514,18 @@ class BookInfoActivity :
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.colorSurfaceContainerHighest,
-1
)
val colorSecondaryContainer =
MaterialColors.getColor(
ctx,
com.google.android.material.R.attr.colorSecondaryContainer,
-1
)
val surfaceTransition = ValueAnimator.ofArgb(surfaceFinalColor, colorSurface).apply {
duration = 400L
@@ -506,9 +533,21 @@ class BookInfoActivity :
val color = animation.animatedValue as Int
binding.cdInfo?.setCardBackgroundColor(color)
binding.llInfo.setBackgroundColor(color)
(binding.llCover.background as? GradientDrawable)?.colors =
intArrayOf(Color.TRANSPARENT, color)
}
}
val surfaceContainerTransition =
ValueAnimator.ofArgb(surfaceContainerFinalColor, colorSurfaceContainer).apply {
duration = 400L
addUpdateListener { animation ->
val color = animation.animatedValue as Int
binding.lbKind.applyColorScheme(color, colorOnSurface)
binding.collTopBar.setContentScrimColor(color)
}
}
val buttonTransition = ValueAnimator.ofArgb(secondaryFinalColor, colorSecondary).apply {
duration = 400L
addUpdateListener { animation ->
@@ -523,6 +562,8 @@ class BookInfoActivity :
btn.setTextColor(color)
btn.iconTint = tint
}
binding.div.setTextColor(color)
binding.tvChapterIndex.setTextColor(color)
}
}
@@ -543,33 +584,48 @@ class BookInfoActivity :
binding.tvAuthor.setTextColor(color)
binding.tvOrigin.setTextColor(color)
binding.tvDetail.setTextColor(color)
binding.tvToc.setTextColor(color)
binding.tvLasted.setTextColor(color)
binding.ivName.imageTintList = ColorStateList.valueOf(color)
binding.ivWeb.imageTintList = ColorStateList.valueOf(color)
}
}
val primaryTransition = ValueAnimator.ofArgb(primaryFinalColor, colorPrimary).apply {
duration = 400L
addUpdateListener { animation ->
val color = animation.animatedValue as Int
binding.tvChapter.setTextColor(color)
}
}
val tertiaryTransition = ValueAnimator.ofArgb(tertiaryFinalColor, colorTertiary).apply {
duration = 400L
addUpdateListener { animation ->
val color = animation.animatedValue as Int
binding.btnRead.setBackgroundColor(color)
}
}
withContext(Dispatchers.Main) {
surfaceTransition.start()
buttonTransition.start()
textTransition.start()
backTransition.start()
listOf(
surfaceTransition,
surfaceContainerTransition,
buttonTransition,
backTransition,
textTransition,
primaryTransition,
tertiaryTransition
).forEach { it.start() }
}
surfaceFinalColor = colorSurface
secondaryFinalColor = colorSecondary
onSurfaceFinalColor = colorOnSurface
(binding.llCover.background as? GradientDrawable)?.colors =
intArrayOf(Color.TRANSPARENT, colorSurface)
binding.collTopBar.setContentScrimColor(colorSurfaceContainer)
binding.lbKind.applyColorScheme(colorSurfaceContainer, colorOnSurface)
binding.tvChapter.setTextColor(colorPrimary)
binding.div.setTextColor(colorSecondary)
binding.tvChapterIndex.setTextColor(colorSecondary)
binding.btnRead.setBackgroundColor(colorTertiary)
binding.tvToc.setTextColor(colorOnSurface)
binding.tvLasted.setTextColor(colorOnSurface)
surfaceContainerFinalColor = colorSurfaceContainer
primaryFinalColor = colorPrimary
tertiaryFinalColor = colorTertiary
secondaryContainerFinalColor = colorSecondaryContainer
}
private fun upLoading(isLoading: Boolean, chapterList: List<BookChapter>? = null) {
@@ -38,7 +38,7 @@ class LabelsBar @JvmOverloads constructor(
chipEndPadding = 8f
chipStrokeWidth = 0f
chipBackgroundColor = ColorStateList.valueOf(
context.themeColor(com.google.android.material.R.attr.colorPrimaryContainer)
context.themeColor(com.google.android.material.R.attr.colorSurfaceContainerHighest)
)
usedChips.add(this)
}
+46 -54
View File
@@ -50,23 +50,21 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="false"
android:focusable="true"
android:padding="0dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
@@ -74,8 +72,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_gradient_mask"
android:paddingHorizontal="16dp"
android:paddingVertical="8dp"
android:paddingTop="8dp"
android:paddingBottom="4dp"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.card.MaterialCardView
@@ -83,11 +81,11 @@
android:layout_width="0dp"
android:layout_height="0dp"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="16dp"
app:layout_constraintDimensionRatio="5:7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.32"
app:layout_constraintWidth_percent="0.3"
app:strokeWidth="0dp">
<io.legato.kazusa.ui.widget.image.CoverImageView
@@ -105,6 +103,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_marginEnd="16dp"
android:padding="12dp"
app:layout_constraintBottom_toBottomOf="@id/cd_cov"
app:layout_constraintEnd_toEndOf="parent"
@@ -182,24 +181,15 @@
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll_info"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?attr/colorSurface"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/ll_cover">
<HorizontalScrollView
android:id="@+id/scroll_labels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:scrollbars="none"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/cd_cov">
<io.legato.kazusa.ui.widget.LabelsBar
android:id="@+id/lb_kind"
@@ -209,6 +199,17 @@
</HorizontalScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll_info"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="?attr/colorSurface"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/ll_cover">
<LinearLayout
android:id="@+id/cl_buttons"
android:layout_width="match_parent"
@@ -217,7 +218,7 @@
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="4"
app:layout_constraintTop_toBottomOf="@id/scroll_labels">
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_shelf"
@@ -287,8 +288,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:layout_marginTop="4dp"
android:textSize="17sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@@ -300,7 +301,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="8dp"
android:layout_marginTop="4dp"
android:singleLine="true"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
@@ -314,7 +315,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginTop="4dp"
android:singleLine="true"
android:textColor="?attr/colorPrimary"
android:textSize="14sp"
@@ -350,50 +351,41 @@
<TextView
android:id="@+id/tv_detail"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="8dp"
android:layout_marginTop="16dp"
android:paddingBottom="120dp"
android:clickable="true"
android:focusable="true"
android:lineSpacingExtra="4dp"
android:minHeight="48dp"
android:paddingBottom="120dp"
android:text="@string/book_intro"
android:textIsSelectable="true"
android:textSize="14sp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_chapter"
tools:text="@string/book_intro" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/ll_read"
android:layout_width="match_parent"
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/btn_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="end"
android:orientation="horizontal">
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/btn_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:contentDescription="@string/reading"
android:minWidth="56dp"
android:text="@string/reading"
android:textColor="?attr/colorOnPrimary"
app:backgroundTint="?attr/colorTertiary"
app:icon="@drawable/ic_bottom_books"
app:iconTint="?attr/colorOnPrimary" />
</LinearLayout>
android:layout_margin="16dp"
android:contentDescription="@string/reading"
android:minWidth="56dp"
android:text="@string/reading"
android:textColor="?attr/colorOnPrimary"
app:backgroundTint="?attr/colorTertiary"
app:icon="@drawable/ic_bottom_books"
app:iconTint="?attr/colorOnPrimary"
app:layout_anchor="@id/refresh_layout"
app:layout_anchorGravity="bottom|end" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>