|
|
@ -14,6 +14,7 @@ import androidx.viewpager2.widget.ViewPager2 |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.VMBaseFragment |
|
|
|
import io.legado.app.base.VMBaseFragment |
|
|
|
|
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.constant.Bus |
|
|
|
import io.legado.app.constant.Bus |
|
|
|
import io.legado.app.data.entities.BookGroup |
|
|
|
import io.legado.app.data.entities.BookGroup |
|
|
|
import io.legado.app.lib.dialogs.* |
|
|
|
import io.legado.app.lib.dialogs.* |
|
|
@ -27,7 +28,8 @@ import org.jetbrains.anko.startActivity |
|
|
|
|
|
|
|
|
|
|
|
class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_bookshelf), |
|
|
|
class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_bookshelf), |
|
|
|
SearchView.OnQueryTextListener, |
|
|
|
SearchView.OnQueryTextListener, |
|
|
|
BookGroupAdapter.CallBack { |
|
|
|
BookGroupAdapter.CallBack, |
|
|
|
|
|
|
|
BookshelfAdapter.CallBack { |
|
|
|
|
|
|
|
|
|
|
|
override val viewModel: BookshelfViewModel |
|
|
|
override val viewModel: BookshelfViewModel |
|
|
|
get() = getViewModel(BookshelfViewModel::class.java) |
|
|
|
get() = getViewModel(BookshelfViewModel::class.java) |
|
|
@ -55,13 +57,21 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override val groupSize: Int |
|
|
|
|
|
|
|
get() = bookGroupAdapter.itemCount |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun getGroup(position: Int): BookGroup? { |
|
|
|
|
|
|
|
return bookGroupAdapter.getItem(position) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
private fun initRecyclerView() { |
|
|
|
ATH.applyEdgeEffectColor(view_pager_bookshelf) |
|
|
|
ATH.applyEdgeEffectColor(view_pager_bookshelf) |
|
|
|
rv_book_group.layoutManager = |
|
|
|
rv_book_group.layoutManager = |
|
|
|
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) |
|
|
|
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) |
|
|
|
bookGroupAdapter = BookGroupAdapter(requireContext(), this) |
|
|
|
bookGroupAdapter = BookGroupAdapter(requireContext(), this) |
|
|
|
rv_book_group.adapter = bookGroupAdapter |
|
|
|
rv_book_group.adapter = bookGroupAdapter |
|
|
|
view_pager_bookshelf.adapter = BookshelfAdapter(this) |
|
|
|
bookGroupAdapter.setItems(AppConst.defaultBookGroups) |
|
|
|
|
|
|
|
view_pager_bookshelf.adapter = BookshelfAdapter(this, this) |
|
|
|
view_pager_bookshelf.registerOnPageChangeCallback(object : |
|
|
|
view_pager_bookshelf.registerOnPageChangeCallback(object : |
|
|
|
ViewPager2.OnPageChangeCallback() { |
|
|
|
ViewPager2.OnPageChangeCallback() { |
|
|
|
override fun onPageSelected(position: Int) { |
|
|
|
override fun onPageSelected(position: Int) { |
|
|
@ -76,11 +86,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b |
|
|
|
bookGroupLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookGroupLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookGroupLiveData = App.db.bookGroupDao().liveDataAll() |
|
|
|
bookGroupLiveData = App.db.bookGroupDao().liveDataAll() |
|
|
|
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { |
|
|
|
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { |
|
|
|
mutableListOf( |
|
|
|
AppConst.defaultBookGroups.apply { |
|
|
|
BookGroup(-1, "全部"), |
|
|
|
|
|
|
|
BookGroup(-2, "本地"), |
|
|
|
|
|
|
|
BookGroup(-3, "音频") |
|
|
|
|
|
|
|
).apply { |
|
|
|
|
|
|
|
addAll(it) |
|
|
|
addAll(it) |
|
|
|
}.let { |
|
|
|
}.let { |
|
|
|
bookGroupAdapter.setItems(it) |
|
|
|
bookGroupAdapter.setItems(it) |
|
|
|