添加所有书签界面

pull/1751/head
kunfei 3 years ago
parent a5f888ba4a
commit b94fb24174
  1. 21
      app/src/main/java/io/legado/app/ui/book/bookmark/AllBookmarkActivity.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/bookmark/AllBookmarkViewModel.kt
  3. 16
      app/src/main/java/io/legado/app/ui/book/bookmark/BookmarkAdapter.kt
  4. 5
      app/src/main/java/io/legado/app/ui/book/bookmark/BookmarkDialog.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  6. 1
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt

@ -3,15 +3,19 @@ package io.legado.app.ui.book.bookmark
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels import androidx.activity.viewModels
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ActivityAllBookmarkBinding import io.legado.app.databinding.ActivityAllBookmarkBinding
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
class AllBookmarkActivity : VMBaseActivity<ActivityAllBookmarkBinding, AllBookmarkViewModel>() { class AllBookmarkActivity : VMBaseActivity<ActivityAllBookmarkBinding, AllBookmarkViewModel>(),
BookmarkAdapter.Callback,
BookmarkDialog.Callback {
override val viewModel by viewModels<AllBookmarkViewModel>() override val viewModel by viewModels<AllBookmarkViewModel>()
override val binding by viewBinding(ActivityAllBookmarkBinding::inflate) override val binding by viewBinding(ActivityAllBookmarkBinding::inflate)
private val adapter by lazy { private val adapter by lazy {
BookmarkAdapter(this) BookmarkAdapter(this, this)
} }
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -26,5 +30,18 @@ class AllBookmarkActivity : VMBaseActivity<ActivityAllBookmarkBinding, AllBookma
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
} }
override fun onItemClick(bookmark: Bookmark, position: Int) {
showDialogFragment(BookmarkDialog(bookmark, position))
}
override fun upBookmark(pos: Int, bookmark: Bookmark) {
adapter.setItem(pos, bookmark)
}
override fun deleteBookmark(pos: Int) {
adapter.getItem(pos)?.let {
viewModel.deleteBookmark(it)
}
adapter.removeItem(pos)
}
} }

@ -16,4 +16,10 @@ class AllBookmarkViewModel(application: Application) : BaseViewModel(application
} }
} }
fun deleteBookmark(bookmark: Bookmark) {
execute {
appDb.bookmarkDao.delete(bookmark)
}
}
} }

@ -7,8 +7,10 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.Bookmark import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ItemBookmarkBinding import io.legado.app.databinding.ItemBookmarkBinding
import io.legado.app.utils.gone import io.legado.app.utils.gone
import splitties.views.onClick
class BookmarkAdapter(context: Context) : RecyclerAdapter<Bookmark, ItemBookmarkBinding>(context) { class BookmarkAdapter(context: Context, val callback: Callback) :
RecyclerAdapter<Bookmark, ItemBookmarkBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemBookmarkBinding { override fun getViewBinding(parent: ViewGroup): ItemBookmarkBinding {
return ItemBookmarkBinding.inflate(inflater, parent, false) return ItemBookmarkBinding.inflate(inflater, parent, false)
@ -28,7 +30,11 @@ class BookmarkAdapter(context: Context) : RecyclerAdapter<Bookmark, ItemBookmark
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemBookmarkBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemBookmarkBinding) {
binding.root.onClick {
getItemByLayoutPosition(holder.layoutPosition)?.let {
callback.onItemClick(it, holder.layoutPosition)
}
}
} }
fun getHeaderText(position: Int): String { fun getHeaderText(position: Int): String {
@ -45,4 +51,10 @@ class BookmarkAdapter(context: Context) : RecyclerAdapter<Bookmark, ItemBookmark
&& lastItem?.bookAuthor == curItem?.bookAuthor) && lastItem?.bookAuthor == curItem?.bookAuthor)
} }
interface Callback {
fun onItemClick(bookmark: Bookmark, position: Int)
}
} }

@ -1,4 +1,4 @@
package io.legado.app.ui.book.toc package io.legado.app.ui.book.bookmark
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
@ -76,7 +76,8 @@ class BookmarkDialog() : BaseDialogFragment(R.layout.dialog_bookmark) {
} }
private fun getCallback(): Callback? { private fun getCallback(): Callback? {
return parentFragment as? Callback return (parentFragment as? Callback)
?: activity as? Callback
} }
interface Callback { interface Callback {

@ -38,6 +38,7 @@ import io.legado.app.model.ReadBook
import io.legado.app.receiver.TimeBatteryReceiver import io.legado.app.receiver.TimeBatteryReceiver
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.bookmark.BookmarkDialog
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
import io.legado.app.ui.book.changesource.ChangeChapterSourceDialog import io.legado.app.ui.book.changesource.ChangeChapterSourceDialog
import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.*
@ -51,7 +52,6 @@ import io.legado.app.ui.book.read.page.provider.TextPageFactory
import io.legado.app.ui.book.searchContent.SearchContentActivity import io.legado.app.ui.book.searchContent.SearchContentActivity
import io.legado.app.ui.book.searchContent.SearchResult import io.legado.app.ui.book.searchContent.SearchResult
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.BookmarkDialog
import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.browser.WebViewActivity import io.legado.app.ui.browser.WebViewActivity
import io.legado.app.ui.dict.DictDialog import io.legado.app.ui.dict.DictDialog

@ -11,6 +11,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Bookmark import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.FragmentBookmarkBinding import io.legado.app.databinding.FragmentBookmarkBinding
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.book.bookmark.BookmarkDialog
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.setEdgeEffectColor import io.legado.app.utils.setEdgeEffectColor

Loading…
Cancel
Save