pull/32/head
gedoor 6 years ago
parent 540db57eb3
commit 11c796456c
  1. 20
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt

@ -1,6 +1,5 @@
package io.legado.app.ui.main.booksource
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -10,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.data.entities.BookSource
import kotlinx.android.synthetic.main.item_book_source.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -28,7 +28,8 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
}
}
var callback :Callback? = null
var callback: Callback? = null
val checkedList = HashSet<String>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_book_source, parent, false))
@ -36,18 +37,27 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
getItem(position)?.let { holder.bind(it, callback) }
getItem(position)?.let { holder.bind(it, checkedList, callback) }
}
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(bookSource: BookSource, callback: Callback?) = with(itemView) {
fun bind(bookSource: BookSource, checkedList: HashSet<String>, callback: Callback?) = with(itemView) {
cb_book_source.text = String.format("%s (%s)", bookSource.name, bookSource.group)
cb_book_source.onClick {
if (cb_book_source.isChecked) {
checkedList.add(bookSource.origin)
} else {
checkedList.remove(bookSource.origin)
}
}
}
}
interface Callback {
fun del(bookSource: BookSource)
fun edit(bookSource: BookSource)
fun update(bookSource: BookSource)
}
}
Loading…
Cancel
Save