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 onItemLongClick(position: Int)
fun isUpdate(bookUrl: String): Boolean fun isUpdate(bookUrl: String): Boolean
fun getItemCount(): Int fun getItemCount(): Int
fun getItemType(position: Int): Int
fun getItem(position: Int): Any fun getItem(position: Int): Any
} }
} }

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

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

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

Loading…
Cancel
Save