修复书源拖动闪退bug

pull/736/head
gedoor 4 years ago
parent fa7c4f64f8
commit 69ea4cb0bf
  1. 11
      app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  5. 3
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  7. 3
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt
  8. 4
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt
  9. 4
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt

@ -121,14 +121,11 @@ abstract class SimpleRecyclerAdapter<ITEM, VB : ViewBinding>(protected val conte
}
}
fun swapItem(oldPosition: Int, newPosition: Int) {
fun swapItem(srcPosition: Int, targetPosition: Int) {
synchronized(lock) {
val size = itemCount
if (oldPosition in 0 until size && newPosition in 0 until size) {
Collections.swap(asyncListDiffer.currentList, oldPosition, newPosition)
notifyItemChanged(oldPosition)
notifyItemChanged(newPosition)
}
val list = ArrayList(getItems())
Collections.swap(list, srcPosition, targetPosition)
setItems(list)
}
}

@ -141,8 +141,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
val srcItem = getItem(srcPosition)
val targetItem = getItem(targetPosition)
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
if (srcItem != null && targetItem != null) {
if (srcItem.order == targetItem.order) {
for ((index, item) in getItems().withIndex()) {
@ -154,6 +152,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
targetItem.order = pos
}
}
swapItem(srcPosition, targetPosition)
isMoved = true
return true
}

@ -31,7 +31,6 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: GroupViewModel
@ -194,8 +193,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
isMoved = true
return true
}

@ -33,7 +33,6 @@ import io.legado.app.utils.getViewModel
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
@ -193,8 +192,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
isMoved = true
return true
}

@ -248,8 +248,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private var isMoved = false
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
isMoved = true
return super.onMove(srcPosition, targetPosition)
}

@ -21,7 +21,6 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback.Callback
import io.legado.app.utils.invisible
import io.legado.app.utils.visible
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class BookSourceAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<BookSource, ItemBookSourceBinding>(context),
@ -194,8 +193,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
movedItems.add(targetItem)
}
}
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
return true
}

@ -153,8 +153,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
movedItems.add(targetItem)
}
}
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
return true
}

@ -17,7 +17,6 @@ import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class RssSourceAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<RssSource, ItemRssSourceBinding>(context),
@ -160,8 +159,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
movedItems.add(targetItem)
}
}
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
return true
}

@ -12,7 +12,6 @@ import io.legado.app.data.entities.RuleSub
import io.legado.app.databinding.ItemRuleSubBinding
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class RuleSubAdapter(context: Context, val callBack: Callback) :
SimpleRecyclerAdapter<RuleSub, ItemRuleSubBinding>(context),
@ -74,8 +73,7 @@ class RuleSubAdapter(context: Context, val callBack: Callback) :
movedItems.add(targetItem)
}
}
Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition)
swapItem(srcPosition, targetPosition)
return true
}

Loading…
Cancel
Save