|
|
@ -13,6 +13,7 @@ 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 |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.appDb |
|
|
|
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Bookmark |
|
|
|
import io.legado.app.data.entities.Bookmark |
|
|
|
import io.legado.app.databinding.DialogBookmarkBinding |
|
|
|
import io.legado.app.databinding.DialogBookmarkBinding |
|
|
|
import io.legado.app.databinding.FragmentBookmarkBinding |
|
|
|
import io.legado.app.databinding.FragmentBookmarkBinding |
|
|
@ -35,7 +36,9 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_ |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
viewModel.bookMarkCallBack = this |
|
|
|
viewModel.bookMarkCallBack = this |
|
|
|
initRecyclerView() |
|
|
|
initRecyclerView() |
|
|
|
initData() |
|
|
|
viewModel.bookData.observe(this) { |
|
|
|
|
|
|
|
initData(it) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
private fun initRecyclerView() { |
|
|
@ -46,20 +49,20 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_ |
|
|
|
binding.recyclerView.adapter = adapter |
|
|
|
binding.recyclerView.adapter = adapter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
private fun initData(book: Book) { |
|
|
|
viewModel.book?.let { book -> |
|
|
|
bookmarkLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookmarkLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookmarkLiveData = |
|
|
|
bookmarkLiveData = |
|
|
|
LivePagedListBuilder( |
|
|
|
LivePagedListBuilder( |
|
|
|
appDb.bookmarkDao.observeByBook(book.bookUrl, book.name, book.author), 20 |
|
|
|
appDb.bookmarkDao.observeByBook(book.bookUrl, book.name, book.author), 20 |
|
|
|
).build() |
|
|
|
).build() |
|
|
|
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) }) |
|
|
|
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun startBookmarkSearch(newText: String?) { |
|
|
|
override fun startBookmarkSearch(newText: String?) { |
|
|
|
if (newText.isNullOrBlank()) { |
|
|
|
if (newText.isNullOrBlank()) { |
|
|
|
initData() |
|
|
|
viewModel.bookData.value?.let { |
|
|
|
|
|
|
|
initData(it) |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bookmarkLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookmarkLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookmarkLiveData = LivePagedListBuilder( |
|
|
|
bookmarkLiveData = LivePagedListBuilder( |
|
|
|