From a5f888ba4a9a2fa18ad04f9f0d2715c8b6dd7ef2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 2 Apr 2022 16:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=80=E6=9C=89=E4=B9=A6?= =?UTF-8?q?=E7=AD=BE=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/bookmark/BookmarkDecoration.kt | 84 ++++++++++--------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/bookmark/BookmarkDecoration.kt b/app/src/main/java/io/legado/app/ui/book/bookmark/BookmarkDecoration.kt index 5ba594cf1..ed18041bf 100644 --- a/app/src/main/java/io/legado/app/ui/book/bookmark/BookmarkDecoration.kt +++ b/app/src/main/java/io/legado/app/ui/book/bookmark/BookmarkDecoration.kt @@ -5,12 +5,14 @@ import android.graphics.Paint import android.graphics.Rect import android.text.TextPaint import android.view.View +import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.lib.theme.accentColor -import io.legado.app.lib.theme.primaryColor +import io.legado.app.lib.theme.backgroundColor import io.legado.app.utils.dpToPx import io.legado.app.utils.spToPx import splitties.init.appCtx +import kotlin.math.min class BookmarkDecoration(val adapter: BookmarkAdapter) : RecyclerView.ItemDecoration() { @@ -18,7 +20,7 @@ class BookmarkDecoration(val adapter: BookmarkAdapter) : RecyclerView.ItemDecora private val headerHeight = 32f.dpToPx() private val headerPaint = Paint().apply { - color = appCtx.primaryColor + color = appCtx.backgroundColor } private val textPaint = TextPaint().apply { textSize = 16f.spToPx() @@ -52,45 +54,45 @@ class BookmarkDecoration(val adapter: BookmarkAdapter) : RecyclerView.ItemDecora } } -// override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { -// val position = (parent.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() -// val view = parent.findViewHolderForAdapterPosition(position)?.itemView ?: return -// val isHeader = adapter.isItemHeader(position + 1) -// val headerText = adapter.getHeaderText(position) -// if (isHeader) { -// val bottom = min(headerHeight.toInt(), view.bottom) -// c.drawRect( -// 0f, -// view.top.toFloat(), -// parent.width.toFloat(), -// view.top + headerHeight, -// headerPaint -// ) -// textPaint.getTextBounds(headerText, 0, headerText.length, textRect) -// c.drawText( -// headerText, -// headerLeft, -// headerHeight / 2 + textRect.height() / 2 - (headerHeight - bottom), -// textPaint -// ) -// } else { -// c.drawRect( -// 0f, -// 0f, -// parent.width.toFloat(), -// headerHeight, -// headerPaint -// ) -// textPaint.getTextBounds(headerText, 0, headerText.length, textRect) -// c.drawText( -// headerText, -// headerLeft, -// headerHeight / 2 + textRect.height() / 2, -// textPaint -// ) -// } -// c.save() -// } + override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { + val position = (parent.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() + val view = parent.findViewHolderForAdapterPosition(position)?.itemView ?: return + val isHeader = adapter.isItemHeader(position + 1) + val headerText = adapter.getHeaderText(position) + if (isHeader) { + val bottom = min(headerHeight.toInt(), view.bottom) + c.drawRect( + 0f, + view.top - headerHeight, + parent.width.toFloat(), + bottom.toFloat(), + headerPaint + ) + textPaint.getTextBounds(headerText, 0, headerText.length, textRect) + c.drawText( + headerText, + headerLeft, + headerHeight / 2 + textRect.height() / 2 - (headerHeight - bottom), + textPaint + ) + } else { + c.drawRect( + 0f, + 0f, + parent.width.toFloat(), + headerHeight, + headerPaint + ) + textPaint.getTextBounds(headerText, 0, headerText.length, textRect) + c.drawText( + headerText, + headerLeft, + headerHeight / 2 + textRect.height() / 2, + textPaint + ) + } + c.save() + } override fun getItemOffsets( outRect: Rect,