From 83cfc65455ae2c396f37e6e4372491cdda68414b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 9 Aug 2019 12:16:12 +0800 Subject: [PATCH] up --- .../app/ui/chapterlist/BookmarkFragment.kt | 6 ++-- .../app/ui/chapterlist/ChapterListFragment.kt | 28 +++++++++++++++++++ app/src/main/res/layout/fragment_bookmark.xml | 2 +- .../main/res/layout/fragment_chapter_list.xml | 2 +- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt index 5133474bf..ecb17d9cb 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt @@ -28,10 +28,10 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ } private fun initRecyclerView() { - ATH.applyEdgeEffectColor(rv_list) + ATH.applyEdgeEffectColor(recycler_view) adapter = BookmarkAdapter() - rv_list.layoutManager = LinearLayoutManager(requireContext()) - rv_list.adapter = adapter + recycler_view.layoutManager = LinearLayoutManager(requireContext()) + recycler_view.adapter = adapter } private fun initData() { diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index f88f0dbb6..ec6418a73 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -1,13 +1,41 @@ package io.legado.app.ui.chapterlist +import android.os.Bundle +import android.view.View +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import androidx.paging.LivePagedListBuilder +import androidx.paging.PagedList +import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment +import io.legado.app.data.entities.BookChapter import io.legado.app.utils.getViewModelOfActivity +import kotlinx.android.synthetic.main.fragment_chapter_list.* class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list) { override val viewModel: ChapterListViewModel get() = getViewModelOfActivity(ChapterListViewModel::class.java) + lateinit var adapter: ChapterListAdapter + var liveData: LiveData>? = null + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + initRecyclerView() + initData() + } + private fun initRecyclerView() { + adapter = ChapterListAdapter() + recycler_view.layoutManager = LinearLayoutManager(requireContext()) + recycler_view.adapter = adapter + } + + private fun initData() { + liveData?.removeObservers(viewLifecycleOwner) + liveData = LivePagedListBuilder(App.db.bookChapterDao().observeByBook(""), 30).build() + liveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bookmark.xml b/app/src/main/res/layout/fragment_bookmark.xml index e9b393f1e..fab36a60b 100644 --- a/app/src/main/res/layout/fragment_bookmark.xml +++ b/app/src/main/res/layout/fragment_bookmark.xml @@ -5,7 +5,7 @@ android:descendantFocusability="blocksDescendants"> diff --git a/app/src/main/res/layout/fragment_chapter_list.xml b/app/src/main/res/layout/fragment_chapter_list.xml index 5fa516994..40633c3d8 100644 --- a/app/src/main/res/layout/fragment_chapter_list.xml +++ b/app/src/main/res/layout/fragment_chapter_list.xml @@ -6,7 +6,7 @@ android:descendantFocusability="blocksDescendants">