添加所有书签界面
This commit is contained in:
@@ -5,12 +5,14 @@ import android.graphics.Paint
|
|||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.text.TextPaint
|
import android.text.TextPaint
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import io.legado.app.lib.theme.accentColor
|
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.dpToPx
|
||||||
import io.legado.app.utils.spToPx
|
import io.legado.app.utils.spToPx
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class BookmarkDecoration(val adapter: BookmarkAdapter) : RecyclerView.ItemDecoration() {
|
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 headerHeight = 32f.dpToPx()
|
||||||
|
|
||||||
private val headerPaint = Paint().apply {
|
private val headerPaint = Paint().apply {
|
||||||
color = appCtx.primaryColor
|
color = appCtx.backgroundColor
|
||||||
}
|
}
|
||||||
private val textPaint = TextPaint().apply {
|
private val textPaint = TextPaint().apply {
|
||||||
textSize = 16f.spToPx()
|
textSize = 16f.spToPx()
|
||||||
@@ -52,45 +54,45 @@ class BookmarkDecoration(val adapter: BookmarkAdapter) : RecyclerView.ItemDecora
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
||||||
// val position = (parent.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
|
val position = (parent.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
|
||||||
// val view = parent.findViewHolderForAdapterPosition(position)?.itemView ?: return
|
val view = parent.findViewHolderForAdapterPosition(position)?.itemView ?: return
|
||||||
// val isHeader = adapter.isItemHeader(position + 1)
|
val isHeader = adapter.isItemHeader(position + 1)
|
||||||
// val headerText = adapter.getHeaderText(position)
|
val headerText = adapter.getHeaderText(position)
|
||||||
// if (isHeader) {
|
if (isHeader) {
|
||||||
// val bottom = min(headerHeight.toInt(), view.bottom)
|
val bottom = min(headerHeight.toInt(), view.bottom)
|
||||||
// c.drawRect(
|
c.drawRect(
|
||||||
// 0f,
|
0f,
|
||||||
// view.top.toFloat(),
|
view.top - headerHeight,
|
||||||
// parent.width.toFloat(),
|
parent.width.toFloat(),
|
||||||
// view.top + headerHeight,
|
bottom.toFloat(),
|
||||||
// headerPaint
|
headerPaint
|
||||||
// )
|
)
|
||||||
// textPaint.getTextBounds(headerText, 0, headerText.length, textRect)
|
textPaint.getTextBounds(headerText, 0, headerText.length, textRect)
|
||||||
// c.drawText(
|
c.drawText(
|
||||||
// headerText,
|
headerText,
|
||||||
// headerLeft,
|
headerLeft,
|
||||||
// headerHeight / 2 + textRect.height() / 2 - (headerHeight - bottom),
|
headerHeight / 2 + textRect.height() / 2 - (headerHeight - bottom),
|
||||||
// textPaint
|
textPaint
|
||||||
// )
|
)
|
||||||
// } else {
|
} else {
|
||||||
// c.drawRect(
|
c.drawRect(
|
||||||
// 0f,
|
0f,
|
||||||
// 0f,
|
0f,
|
||||||
// parent.width.toFloat(),
|
parent.width.toFloat(),
|
||||||
// headerHeight,
|
headerHeight,
|
||||||
// headerPaint
|
headerPaint
|
||||||
// )
|
)
|
||||||
// textPaint.getTextBounds(headerText, 0, headerText.length, textRect)
|
textPaint.getTextBounds(headerText, 0, headerText.length, textRect)
|
||||||
// c.drawText(
|
c.drawText(
|
||||||
// headerText,
|
headerText,
|
||||||
// headerLeft,
|
headerLeft,
|
||||||
// headerHeight / 2 + textRect.height() / 2,
|
headerHeight / 2 + textRect.height() / 2,
|
||||||
// textPaint
|
textPaint
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// c.save()
|
c.save()
|
||||||
// }
|
}
|
||||||
|
|
||||||
override fun getItemOffsets(
|
override fun getItemOffsets(
|
||||||
outRect: Rect,
|
outRect: Rect,
|
||||||
|
|||||||
Reference in New Issue
Block a user