pull/32/head
GKF 6 years ago
parent 5372fff318
commit dc4a9df268
  1. 25
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookGroupAdapter.kt
  2. 1
      app/src/main/res/layout/item_book_group.xml

@ -8,6 +8,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import kotlinx.android.synthetic.main.item_book_group.view.*
class BookGroupAdapter : PagedListAdapter<BookGroup, BookGroupAdapter.MyViewHolder>(DIFF_CALLBACK) { class BookGroupAdapter : PagedListAdapter<BookGroup, BookGroupAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -24,15 +25,37 @@ class BookGroupAdapter : PagedListAdapter<BookGroup, BookGroupAdapter.MyViewHold
} }
} }
var callBack: CallBack? = null
private val defaultGroups = arrayOf(BookGroup(-5, "全部"),
BookGroup(-5, "本地"),
BookGroup(-5, "音频"))
override fun getItemCount(): Int {
return super.getItemCount() + defaultGroups.size
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_book_group, parent, false)) return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_book_group, parent, false))
} }
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
if (position < defaultGroups.size) {
holder.bind(defaultGroups[position], callBack)
} else {
currentList?.get(position - defaultGroups.size)?.let {
holder.bind(it, callBack)
}
}
} }
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(bookGroup: BookGroup, callBack: CallBack?) = with(itemView) {
tv_group.text = bookGroup.groupName
}
}
interface CallBack {
} }
} }

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_group"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="5dp" android:layout_margin="5dp"

Loading…
Cancel
Save