From c6c6ffe742cfcc4f3cd9119883cf2db6ae0d109b Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 2 Aug 2020 21:55:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B9=A6=E7=AD=BE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookmarkDao.kt | 3 ++ .../ui/book/chapterlist/BookmarkAdapter.kt | 11 ++--- .../ui/book/chapterlist/BookmarkFragment.kt | 43 +++++++++++++++++-- app/src/main/res/layout/item_bookmark.xml | 3 ++ 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt index cec2761b0..14e852352 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkAdapter.kt b/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkAdapter.kt index 05e3751c9..e9c7384ea 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkAdapter.kt @@ -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(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(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() + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_bookmark.xml b/app/src/main/res/layout/item_bookmark.xml index bd0ec0e11..971d56416 100644 --- a/app/src/main/res/layout/item_bookmark.xml +++ b/app/src/main/res/layout/item_bookmark.xml @@ -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">