From 0cce324ce375b5344d75f67171672ddc5f8e3eeb Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 18:40:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/arrange/ArrangeBookActivity.kt | 8 ++------ .../app/ui/book/arrange/ArrangeBookAdapter.kt | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 10 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 740afc1cc..936c7b70b 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 @@ -49,7 +49,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi adapter = ArrangeBookAdapter(this, this) recycler_view.adapter = adapter cb_selected_all.onClick { - adapter.selectAll(cb_selected_all.isChecked) + adapter.selectAll(!adapter.isSelectAll()) } } @@ -70,11 +70,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi } override fun upSelectCount() { - if (adapter.selectedBooks.size == 0) { - cb_selected_all.isChecked = false - } else { - cb_selected_all.isChecked = adapter.selectedBooks.size >= adapter.getItems().size - } + cb_selected_all.isChecked = adapter.isSelectAll() //重置全选的文字 if (cb_selected_all.isChecked) { cb_selected_all.setText(R.string.cancel) 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 75bc12c85..890f29bad 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 @@ -15,17 +15,25 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : val selectedBooks: HashSet = hashSetOf() + fun isSelectAll(): Boolean { + return if (selectedBooks.isEmpty()) { + false + } else { + selectedBooks.size >= itemCount + } + } + fun selectAll(selectAll: Boolean) { if (selectAll) { - selectedBooks.clear() - notifyDataSetChanged() - callBack.upSelectCount() - } else { getItems().forEach { selectedBooks.add(it.bookUrl) } notifyDataSetChanged() callBack.upSelectCount() + } else { + selectedBooks.clear() + notifyDataSetChanged() + callBack.upSelectCount() } }