pull/32/head
kunfei 6 years ago
parent 998ce1815f
commit c36d08c071
  1. 23
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt
  2. 5
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt

@ -5,6 +5,7 @@ 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
import androidx.recyclerview.widget.RecyclerView
@ -33,7 +34,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
}
var callBack: CallBack? = null
val checkedList = HashSet<String>()
private val checkedList = HashSet<String>()
val itemTouchCallbackListener = object : OnItemTouchCallbackListener {
override fun onSwiped(adapterPosition: Int) {
@ -56,6 +57,25 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
}
}
fun selectAll() {
currentList?.let {
if (checkedList.size == it.size) {
checkedList.clear()
notifyDataSetChanged()
} else {
for (item in it) {
item?.let { checkedList.add(item.origin) }
}
notifyDataSetChanged()
}
}
}
override fun onCurrentListChanged(previousList: PagedList<BookSource>?, currentList: PagedList<BookSource>?) {
super.onCurrentListChanged(previousList, currentList)
callBack?.upCount(itemCount)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_book_source, parent, false))
}
@ -116,6 +136,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
}
interface CallBack {
fun upCount(count: Int)
fun del(bookSource: BookSource)
fun edit(bookSource: BookSource)
fun update(bookSource: BookSource)

@ -50,6 +50,7 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
R.id.action_import_book_source_qr -> {
context?.startActivity<QrCodeActivity>()
}
R.id.action_select_all -> adapter.selectAll()
}
}
@ -98,6 +99,10 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
return false
}
override fun upCount(count: Int) {
search_view.queryHint = getString(R.string.search_book_source_num, count)
}
override fun del(bookSource: BookSource) {
launch(IO) { App.db.bookSourceDao().delete(bookSource) }
}

Loading…
Cancel
Save