|
|
@ -7,8 +7,6 @@ import android.os.Bundle |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import androidx.fragment.app.activityViewModels |
|
|
|
import androidx.fragment.app.activityViewModels |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
import androidx.paging.LivePagedListBuilder |
|
|
|
|
|
|
|
import androidx.paging.PagedList |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.VMBaseFragment |
|
|
|
import io.legado.app.base.VMBaseFragment |
|
|
@ -31,7 +29,7 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_ |
|
|
|
override val viewModel: ChapterListViewModel by activityViewModels() |
|
|
|
override val viewModel: ChapterListViewModel by activityViewModels() |
|
|
|
private val binding by viewBinding(FragmentBookmarkBinding::bind) |
|
|
|
private val binding by viewBinding(FragmentBookmarkBinding::bind) |
|
|
|
private lateinit var adapter: BookmarkAdapter |
|
|
|
private lateinit var adapter: BookmarkAdapter |
|
|
|
private var bookmarkLiveData: LiveData<PagedList<Bookmark>>? = null |
|
|
|
private var bookmarkLiveData: LiveData<List<Bookmark>>? = null |
|
|
|
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
viewModel.bookMarkCallBack = this |
|
|
|
viewModel.bookMarkCallBack = this |
|
|
@ -43,7 +41,7 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_ |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
private fun initRecyclerView() { |
|
|
|
ATH.applyEdgeEffectColor(binding.recyclerView) |
|
|
|
ATH.applyEdgeEffectColor(binding.recyclerView) |
|
|
|
adapter = BookmarkAdapter(this) |
|
|
|
adapter = BookmarkAdapter(requireContext(), this) |
|
|
|
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext())) |
|
|
|
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext())) |
|
|
|
binding.recyclerView.adapter = adapter |
|
|
|
binding.recyclerView.adapter = adapter |
|
|
@ -51,11 +49,8 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_ |
|
|
|
|
|
|
|
|
|
|
|
private fun initData(book: Book) { |
|
|
|
private fun initData(book: Book) { |
|
|
|
bookmarkLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookmarkLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookmarkLiveData = |
|
|
|
bookmarkLiveData = appDb.bookmarkDao.observeByBook(book.bookUrl, book.name, book.author) |
|
|
|
LivePagedListBuilder( |
|
|
|
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.setItems(it) }) |
|
|
|
appDb.bookmarkDao.observeByBook(book.bookUrl, book.name, book.author), 20 |
|
|
|
|
|
|
|
).build() |
|
|
|
|
|
|
|
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) }) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun startBookmarkSearch(newText: String?) { |
|
|
|
override fun startBookmarkSearch(newText: String?) { |
|
|
@ -65,13 +60,8 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_ |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bookmarkLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookmarkLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookmarkLiveData = LivePagedListBuilder( |
|
|
|
bookmarkLiveData = appDb.bookmarkDao.liveDataSearch(viewModel.bookUrl, newText) |
|
|
|
appDb.bookmarkDao.liveDataSearch( |
|
|
|
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.setItems(it) }) |
|
|
|
viewModel.bookUrl, |
|
|
|
|
|
|
|
newText |
|
|
|
|
|
|
|
), 20 |
|
|
|
|
|
|
|
).build() |
|
|
|
|
|
|
|
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) }) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|