pull/32/head
gedoor 6 years ago
parent d90ea77f08
commit 540db57eb3
  1. 20
      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
  3. 2
      app/src/main/res/layout/item_book_source.xml

@ -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 {
}
}

@ -37,13 +37,10 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source) {
private fun initRecyclerView() {
recycler_view.layoutManager = LinearLayoutManager(context)
context?.let {
adapter = BookSourceAdapter(it)
adapter = BookSourceAdapter()
recycler_view.adapter = adapter
}
}
private fun initDataObservers() {
bookSourceLiveDate?.removeObservers(viewLifecycleOwner)
bookSourceLiveDate = LivePagedListBuilder(App.db.sourceDao().observeAll(), 30).build()

@ -11,7 +11,7 @@
android:orientation="horizontal"
android:padding="16dp">
<com.kunfei.bookshelf.widget.views.ATECheckBox
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_book_source"
android:layout_width="0dp"
android:layout_height="wrap_content"

Loading…
Cancel
Save