pull/32/head
GKF 6 years ago
parent 3101a90393
commit 304c099151
  1. 38
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 7
      app/src/main/res/layout/item_bookshelf_list_add.xml

@ -16,7 +16,7 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name
import java.io.File
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {
class BookshelfAdapter : PagedListAdapter<Book, RecyclerView.ViewHolder>(DIFF_CALLBACK) {
companion object {
@JvmField
@ -33,13 +33,40 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
var callBack: CallBack? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
override fun getItemViewType(position: Int): Int {
if (position == itemCount - 1) {
return 1
}
return super.getItemViewType(position)
}
override fun getItemCount(): Int {
return super.getItemCount() + 1
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
if (viewType == 1) {
return AddViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookshelf_list_add, parent, false))
}
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookshelf_list, parent, false))
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
currentList?.get(position)?.let {
holder.bind(it, callBack)
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is MyViewHolder -> {
currentList?.get(position)?.let {
holder.bind(it, callBack)
}
}
is AddViewHolder -> holder.bind(callBack)
}
}
class AddViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(callBack: CallBack?) = with(itemView) {
setOnClickListener { callBack?.search() }
}
}
@ -76,5 +103,6 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
interface CallBack {
fun open(book: Book)
fun search()
}
}

@ -7,6 +7,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
@ -42,6 +43,7 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
bookGroupAdapter = BookGroupAdapter()
rv_book_group.adapter = bookGroupAdapter
rv_bookshelf.layoutManager = LinearLayoutManager(context)
rv_bookshelf.addItemDecoration(DividerItemDecoration(rv_bookshelf.context, LinearLayoutManager.VERTICAL))
bookshelfAdapter = BookshelfAdapter()
rv_bookshelf.adapter = bookshelfAdapter
}

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:text="@string/add"
android:textSize="24sp" />
Loading…
Cancel
Save