pull/2424/head
kunfei 2 years ago
parent 74d6e90124
commit bbac3e59d8
  1. 46
      app/src/main/java/io/legado/app/ui/book/read/ContentEditDialog.kt
  2. 26
      app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt
  3. 27
      app/src/main/res/layout/dialog_content_edit.xml
  4. 110
      app/src/main/res/layout/dialog_search_scope.xml
  5. 2
      app/src/main/res/layout/dialog_toc_regex.xml

@ -1,10 +1,12 @@
package io.legado.app.ui.book.read package io.legado.app.ui.book.read
import android.app.Application import android.app.Application
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.MutableLiveData
import io.legado.app.R 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
@ -15,6 +17,7 @@ import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.book.BookHelp import io.legado.app.help.book.BookHelp
import io.legado.app.help.book.ContentProcessor import io.legado.app.help.book.ContentProcessor
import io.legado.app.help.book.isLocal 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.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
@ -53,6 +56,13 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) {
editTitle(chapter) editTitle(chapter)
} }
} }
viewModel.loadStateLiveData.observe(viewLifecycleOwner) {
if (it) {
binding.rlLoading.show()
} else {
binding.rlLoading.hide()
}
}
viewModel.initContent { viewModel.initContent {
binding.contentView.setText(it) binding.contentView.setText(it)
binding.contentView.post { binding.contentView.post {
@ -70,17 +80,8 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) {
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
binding.toolBar.setOnMenuItemClickListener { binding.toolBar.setOnMenuItemClickListener {
when (it.itemId) { when (it.itemId) {
R.id.menu_save -> launch { R.id.menu_save -> {
binding.contentView.text?.toString()?.let { content -> save()
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)
dismiss() dismiss()
} }
R.id.menu_reset -> viewModel.initContent(true) { content -> 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<Boolean>()
var content: String? = null var content: String? = null
fun initContent(reset: Boolean = false, success: (String) -> Unit) { 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) contentProcessor.getContent(book, chapter, content, includeTitle = false)
.joinToString("\n") .joinToString("\n")
} }
}.onStart {
loadStateLiveData.postValue(true)
}.onSuccess { }.onSuccess {
content = it content = it
success.invoke(it ?: "") success.invoke(it ?: "")
}.onFinally {
loadStateLiveData.postValue(false)
} }
} }

@ -2,19 +2,43 @@ package io.legado.app.ui.book.search
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment 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 val callback: Callback
get() { get() {
return parentFragment as? Callback ?: activity as Callback 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?) { 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(""))
}
} }

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/background" android:background="@color/background"
android:orientation="vertical"> android:orientation="vertical">
@ -11,14 +11,27 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="?attr/actionBarStyle" android:theme="?attr/actionBarStyle"
app:title="edit"
app:popupTheme="@style/AppTheme.PopupOverlay" app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextAppearance="@style/ToolbarTitle" /> app:title="edit"
app:titleTextAppearance="@style/ToolbarTitle"
app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.lib.theme.view.ThemeEditText <io.legado.app.lib.theme.view.ThemeEditText
android:id="@+id/content_view" android:id="@+id/content_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
android:padding="12dp" /> android:padding="12dp"
app:layout_constraintTop_toBottomOf="@+id/tool_bar"
app:layout_constraintBottom_toBottomOf="parent" />
<io.legado.app.ui.widget.anima.RotateLoading
android:id="@+id/rl_loading"
android:layout_width="60dp"
android:layout_height="60dp"
android:visibility="invisible"
app:layout_constraintTop_toBottomOf="@+id/tool_bar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -1,7 +1,115 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="@color/background">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_menu"
android:elevation="5dp"
android:theme="?attr/actionBarStyle"
app:displayHomeAsUp="false"
app:fitStatusBar="false"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/search_scope"
app:titleTextAppearance="@style/ToolbarTitle" />
<RadioGroup
android:id="@+id/rg_scope"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="11dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@+id/tool_bar">
<io.legado.app.lib.theme.view.ThemeRadioNoButton
android:id="@+id/rb_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:padding="5dp"
android:singleLine="true"
android:checked="true"
android:text="@string/group"
app:isBottomBackground="true" />
<io.legado.app.lib.theme.view.ThemeRadioNoButton
android:id="@+id/rb_source"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:padding="5dp"
android:singleLine="true"
android:text="@string/book_source"
app:isBottomBackground="true" />
</RadioGroup>
<io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@+id/ll_bottom_bar"
app:layout_constraintTop_toBottomOf="@+id/rg_scope" />
<LinearLayout
android:id="@+id/ll_bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:id="@+id/tv_all_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:padding="12dp"
android:text="@string/all_source"
tools:ignore="RtlHardcoded" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:padding="12dp"
android:text="@string/cancel"
tools:ignore="RtlHardcoded" />
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:padding="12dp"
android:text="@string/ok"
tools:ignore="RtlHardcoded" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -39,7 +39,7 @@
android:text="@string/cancel" android:text="@string/cancel"
tools:ignore="RtlHardcoded" /> tools:ignore="RtlHardcoded" />
<TextView <io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_ok" android:id="@+id/tv_ok"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

Loading…
Cancel
Save