pull/1630/head
kunfei 3 years ago
parent 2dc41a9f08
commit 88e9de47a5
  1. 31
      app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  4. 20
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt

@ -9,9 +9,12 @@ import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.DialogContentEditBinding import io.legado.app.databinding.DialogContentEditBinding
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor import io.legado.app.help.ContentProcessor
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.model.webBook.WebBook 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.setBackgroundColor(primaryColor)
binding.toolBar.title = ReadBook.curTextChapter?.title binding.toolBar.title = ReadBook.curTextChapter?.title
initMenu() 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 { viewModel.initContent {
binding.contentView.setText(it) 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) { class ContentEditViewModel(application: Application) : BaseViewModel(application) {
var content: String? = null var content: String? = null

@ -11,6 +11,10 @@ import io.legado.app.databinding.ItemFilletTextBinding
class BookAdapter(context: Context, val callBack: CallBack) : class BookAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<Book, ItemFilletTextBinding>(context) { RecyclerAdapter<Book, ItemFilletTextBinding>(context) {
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding { override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding {
return ItemFilletTextBinding.inflate(inflater, parent, false) return ItemFilletTextBinding.inflate(inflater, parent, false)
} }

@ -13,6 +13,10 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
private val explosionField = ExplosionField.attach2Window(activity) private val explosionField = ExplosionField.attach2Window(activity)
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding { override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding {
return ItemFilletTextBinding.inflate(inflater, parent, false) return ItemFilletTextBinding.inflate(inflater, parent, false)
} }

@ -42,8 +42,16 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
override val viewModel by viewModels<SearchViewModel>() override val viewModel by viewModels<SearchViewModel>()
private val adapter by lazy { SearchAdapter(this, this) } private val adapter by lazy { SearchAdapter(this, this) }
private val bookAdapter by lazy { BookAdapter(this, this) } private val bookAdapter by lazy {
private val historyKeyAdapter by lazy { HistoryKeyAdapter(this, this) } 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 loadMoreView by lazy { LoadMoreView(this) }
private val searchView: SearchView by lazy { private val searchView: SearchView by lazy {
binding.titleBar.findViewById(R.id.search_view) binding.titleBar.findViewById(R.id.search_view)
@ -196,16 +204,16 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
upGroupMenu() upGroupMenu()
} }
} }
viewModel.searchBookLiveData.observe(this, { viewModel.searchBookLiveData.observe(this) {
upSearchItems(it) upSearchItems(it)
}) }
viewModel.isSearchLiveData.observe(this, { viewModel.isSearchLiveData.observe(this) {
if (it) { if (it) {
startSearch() startSearch()
} else { } else {
searchFinally() searchFinally()
} }
}) }
} }
private fun receiptIntent(intent: Intent? = null) { private fun receiptIntent(intent: Intent? = null) {

Loading…
Cancel
Save