From 7b43dac406e7db0ceebb8527351ccca8ec48d393 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 12 Mar 2020 17:03:37 +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 --- .../app/ui/book/arrange/ArrangeBookActivity.kt | 6 ++++++ .../app/ui/book/arrange/ArrangeBookAdapter.kt | 16 +++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) 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 f3b0d5ee5..15217f3bc 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 @@ -6,12 +6,14 @@ import android.view.MenuItem import androidx.appcompat.widget.PopupMenu import androidx.lifecycle.LiveData import androidx.lifecycle.Observer +import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup +import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.okButton @@ -64,6 +66,10 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi recycler_view.addItemDecoration(VerticalDivider(this)) adapter = ArrangeBookAdapter(this, this) recycler_view.adapter = adapter + val itemTouchCallback = ItemTouchCallback() + itemTouchCallback.onItemTouchCallbackListener = adapter + itemTouchCallback.isCanDrag = true + ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) select_action_bar.setMainActionText(R.string.move_to_group) select_action_bar.inflateMenu(R.menu.arrange_book_sel) select_action_bar.setOnMenuItemClickListener(this) 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 fd51e3a3d..abc72b905 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 @@ -7,14 +7,13 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup -import io.legado.app.utils.gone -import io.legado.app.utils.visible +import io.legado.app.help.ItemTouchCallback import kotlinx.android.synthetic.main.item_arrange_book.view.* import org.jetbrains.anko.sdk27.listeners.onClick - class ArrangeBookAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context, R.layout.item_arrange_book) { + SimpleRecyclerAdapter(context, R.layout.item_arrange_book), + ItemTouchCallback.OnItemTouchCallbackListener { val groupRequestCode = 12 private val selectedBooks: HashSet = hashSetOf() var actionItem: Book? = null @@ -56,12 +55,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { tv_name.text = item.name -// tv_name.text = if (item.author.isEmpty()) { -// item.name -// } else { -// "${item.name}(${item.author})" -// } - tv_author.text = item.author // resources.getString(R.string.author_show, item.author) + tv_author.text = item.author tv_author.visibility = if (item.author.isEmpty()) View.GONE else View.VISIBLE tv_group_s.text = getGroupName(item.group) checkbox.isChecked = selectedBooks.contains(item) @@ -115,7 +109,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : groupNames.add(it.groupName) } } - return groupNames; + return groupNames } private fun getGroupName(groupId: Int): String {