diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt index 15132959a..e5a0428c5 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt @@ -80,6 +80,7 @@ abstract class BaseBooksAdapter( fun onItemLongClick(position: Int) fun isUpdate(bookUrl: String): Boolean fun getItemCount(): Int + fun getItemType(position: Int): Int fun getItem(position: Int): Any } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt index 3bd6e01c4..fc78d79cd 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt @@ -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( diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt index 0c85fd5fe..461991628 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt @@ -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( diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index 6e433dec9..fc5e34ddd 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -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) {