pull/1198/head
gedoor 3 years ago
parent 0d0f07ba8c
commit bd4848a7af
  1. 1
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt
  2. 15
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt
  3. 15
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt
  4. 9
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt

@ -80,6 +80,7 @@ abstract class BaseBooksAdapter<VH : RecyclerView.ViewHolder>(
fun onItemLongClick(position: Int)
fun isUpdate(bookUrl: String): Boolean
fun getItemCount(): Int
fun getItemType(position: Int): Int
fun getItem(position: Int): Any
}
}

@ -21,13 +21,22 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
return callBack.getItemCount()
}
override fun getItemViewType(position: Int): Int {
return callBack.getItemType(position)
}
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): RecyclerView.ViewHolder {
return BookViewHolder(
ItemBookshelfGridBinding.inflate(LayoutInflater.from(context), parent, false)
)
return when (viewType) {
1 -> GroupViewHolder(
ItemBookshelfGridGroupBinding.inflate(LayoutInflater.from(context), parent, false)
)
else -> BookViewHolder(
ItemBookshelfGridBinding.inflate(LayoutInflater.from(context), parent, false)
)
}
}
override fun onBindViewHolder(

@ -23,10 +23,19 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
return callBack.getItemCount()
}
override fun getItemViewType(position: Int): Int {
return callBack.getItemType(position)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return BookViewHolder(
ItemBookshelfListBinding.inflate(LayoutInflater.from(context), parent, false)
)
return when (viewType) {
1 -> GroupViewHolder(
ItemBookshelfListGroupBinding.inflate(LayoutInflater.from(context), parent, false)
)
else -> BookViewHolder(
ItemBookshelfListBinding.inflate(LayoutInflater.from(context), parent, false)
)
}
}
override fun onBindViewHolder(

@ -45,7 +45,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
BaseBooksAdapter.CallBack {
private val binding by viewBinding(FragmentBookshelf1Binding::bind)
private lateinit var searchView: SearchView
private lateinit var booksAdapter: BaseBooksAdapter<*>
override var groupId = AppConst.bookGroupNoneId
private var booksFlowJob: Job? = null
@ -198,6 +197,14 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
}
}
override fun getItemType(position: Int): Int {
return if (groupId == AppConst.bookGroupNoneId) {
if (position < bookGroups.size) 1 else 0
} else {
0
}
}
override fun getItem(position: Int): Any {
return if (groupId == AppConst.bookGroupNoneId) {
if (position < bookGroups.size) {

Loading…
Cancel
Save