优化
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
/**
|
||||
* 保持亮屏
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user