diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index a02055ad2..f259d3fae 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -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() private val qrResult = registerForActivityResult(QrCodeResult()) { it ?: return@registerForActivityResult @@ -274,7 +270,9 @@ class BookSourceActivity : VMBaseActivity { 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() private val finalMessageRegex = Regex("成功|失败") + var showSourceHost = false val selection: List get() { @@ -89,6 +91,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : payloads: MutableList ) { 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) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceDecoration.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceDecoration.kt deleted file mode 100644 index 85bf735c8..000000000 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceDecoration.kt +++ /dev/null @@ -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() - } - } - -} diff --git a/app/src/main/res/layout/item_book_source.xml b/app/src/main/res/layout/item_book_source.xml index 1b5ee6ec6..27487fed5 100644 --- a/app/src/main/res/layout/item_book_source.xml +++ b/app/src/main/res/layout/item_book_source.xml @@ -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"> + + + + @@ -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" /> + app:layout_constraintTop_toBottomOf="@id/barrier" />