This commit is contained in:
Horis 2024-12-21 20:52:32 +08:00
parent 407c6a964c
commit 48b93a05b1
4 changed files with 43 additions and 93 deletions

View File

@ -19,7 +19,6 @@ import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
@ -106,9 +105,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private set
private var snackBar: Snackbar? = null
private var showDuplicationSource = false
private val bookSourceDecoration by lazy {
BookSourceDecoration(adapter)
}
private val hostMap = hashMapOf<String, String>()
private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
@ -274,7 +270,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
R.id.menu_show_same_source -> {
item.isChecked = !item.isChecked
toggleDuplicationSourceView(item.isChecked)
showDuplicationSource = item.isChecked
adapter.showSourceHost = item.isChecked
upBookSource(searchView.query?.toString())
}
R.id.menu_help -> showHelp("SourceMBookHelp")
@ -685,21 +683,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
private fun toggleDuplicationSourceView(enable: Boolean) {
showDuplicationSource = enable
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() {
if (enable) {
binding.recyclerView.addItemDecoration(bookSourceDecoration)
} else {
binding.recyclerView.removeItemDecoration(bookSourceDecoration)
}
adapter.unregisterAdapterDataObserver(this)
}
})
upBookSource(searchView.query?.toString())
}
/**
* 保持亮屏
*/

View File

@ -21,6 +21,7 @@ import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.gone
import io.legado.app.utils.invisible
import io.legado.app.utils.startActivity
import io.legado.app.utils.visible
@ -33,6 +34,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
private val selected = linkedSetOf<BookSourcePart>()
private val finalMessageRegex = Regex("成功|失败")
var showSourceHost = false
val selection: List<BookSourcePart>
get() {
@ -89,6 +91,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
payloads: MutableList<Any>
) {
binding.run {
upSourceHost(binding, holder.layoutPosition)
if (payloads.isEmpty()) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
cbBookSource.text = item.getDisPlayNameGroup()
@ -233,6 +236,15 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
if (isFinalMessage || isEmpty || !Debug.isChecking) View.GONE else View.VISIBLE
}
private fun upSourceHost(binding: ItemBookSourceBinding, position: Int) = binding.run {
if (showSourceHost && isItemHeader(position)) {
tvHostText.text = getHeaderText(position)
tvHostText.visible()
} else {
tvHostText.gone()
}
}
fun selectAll() {
getItems().forEach {
selected.add(it)

View File

@ -1,69 +0,0 @@
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()
}
}
}

View File

@ -5,9 +5,33 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clipToPadding="false"
android:padding="16dp"
android:scrollbars="none">
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_host_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-12dp"
android:layout_marginBottom="16dp"
android:scrollbars="none"
android:singleLine="true"
android:textSize="16sp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/barrier"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="host"
tools:visibility="visible" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="cb_book_source,swt_enabled,iv_edit,iv_menu_more" />
<io.legado.app.lib.theme.view.ThemeCheckBox
android:id="@+id/cb_book_source"
android:layout_width="0dp"
@ -19,7 +43,7 @@
app:layout_constraintBottom_toTopOf="@id/iv_debug_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/swt_enabled"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/barrier"
tools:ignore="TouchTargetSizeCheck"
tools:text="@string/book_source" />
@ -32,7 +56,7 @@
android:scrollbars="none"
app:layout_constraintBottom_toTopOf="@id/iv_debug_text"
app:layout_constraintRight_toLeftOf="@id/iv_edit"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/barrier"
tools:ignore="RtlHardcoded,RtlSymmetry,TouchTargetSizeCheck" />
<androidx.appcompat.widget.AppCompatImageView
@ -48,7 +72,7 @@
android:tint="@color/primaryText"
app:layout_constraintBottom_toTopOf="@id/iv_debug_text"
app:layout_constraintRight_toLeftOf="@id/iv_menu_more"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@id/barrier" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_menu_more"
@ -62,7 +86,7 @@
android:tint="@color/primaryText"
app:layout_constraintBottom_toTopOf="@id/iv_debug_text"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/barrier"
tools:ignore="RtlHardcoded" />
<io.legado.app.ui.widget.image.CircleImageView