Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Dec 21, 2024
1 parent 407c6a9 commit 48b93a0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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())
}

/**
* 保持亮屏
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

This file was deleted.

32 changes: 28 additions & 4 deletions app/src/main/res/layout/item_book_source.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" />

Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 48b93a0

Please sign in to comment.