From cdfb24e8338bc95b9ad65aafd5a1ee12ecac6f65 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 18:10:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/arrange/ArrangeBookActivity.kt | 4 ++++ .../io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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) }