diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 1fe5e1f63..1552ae106 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -213,6 +213,10 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi select_action_bar.upCountView(adapter.selectedBooks().size, adapter.getItems().size) } + override fun updateBook(vararg book: Book) { + viewModel.updateBook(*book) + } + override fun deleteBook(book: Book) { alert(titleResource = R.string.draw, messageResource = R.string.sure_del) { okButton { diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index d585e8c62..8ceba8f15 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -127,19 +127,26 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { Collections.swap(getItems(), srcPosition, targetPosition) notifyItemMoved(srcPosition, targetPosition) + if (getItem(srcPosition)?.order == getItem(targetPosition)?.order) { + for ((index, item) in getItems().withIndex()) { + item.order = index + 1 + } + } isMoved = true return true } override fun onClearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { if (isMoved) { - + callBack.updateBook(*getItems().toTypedArray()) } + isMoved = false } interface CallBack { val groupList: List fun upSelectCount() + fun updateBook(vararg book: Book) fun deleteBook(book: Book) fun selectGroup(groupId: Int, requestCode: Int) }