pull/737/head
Robot 4 years ago
commit 298d858baa
  1. 13
      app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  4. 1
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  5. 7
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt

@ -16,12 +16,14 @@ import kotlin.collections.ArrayList
*/ */
@Suppress("unused") @Suppress("unused")
abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Context) : abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Context) :
RecyclerView.Adapter<ItemViewHolder>() { RecyclerView.Adapter<ItemViewHolder>(), AsyncListDiffer.ListListener<ITEM> {
val inflater: LayoutInflater = LayoutInflater.from(context) val inflater: LayoutInflater = LayoutInflater.from(context)
private val asyncListDiffer: AsyncListDiffer<ITEM> by lazy { private val asyncListDiffer: AsyncListDiffer<ITEM> by lazy {
AsyncListDiffer(this, diffItemCallback) AsyncListDiffer(this, diffItemCallback).apply {
addListListener(this@DiffRecyclerAdapter)
}
} }
private val lock = Object() private val lock = Object()
@ -144,6 +146,13 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context
final override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {} final override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {}
override fun onCurrentListChanged(
previousList: MutableList<ITEM>,
currentList: MutableList<ITEM>
) {
}
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
final override fun onBindViewHolder( final override fun onBindViewHolder(
holder: ItemViewHolder, holder: ItemViewHolder,

@ -152,7 +152,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
adapter = BookSourceAdapter(this, this) adapter = BookSourceAdapter(this, this)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
// When this page is opened, it is in selection mode // When this page is opened, it is in selection mode
val dragSelectTouchHelper: DragSelectTouchHelper = val dragSelectTouchHelper =
DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50) DragSelectTouchHelper(adapter.dragSelectCallback).setSlideArea(16, 50)
dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView) dragSelectTouchHelper.attachToRecyclerView(binding.recyclerView)
dragSelectTouchHelper.activeSlideSelect() dragSelectTouchHelper.activeSlideSelect()
@ -207,7 +207,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
else -> data.reversed() else -> data.reversed()
} }
adapter.setItems(sourceList) adapter.setItems(sourceList)
upCountView()
}) })
} }

@ -147,6 +147,13 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} }
} }
override fun onCurrentListChanged(
previousList: MutableList<BookSource>,
currentList: MutableList<BookSource>
) {
callBack.upCountView()
}
private fun showMenu(view: View, position: Int) { private fun showMenu(view: View, position: Int) {
val source = getItem(position) ?: return val source = getItem(position) ?: return
val popupMenu = PopupMenu(context, view) val popupMenu = PopupMenu(context, view)

@ -209,7 +209,6 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
} }
sourceLiveData?.observe(this, { sourceLiveData?.observe(this, {
adapter.setItems(it) adapter.setItems(it)
upCountView()
}) })
} }

@ -128,6 +128,13 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
} }
} }
override fun onCurrentListChanged(
previousList: MutableList<RssSource>,
currentList: MutableList<RssSource>
) {
callBack.upCountView()
}
fun selectAll() { fun selectAll() {
getItems().forEach { getItems().forEach {
selected.add(it) selected.add(it)

Loading…
Cancel
Save