pull/1705/head
kunfei 3 years ago
parent 49785f97a1
commit 24a4db9e7c
  1. 13
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkDialog.kt
  2. 9
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt

@ -59,6 +59,7 @@ class BookmarkDialog() : BaseDialogFragment(R.layout.dialog_bookmark) {
withContext(IO) {
appDb.bookmarkDao.insert(bookmark)
}
getCallback()?.upBookmark(editPos, bookmark)
dismiss()
}
}
@ -67,11 +68,23 @@ class BookmarkDialog() : BaseDialogFragment(R.layout.dialog_bookmark) {
withContext(IO) {
appDb.bookmarkDao.delete(bookmark)
}
getCallback()?.deleteBookmark(editPos)
dismiss()
}
}
}
}
fun getCallback(): Callback? {
return parentFragment as? Callback
}
interface Callback {
fun upBookmark(pos: Int, bookmark: Bookmark)
fun deleteBookmark(pos: Int)
}
}

@ -24,6 +24,7 @@ import kotlinx.coroutines.withContext
class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark),
BookmarkAdapter.Callback,
BookmarkDialog.Callback,
TocViewModel.BookmarkCallBack {
override val viewModel by activityViewModels<TocViewModel>()
private val binding by viewBinding(FragmentBookmarkBinding::bind)
@ -85,4 +86,12 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark
override fun onLongClick(bookmark: Bookmark) {
showDialogFragment(BookmarkDialog(bookmark))
}
override fun upBookmark(pos: Int, bookmark: Bookmark) {
adapter.setItem(pos, bookmark)
}
override fun deleteBookmark(pos: Int) {
adapter.removeItem(pos)
}
}
Loading…
Cancel
Save