From 88e9de47a56e7c215e7d585641648611078d1246 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 18 Feb 2022 16:00:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ContentEditDialog.kt | 31 +++++++++++++++++++ .../legado/app/ui/book/search/BookAdapter.kt | 4 +++ .../app/ui/book/search/HistoryKeyAdapter.kt | 4 +++ .../app/ui/book/search/SearchActivity.kt | 20 ++++++++---- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt index 4c6d6dda7..06862ed4a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt @@ -9,9 +9,12 @@ import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseViewModel import io.legado.app.data.appDb +import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.DialogContentEditBinding +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.BookHelp import io.legado.app.help.ContentProcessor +import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor import io.legado.app.model.ReadBook import io.legado.app.model.webBook.WebBook @@ -39,6 +42,15 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) { binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.title = ReadBook.curTextChapter?.title initMenu() + binding.toolBar.setOnClickListener { + launch { + val book = ReadBook.book ?: return@launch + val chapter = withContext(IO) { + appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex) + } ?: return@launch + editTitle(chapter) + } + } viewModel.initContent { binding.contentView.setText(it) } @@ -71,6 +83,25 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) { } } + private fun editTitle(chapter: BookChapter) { + alert { + setTitle(R.string.edit) + val alertBinding = DialogEditTextBinding.inflate(layoutInflater) + alertBinding.editView.setText(chapter.title) + setCustomView(alertBinding.root) + okButton { + chapter.title = alertBinding.editView.text.toString() + launch { + withContext(IO) { + appDb.bookChapterDao.upDate(chapter) + } + binding.toolBar.title = chapter.getDisplayTitle() + ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false) + } + } + } + } + class ContentEditViewModel(application: Application) : BaseViewModel(application) { var content: String? = null diff --git a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt index 1aa9f0fff..91a312ddc 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt @@ -11,6 +11,10 @@ import io.legado.app.databinding.ItemFilletTextBinding class BookAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context) { + override fun getItemId(position: Int): Long { + return position.toLong() + } + override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding { return ItemFilletTextBinding.inflate(inflater, parent, false) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index f7bbd8297..731689762 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -13,6 +13,10 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : private val explosionField = ExplosionField.attach2Window(activity) + override fun getItemId(position: Int): Long { + return position.toLong() + } + override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding { return ItemFilletTextBinding.inflate(inflater, parent, false) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index f80163368..72ab2d6b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -42,8 +42,16 @@ class SearchActivity : VMBaseActivity() private val adapter by lazy { SearchAdapter(this, this) } - private val bookAdapter by lazy { BookAdapter(this, this) } - private val historyKeyAdapter by lazy { HistoryKeyAdapter(this, this) } + private val bookAdapter by lazy { + BookAdapter(this, this).apply { + setHasStableIds(true) + } + } + private val historyKeyAdapter by lazy { + HistoryKeyAdapter(this, this).apply { + setHasStableIds(true) + } + } private val loadMoreView by lazy { LoadMoreView(this) } private val searchView: SearchView by lazy { binding.titleBar.findViewById(R.id.search_view) @@ -196,16 +204,16 @@ class SearchActivity : VMBaseActivity