pull/1172/head
gedoor 3 years ago
parent 9c60381310
commit 751b0d234c
  1. 24
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  2. 86
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkDialog.kt
  3. 30
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt
  4. 91
      app/src/main/res/layout/dialog_bookmark.xml

@ -12,16 +12,13 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst.charsets
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ActivityBookReadBinding
import io.legado.app.databinding.DialogBookmarkBinding
import io.legado.app.databinding.DialogDownloadChoiceBinding
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.LocalConfig
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH
@ -32,8 +29,8 @@ import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.config.BgTextConfigDialog
import io.legado.app.ui.book.read.config.ClickActionConfigDialog
import io.legado.app.ui.book.read.config.PaddingConfigDialog
import io.legado.app.ui.book.toc.BookmarkDialog
import io.legado.app.utils.getPrefString
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding
/**
@ -199,24 +196,7 @@ abstract class ReadBookBaseActivity :
@SuppressLint("InflateParams")
fun showBookMark(bookmark: Bookmark) {
alert(title = getString(R.string.bookmark_add)) {
setMessage(bookmark.chapterName)
val alertBinding = DialogBookmarkBinding.inflate(layoutInflater).apply {
editBookText.setText(bookmark.bookText)
editView.setText(bookmark.content)
}
customView { alertBinding.root }
yesButton {
alertBinding.apply {
Coroutine.async {
bookmark.bookText = editBookText.text.toString()
bookmark.content = editView.text.toString()
appDb.bookmarkDao.insert(bookmark)
}
}
}
noButton()
}.show().requestInputMethod()
BookmarkDialog.start(supportFragmentManager, bookmark)
}
fun showCharsetConfig() {

@ -0,0 +1,86 @@
package io.legado.app.ui.book.toc
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.lifecycleScope
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.data.appDb
import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.DialogBookmarkBinding
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class BookmarkDialog : BaseDialogFragment() {
companion object {
fun start(fragmentManager: FragmentManager, bookmark: Bookmark) {
BookmarkDialog().apply {
arguments = Bundle().apply {
putParcelable("bookmark", bookmark)
}
}.show(fragmentManager, "bookMarkDialog")
}
}
private val binding by viewBinding(DialogBookmarkBinding::bind)
override fun onStart() {
super.onStart()
dialog?.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.dialog_bookmark, container)
}
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
val bookmark = arguments?.getParcelable<Bookmark>("bookmark")
bookmark ?: let {
dismiss()
return
}
binding.run {
tvChapterName.text = bookmark.chapterName
editBookText.setText(bookmark.bookText)
editContent.setText(bookmark.content)
tvCancel.setOnClickListener {
dismiss()
}
tvOk.setOnClickListener {
bookmark.bookText = editBookText.text?.toString() ?: ""
bookmark.content = editContent.text?.toString() ?: ""
lifecycleScope.launch {
withContext(IO) {
appDb.bookmarkDao.insert(bookmark)
}
dismiss()
}
}
tvFooterLeft.setOnClickListener {
lifecycleScope.launch {
withContext(IO) {
appDb.bookmarkDao.delete(bookmark)
}
dismiss()
}
}
}
}
}

@ -11,13 +11,9 @@ import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.data.appDb
import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.DialogBookmarkBinding
import io.legado.app.databinding.FragmentBookmarkBinding
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
@ -73,30 +69,6 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark
}
override fun onLongClick(bookmark: Bookmark) {
requireContext().alert(R.string.bookmark) {
setMessage(bookmark.chapterName)
val alertBinding = DialogBookmarkBinding.inflate(layoutInflater).apply {
editBookText.setText(bookmark.bookText)
editView.setText(bookmark.content)
editBookText.textSize = 15f
editView.textSize = 15f
editBookText.maxLines = 6
editView.maxLines = 6
}
customView { alertBinding.root }
yesButton {
alertBinding.apply {
Coroutine.async {
bookmark.bookText = editBookText.text.toString()
bookmark.content = editView.text.toString()
appDb.bookmarkDao.insert(bookmark)
}
}
}
noButton()
neutralButton(R.string.delete) {
appDb.bookmarkDao.delete(bookmark)
}
}.show().requestInputMethod()
BookmarkDialog.start(childFragmentManager, bookmark)
}
}

@ -1,28 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout 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_height="match_parent"
android:layout_marginTop="48dp"
android:layout_marginBottom="48dp"
android:overScrollMode="ifContentScrolls">
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?attr/actionBarStyle"
app:title="@string/bookmark"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextAppearance="@style/ToolbarTitle" />
<TextView
android:id="@+id/tv_chapter_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="@color/primaryText" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:padding="16dp">
<io.legado.app.ui.widget.text.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="3dp"
android:paddingRight="16dp">
android:paddingTop="3dp">
<io.legado.app.ui.widget.text.EditText
android:id="@+id/edit_book_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="6"
android:hint="@string/content" />
</io.legado.app.ui.widget.text.TextInputLayout>
@ -30,19 +50,58 @@
<io.legado.app.ui.widget.text.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="3dp"
android:paddingRight="16dp">
android:paddingTop="3dp">
<io.legado.app.ui.widget.text.EditText
android:id="@+id/edit_view"
android:id="@+id/edit_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="6"
android:hint="@string/note_content" />
</io.legado.app.ui.widget.text.TextInputLayout>
</LinearLayout>
</ScrollView>
</androidx.core.widget.NestedScrollView>
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingRight="12dp"
app:flexWrap="wrap"
app:justifyContent="space_between">
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_footer_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="@string/delete"
tools:ignore="RtlHardcoded" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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:padding="12dp"
android:text="@string/ok"
tools:ignore="RtlHardcoded" />
</LinearLayout>
</com.google.android.flexbox.FlexboxLayout>
</LinearLayout>

Loading…
Cancel
Save