diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index ff1d48987..8152ae3c8 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -36,6 +36,7 @@ import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* +import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -61,6 +62,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity initSearchView() initLiveDataBookSource() initLiveDataGroup() + initViewEvent() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -81,8 +83,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity R.id.menu_group_manage -> GroupManageDialog().show(supportFragmentManager, "groupManage") R.id.menu_import_source_local -> selectFileSys() - R.id.menu_select_all -> adapter.selectAll() - R.id.menu_revert_selection -> adapter.revertSelection() R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelection()) @@ -142,11 +142,11 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity App.db.bookSourceDao().liveDataSearch("%$searchKey%") } bookSourceLiveDate?.observe(this, Observer { - search_view.queryHint = getString(R.string.search_book_source_num, it.size) val diffResult = DiffUtil .calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it, false) diffResult.dispatchUpdatesTo(adapter) + upCountView() }) } @@ -160,6 +160,16 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity }) } + private fun initViewEvent() { + cb_selected_all.onClick { + adapter.selectAll() + } + btn_revert_selection.onClick { + adapter.revertSelection() + } + + } + private fun upGroupMenu() { groupMenu?.removeGroup(R.id.source_group) groups.map { @@ -230,6 +240,40 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity ) } + override fun upCountView() { + val selectCount = adapter.getSelection().size + if (selectCount == 0) { + cb_selected_all.isChecked = false + } else { + cb_selected_all.isChecked = selectCount >= adapter.getActualItemCount() + } + + //重置全选的文字 + if (cb_selected_all.isChecked) { + cb_selected_all.text = getString( + R.string.select_cancel_count, + selectCount, + adapter.getActualItemCount() + ) + } else { + cb_selected_all.text = getString( + R.string.select_all_count, + selectCount, + adapter.getActualItemCount() + ) + } + setMenuClickable(selectCount > 0) + } + + private fun setMenuClickable(isClickable: Boolean) { + //设置是否可删除 + btn_delete.isEnabled = isClickable + btn_delete.isClickable = isClickable + //设置是否可添加书籍 + btn_revert_selection.isEnabled = isClickable + btn_revert_selection.isClickable = isClickable + } + override fun onFilePicked(requestCode: Int, currentPath: String) { if (requestCode == importSource) { Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index 8e873422b..1da9f5ae4 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -27,6 +27,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : selected.add(it) } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) + callBack.upCountView() } fun revertSelection() { @@ -38,6 +39,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) + callBack.upCountView() } fun getSelection(): LinkedHashSet { @@ -73,6 +75,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } else { selected.remove(item) } + callBack.upCountView() } iv_edit.onClick { callBack.edit(item) } iv_menu_more.onClick { @@ -140,5 +143,6 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : fun update(vararg bookSource: BookSource) fun toTop(bookSource: BookSource) fun upOrder() + fun upCountView() } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index 9fdc30961..bafdbabe6 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -42,16 +42,16 @@ android:layout_margin="5dp" android:padding="5dp" android:gravity="center" - android:minWidth="100dp" + android:minWidth="90dp" android:text="@string/move_to_group" /> diff --git a/app/src/main/res/layout/activity_book_source.xml b/app/src/main/res/layout/activity_book_source.xml index 8fd1a1630..f3be2d751 100644 --- a/app/src/main/res/layout/activity_book_source.xml +++ b/app/src/main/res/layout/activity_book_source.xml @@ -16,7 +16,8 @@ + android:layout_height="0dp" + android:layout_weight="1"> + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index 38bfab5d5..4a4b16d92 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -93,16 +93,16 @@ android:layout_margin="5dp" android:padding="5dp" android:gravity="center" - android:minWidth="100dp" + android:minWidth="90dp" android:text="@string/add_to_shelf" /> diff --git a/app/src/main/res/menu/book_source.xml b/app/src/main/res/menu/book_source.xml index 5740683bd..8df8928e4 100644 --- a/app/src/main/res/menu/book_source.xml +++ b/app/src/main/res/menu/book_source.xml @@ -12,16 +12,6 @@ - - - - 朗读时音量键翻页 Tip边距跟随边距调整 允许更新 - 反转选择 + 反选 搜索书名、作者 书名、作者、URL 常见问题