修复书源拖动闪退bug

pull/737/head
gedoor 4 years ago
parent 69ea4cb0bf
commit 87f2aed7db
  1. 58
      app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt
  5. 4
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugAdapter.kt

@ -35,7 +35,7 @@ abstract class SimpleRecyclerAdapter<ITEM, VB : ViewBinding>(protected val conte
object : DiffUtil.ItemCallback<ITEM>() {
override fun areItemsTheSame(oldItem: ITEM, newItem: ITEM): Boolean {
return oldItem == newItem
return false
}
override fun areContentsTheSame(oldItem: ITEM, newItem: ITEM): Boolean {
@ -70,57 +70,6 @@ abstract class SimpleRecyclerAdapter<ITEM, VB : ViewBinding>(protected val conte
}
}
fun addItem(item: ITEM) {
synchronized(lock) {
val list = ArrayList(asyncListDiffer.currentList)
list.add(item)
asyncListDiffer.submitList(list)
}
}
fun addItems(position: Int, newItems: List<ITEM>) {
synchronized(lock) {
val list = ArrayList(asyncListDiffer.currentList)
list.addAll(position, newItems)
asyncListDiffer.submitList(list)
}
}
fun addItems(newItems: List<ITEM>) {
synchronized(lock) {
val list = ArrayList(asyncListDiffer.currentList)
list.addAll(newItems)
asyncListDiffer.submitList(list)
}
}
fun removeItem(position: Int) {
synchronized(lock) {
val list = ArrayList(asyncListDiffer.currentList)
if (list.removeAt(position) != null) {
asyncListDiffer.submitList(list)
}
}
}
fun removeItem(item: ITEM) {
synchronized(lock) {
val list = ArrayList(asyncListDiffer.currentList)
if (list.remove(item)) {
asyncListDiffer.submitList(list)
}
}
}
fun removeItems(items: List<ITEM>) {
synchronized(lock) {
val list = ArrayList(asyncListDiffer.currentList)
if (list.removeAll(items)) {
asyncListDiffer.submitList(list)
}
}
}
fun swapItem(srcPosition: Int, targetPosition: Int) {
synchronized(lock) {
val list = ArrayList(getItems())
@ -158,11 +107,6 @@ abstract class SimpleRecyclerAdapter<ITEM, VB : ViewBinding>(protected val conte
}
}
fun clearItems() =
synchronized(lock) {
asyncListDiffer.submitList(arrayListOf())
}
fun isEmpty() = asyncListDiffer.currentList.isEmpty()
fun isNotEmpty() = asyncListDiffer.currentList.isNotEmpty()

@ -4,8 +4,8 @@ import android.content.Context
import android.net.Uri
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.CommonRecyclerAdapter
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.AppConst
import io.legado.app.databinding.ItemImportBookBinding
import io.legado.app.utils.*
@ -13,7 +13,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class ImportBookAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<DocItem, ItemImportBookBinding>(context) {
CommonRecyclerAdapter<DocItem, ItemImportBookBinding>(context) {
var selectedUris = hashSetOf<String>()
var checkableCount = 0
private var bookFileNames = arrayListOf<String>()

@ -3,8 +3,8 @@ package io.legado.app.ui.book.searchContent
import android.content.Context
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.CommonRecyclerAdapter
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.databinding.ItemSearchListBinding
import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.getCompatColor
@ -12,7 +12,7 @@ import io.legado.app.utils.hexString
import org.jetbrains.anko.sdk27.listeners.onClick
class SearchContentAdapter(context: Context, val callback: Callback) :
SimpleRecyclerAdapter<SearchResult, ItemSearchListBinding>(context) {
CommonRecyclerAdapter<SearchResult, ItemSearchListBinding>(context) {
val cacheFileNames = hashSetOf<String>()
val textColor = context.getCompatColor(R.color.primaryText).hexString.substring(2)

@ -4,12 +4,12 @@ import android.content.Context
import android.view.View
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.CommonRecyclerAdapter
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.databinding.ItemLogBinding
class BookSourceDebugAdapter(context: Context) :
SimpleRecyclerAdapter<String, ItemLogBinding>(context) {
CommonRecyclerAdapter<String, ItemLogBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemLogBinding {
return ItemLogBinding.inflate(inflater, parent, false)

@ -4,12 +4,12 @@ import android.content.Context
import android.view.View
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.adapter.CommonRecyclerAdapter
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.databinding.ItemLogBinding
class RssSourceDebugAdapter(context: Context) :
SimpleRecyclerAdapter<String, ItemLogBinding>(context) {
CommonRecyclerAdapter<String, ItemLogBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemLogBinding {
return ItemLogBinding.inflate(inflater, parent, false)

Loading…
Cancel
Save