|
|
|
@ -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) { |
|
|
|
|
|
|
|
|
@ -29,6 +29,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |