From 397e64a84a8605231cb4efeed2d2727b474dcab1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 27 Jun 2019 20:44:48 +0800 Subject: [PATCH] up --- .../ui/main/booksource/BookSourceAdapter.kt | 67 +++---------------- .../ui/main/booksource/BookSourceFragment.kt | 7 +- app/src/main/res/layout/item_book_source.xml | 39 ++++++++--- 3 files changed, 43 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt index 571c44ee1..e66f83482 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt @@ -1,10 +1,8 @@ package io.legado.app.ui.main.booksource import android.view.LayoutInflater -import android.view.Menu import android.view.View import android.view.ViewGroup -import android.widget.PopupMenu import androidx.paging.PagedList import androidx.paging.PagedListAdapter import androidx.recyclerview.widget.DiffUtil @@ -34,7 +32,6 @@ class BookSourceAdapter : PagedListAdapter() val itemTouchCallbackListener = object : OnItemTouchCallbackListener { override fun onSwiped(adapterPosition: Int) { @@ -57,24 +54,6 @@ class BookSourceAdapter : PagedListAdapter?, currentList: PagedList?) { super.onCurrentListChanged(previousList, currentList) callBack?.upCount(itemCount) @@ -86,7 +65,7 @@ class BookSourceAdapter : PagedListAdapter, callBack: CallBack?) = with(itemView) { + fun bind(bookSource: BookSource, callBack: CallBack?) = with(itemView) { cb_book_source.text = String.format("%s (%s)", bookSource.name, bookSource.group) - cb_book_source.isChecked = checkedList.contains(bookSource.origin) - cb_book_source.onClick { - if (cb_book_source.isChecked) { - checkedList.add(bookSource.origin) - } else { - checkedList.remove(bookSource.origin) - } - } - sw_enabled.isChecked = bookSource.isEnabled - sw_enabled.setOnClickListener { - bookSource.isEnabled = sw_enabled.isChecked + cb_book_source.isChecked = bookSource.isEnabled + cb_book_source.setOnClickListener { + bookSource.isEnabled = cb_book_source.isChecked callBack?.update(bookSource) } - iv_more.onClick { - val popupMenu = PopupMenu(context, iv_more) - popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit) - popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete) - popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top) - popupMenu.setOnMenuItemClickListener { - when (it.itemId) { - R.id.menu_edit -> { - callBack?.edit(bookSource) - true - } - R.id.menu_del -> { - callBack?.del(bookSource) - true - } - R.id.menu_top -> { - true - } - else -> { - false - } - } - } - popupMenu.show() - } + iv_edit_source.onClick { callBack?.edit(bookSource) } + iv_top_source.onClick { } + iv_del_source.onClick { callBack?.del(bookSource) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt index f9cdfc971..b7208af8b 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt @@ -50,7 +50,11 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour R.id.action_import_book_source_qr -> { context?.startActivity() } - R.id.action_select_all -> adapter.selectAll() + R.id.action_select_all -> { + launch { + + } + } } } @@ -92,7 +96,6 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour override fun onQueryTextChange(newText: String?): Boolean { newText?.let { - adapter.clearSelect() initDataObserve("%$it%") } return false diff --git a/app/src/main/res/layout/item_book_source.xml b/app/src/main/res/layout/item_book_source.xml index 2b0c1450d..31775c35d 100644 --- a/app/src/main/res/layout/item_book_source.xml +++ b/app/src/main/res/layout/item_book_source.xml @@ -18,19 +18,40 @@ android:text="" android:textColor="@color/tv_text_default" /> - + + + + \ No newline at end of file