|
|
|
@ -1,14 +1,17 @@ |
|
|
|
|
package io.legado.app.ui.main.booksource |
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
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.* |
|
|
|
|
|
|
|
|
|
class BookSourceAdapter(context : Context) : PagedListAdapter<BookSource, BookSourceAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
|
class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
@ -25,17 +28,26 @@ class BookSourceAdapter(context : Context) : PagedListAdapter<BookSource, BookSo |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var callback :Callback? = null |
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { |
|
|
|
|
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
|
|
|
|
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_book_source, parent, false)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
|
|
|
|
|
|
getItem(position)?.let { holder.bind(it, callback) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
|
|
|
|
|
|
fun bind(bookSource: BookSource, callback: Callback?) = with(itemView) { |
|
|
|
|
cb_book_source.text = String.format("%s (%s)", bookSource.name, bookSource.group) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface Callback { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |