feat: 优化代码

pull/173/head
kunfei 5 years ago
parent 26ff281fe9
commit cdfb24e833
  1. 4
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  2. 9
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt

@ -213,6 +213,10 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
select_action_bar.upCountView(adapter.selectedBooks().size, adapter.getItems().size) select_action_bar.upCountView(adapter.selectedBooks().size, adapter.getItems().size)
} }
override fun updateBook(vararg book: Book) {
viewModel.updateBook(*book)
}
override fun deleteBook(book: Book) { override fun deleteBook(book: Book) {
alert(titleResource = R.string.draw, messageResource = R.string.sure_del) { alert(titleResource = R.string.draw, messageResource = R.string.sure_del) {
okButton { okButton {

@ -127,19 +127,26 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
Collections.swap(getItems(), srcPosition, targetPosition) Collections.swap(getItems(), srcPosition, targetPosition)
notifyItemMoved(srcPosition, targetPosition) notifyItemMoved(srcPosition, targetPosition)
if (getItem(srcPosition)?.order == getItem(targetPosition)?.order) {
for ((index, item) in getItems().withIndex()) {
item.order = index + 1
}
}
isMoved = true isMoved = true
return true return true
} }
override fun onClearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { override fun onClearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
if (isMoved) { if (isMoved) {
callBack.updateBook(*getItems().toTypedArray())
} }
isMoved = false
} }
interface CallBack { interface CallBack {
val groupList: List<BookGroup> val groupList: List<BookGroup>
fun upSelectCount() fun upSelectCount()
fun updateBook(vararg book: Book)
fun deleteBook(book: Book) fun deleteBook(book: Book)
fun selectGroup(groupId: Int, requestCode: Int) fun selectGroup(groupId: Int, requestCode: Int)
} }

Loading…
Cancel
Save