From bdfe417aeab8b085fac9c67c0823f280acee3dd4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 16 Apr 2022 12:53:45 +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/ReadBookActivity.kt | 8 +++++ .../app/ui/book/read/page/ContentTextView.kt | 19 +++++++----- .../app/ui/widget/dialog/PhotoDialog.kt | 30 +++++++------------ 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index b19e7325b..19bcb14d0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -60,6 +60,7 @@ import io.legado.app.ui.dict.DictDialog import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.replace.ReplaceRuleActivity import io.legado.app.ui.replace.edit.ReplaceEditActivity +import io.legado.app.ui.widget.dialog.PhotoDialog import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO @@ -950,6 +951,13 @@ class ReadBookActivity : BaseReadBookActivity(), } } + /** + * 长按图片 + */ + override fun onImageLongPress(src: String) { + showDialogFragment(PhotoDialog(src)) + } + /** * colorSelectDialog */ diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index cda8d3e5d..3a54564ff 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -19,8 +19,10 @@ import io.legado.app.ui.book.read.page.entities.TextPos import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.ui.book.read.page.provider.TextPageFactory -import io.legado.app.ui.widget.dialog.PhotoDialog -import io.legado.app.utils.* +import io.legado.app.utils.activity +import io.legado.app.utils.getCompatColor +import io.legado.app.utils.getPrefBoolean +import io.legado.app.utils.toastOnUi import kotlin.math.min /** @@ -217,16 +219,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } /** - * + * 长按 */ fun longPress( x: Float, y: Float, select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit, ) { - touch(x, y) { _, relativePos, textPage, lineIndex, _, charIndex, textChar -> + touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar -> if (textChar.isImage) { - activity?.showDialogFragment(PhotoDialog(textPage.chapterIndex, textChar.charData)) + callBack.onImageLongPress(textChar.charData) } else { if (!selectAble) return@touch textChar.selected = true @@ -459,12 +461,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } interface CallBack { - fun upSelectedStart(x: Float, y: Float, top: Float) - fun upSelectedEnd(x: Float, y: Float) - fun onCancelSelect() val headerHeight: Int val pageFactory: TextPageFactory val isScroll: Boolean var isSelectingSearchResult: Boolean + fun upSelectedStart(x: Float, y: Float, top: Float) + fun upSelectedEnd(x: Float, y: Float) + fun onCancelSelect() + fun onImageLongPress(src: String) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt index 7d76b2a9a..49f624f38 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt @@ -17,19 +17,12 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding */ class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) { - constructor(chapterIndex: Int, src: String) : this() { + constructor(src: String) : this() { arguments = Bundle().apply { - putInt("chapterIndex", chapterIndex) putString("src", src) } } - constructor(path: String) : this() { - arguments = Bundle().apply { - putString("path", path) - } - } - private val binding by viewBinding(DialogPhotoViewBinding::bind) override fun onStart() { @@ -38,19 +31,16 @@ class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) { } override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { - arguments?.let { - val path = it.getString("path") - if (path.isNullOrEmpty()) { - ReadBook.book?.let { book -> - it.getString("src")?.let { src -> - val file = BookHelp.getImage(book, src) - ImageLoader.load(requireContext(), file) - .error(R.drawable.image_loading_error) - .into(binding.photoView) - } - } + arguments?.getString("src")?.let { src -> + val file = ReadBook.book?.let { book -> + BookHelp.getImage(book, src) + } + if (file?.exists() == true) { + ImageLoader.load(requireContext(), file) + .error(R.drawable.image_loading_error) + .into(binding.photoView) } else { - BookCover.load(requireContext(), path = path) + BookCover.load(requireContext(), path = src) .into(binding.photoView) } }