优化书签功能

pull/293/head
gedoor 4 years ago
parent 550295632c
commit c6c6ffe742
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt
  2. 11
      app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkAdapter.kt
  3. 43
      app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkFragment.kt
  4. 3
      app/src/main/res/layout/item_bookmark.xml

@ -24,6 +24,9 @@ interface BookmarkDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg bookmark: Bookmark)
@Update
fun update(bookmark: Bookmark)
@Delete
fun delete(vararg bookmark: Bookmark)

@ -1,6 +1,5 @@
package io.legado.app.ui.book.chapterlist
import android.os.AsyncTask.execute
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -47,19 +46,17 @@ class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, Bookm
tv_chapter_name.text = bookmark.chapterName
tv_content.text = bookmark.content
itemView.onClick {
callback?.open(bookmark)
callback?.onClick(bookmark)
}
itemView.onLongClick {
execute {
callback?.delBookmark(bookmark)
}
callback?.onLongClick(bookmark)
true
}
}
}
interface Callback {
fun open(bookmark: Bookmark)
fun delBookmark(bookmark: Bookmark)
fun onClick(bookmark: Bookmark)
fun onLongClick(bookmark: Bookmark)
}
}

@ -1,9 +1,12 @@
package io.legado.app.ui.book.chapterlist
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.os.AsyncTask
import android.os.Bundle
import android.view.View
import android.widget.EditText
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
@ -13,9 +16,16 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.data.entities.Bookmark
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.requestInputMethod
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.fragment_bookmark.*
@ -68,7 +78,8 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
}
}
override fun open(bookmark: Bookmark) {
override fun onClick(bookmark: Bookmark) {
val bookmarkData = Intent()
bookmarkData.putExtra("index", bookmark.chapterIndex)
bookmarkData.putExtra("pageIndex", bookmark.pageIndex)
@ -76,7 +87,33 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
activity?.finish()
}
override fun delBookmark(bookmark: Bookmark) {
App.db.bookmarkDao().delete(bookmark)
@SuppressLint("InflateParams")
override fun onLongClick(bookmark: Bookmark) {
viewModel.book?.let { book ->
requireContext().alert(R.string.bookmark) {
var editText: EditText? = null
message = book.name + "" + bookmark.chapterName
customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
editText = edit_view.apply {
setHint(R.string.note_content)
setText(bookmark.content)
}
}
}
yesButton {
editText?.text?.toString()?.let { editContent ->
AsyncTask.execute {
bookmark.content = editContent
App.db.bookmarkDao().update(bookmark)
}
}
}
noButton()
neutralButton(R.string.delete) {
App.db.bookmarkDao().delete(bookmark)
}
}.show().applyTint().requestInputMethod()
}
}
}

@ -3,18 +3,21 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="?android:attr/selectableItemBackground">
<TextView
android:id="@+id/tv_chapter_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:singleLine="true" />
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:textSize="12sp"
android:singleLine="true" />

Loading…
Cancel
Save