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 f24c07831..8abced44f 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 @@ -1,10 +1,12 @@ package io.legado.app.ui.book.read import android.app.Application +import android.content.DialogInterface import android.os.Bundle import android.view.View import android.view.ViewGroup import androidx.fragment.app.viewModels +import androidx.lifecycle.MutableLiveData import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseViewModel @@ -15,6 +17,7 @@ import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.book.BookHelp import io.legado.app.help.book.ContentProcessor import io.legado.app.help.book.isLocal +import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor import io.legado.app.model.ReadBook @@ -53,6 +56,13 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) { editTitle(chapter) } } + viewModel.loadStateLiveData.observe(viewLifecycleOwner) { + if (it) { + binding.rlLoading.show() + } else { + binding.rlLoading.hide() + } + } viewModel.initContent { binding.contentView.setText(it) binding.contentView.post { @@ -70,17 +80,8 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) { binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.setOnMenuItemClickListener { when (it.itemId) { - R.id.menu_save -> launch { - binding.contentView.text?.toString()?.let { content -> - withContext(IO) { - val book = ReadBook.book ?: return@withContext - val chapter = appDb.bookChapterDao - .getChapter(book.bookUrl, ReadBook.durChapterIndex) - ?: return@withContext - BookHelp.saveText(book, chapter, content) - } - } - ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false) + R.id.menu_save -> { + save() dismiss() } R.id.menu_reset -> viewModel.initContent(true) { content -> @@ -113,8 +114,25 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) { } } - class ContentEditViewModel(application: Application) : BaseViewModel(application) { + override fun onCancel(dialog: DialogInterface) { + super.onCancel(dialog) + save() + } + private fun save() { + val content = binding.contentView.text?.toString() ?: return + Coroutine.async { + val book = ReadBook.book ?: return@async + val chapter = appDb.bookChapterDao + .getChapter(book.bookUrl, ReadBook.durChapterIndex) + ?: return@async + BookHelp.saveText(book, chapter, content) + ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false) + } + } + + class ContentEditViewModel(application: Application) : BaseViewModel(application) { + val loadStateLiveData = MutableLiveData() var content: String? = null fun initContent(reset: Boolean = false, success: (String) -> Unit) { @@ -136,9 +154,13 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) { contentProcessor.getContent(book, chapter, content, includeTitle = false) .joinToString("\n") } + }.onStart { + loadStateLiveData.postValue(true) }.onSuccess { content = it success.invoke(it ?: "") + }.onFinally { + loadStateLiveData.postValue(false) } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt index 6a68ad846..15cb4aa78 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt @@ -2,19 +2,43 @@ package io.legado.app.ui.book.search import android.os.Bundle import android.view.View +import android.view.ViewGroup import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.databinding.DialogSearchScopeBinding +import io.legado.app.lib.theme.primaryColor +import io.legado.app.utils.setLayout +import io.legado.app.utils.viewbindingdelegate.viewBinding -class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope, true) { +class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) { + private val binding by viewBinding(DialogSearchScopeBinding::bind) val callback: Callback get() { return parentFragment as? Callback ?: activity as Callback } + override fun onStart() { + super.onStart() + setLayout(0.9f, ViewGroup.LayoutParams.WRAP_CONTENT) + } + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + binding.toolBar.setBackgroundColor(primaryColor) + initOtherView() + } + private fun initOtherView() { + binding.tvCancel.setOnClickListener { + dismiss() + } + binding.tvAllSource.setOnClickListener { + callback.onSearchScopeOk(SearchScope("")) + } + binding.tvOk.setOnClickListener { + callback.onSearchScopeOk(SearchScope("")) + } } diff --git a/app/src/main/res/layout/dialog_content_edit.xml b/app/src/main/res/layout/dialog_content_edit.xml index 34c7caa81..ad0546d92 100644 --- a/app/src/main/res/layout/dialog_content_edit.xml +++ b/app/src/main/res/layout/dialog_content_edit.xml @@ -1,8 +1,8 @@ - @@ -11,14 +11,27 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="?attr/actionBarStyle" - app:title="edit" app:popupTheme="@style/AppTheme.PopupOverlay" - app:titleTextAppearance="@style/ToolbarTitle" /> + app:title="edit" + app:titleTextAppearance="@style/ToolbarTitle" + app:layout_constraintTop_toTopOf="parent" /> + android:layout_height="0dp" + android:padding="12dp" + app:layout_constraintTop_toBottomOf="@+id/tool_bar" + app:layout_constraintBottom_toBottomOf="parent" /> + + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_search_scope.xml b/app/src/main/res/layout/dialog_search_scope.xml index 63d12a49d..7ba164d9b 100644 --- a/app/src/main/res/layout/dialog_search_scope.xml +++ b/app/src/main/res/layout/dialog_search_scope.xml @@ -1,7 +1,115 @@ + android:layout_height="match_parent" + android:background="@color/background"> + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_toc_regex.xml b/app/src/main/res/layout/dialog_toc_regex.xml index 2712cabf4..f78ec5297 100644 --- a/app/src/main/res/layout/dialog_toc_regex.xml +++ b/app/src/main/res/layout/dialog_toc_regex.xml @@ -39,7 +39,7 @@ android:text="@string/cancel" tools:ignore="RtlHardcoded" /> -