-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceDecoration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.legado.app.ui.book.source.manage | ||
|
||
import android.graphics.Canvas | ||
import android.graphics.Paint | ||
import android.graphics.Rect | ||
import android.text.TextPaint | ||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import io.legado.app.lib.theme.accentColor | ||
import io.legado.app.lib.theme.backgroundColor | ||
import io.legado.app.utils.dpToPx | ||
import io.legado.app.utils.spToPx | ||
import splitties.init.appCtx | ||
|
||
class BookSourceDecoration(val adapter: BookSourceAdapter): RecyclerView.ItemDecoration() { | ||
|
||
private val headerLeft = 16f.dpToPx() | ||
private val headerHeight = 32f.dpToPx() | ||
|
||
private val headerPaint = Paint().apply { | ||
color = appCtx.backgroundColor | ||
} | ||
private val textPaint = TextPaint().apply { | ||
textSize = 16f.spToPx() | ||
color = appCtx.accentColor | ||
isAntiAlias = true | ||
} | ||
private val textRect = Rect() | ||
|
||
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { | ||
val count = parent.childCount | ||
for (i in 0 until count) { | ||
val view = parent.getChildAt(i) | ||
val position = parent.getChildLayoutPosition(view) | ||
val isHeader = adapter.isItemHeader(position) | ||
if (isHeader) { | ||
c.drawRect( | ||
0f, | ||
view.top - headerHeight, | ||
parent.width.toFloat(), | ||
view.top.toFloat(), | ||
headerPaint | ||
) | ||
val headerText = adapter.getHeaderText(position) | ||
textPaint.getTextBounds(headerText, 0, headerText.length, textRect) | ||
c.drawText( | ||
headerText, | ||
headerLeft, | ||
(view.top - headerHeight) + headerHeight / 2 + textRect.height() / 2, | ||
textPaint | ||
) | ||
} | ||
} | ||
} | ||
|
||
override fun getItemOffsets( | ||
outRect: Rect, | ||
view: View, | ||
parent: RecyclerView, | ||
state: RecyclerView.State | ||
) { | ||
val position = parent.getChildLayoutPosition(view) | ||
val isHeader = adapter.isItemHeader(position) | ||
if (isHeader) { | ||
outRect.top = headerHeight.toInt() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="show_same_source">显示重复书源</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters