pull/1794/head
kunfei 3 years ago
parent 7ff0b89718
commit bdfe417aea
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 19
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 30
      app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt

@ -60,6 +60,7 @@ import io.legado.app.ui.dict.DictDialog
import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.replace.ReplaceRuleActivity import io.legado.app.ui.replace.ReplaceRuleActivity
import io.legado.app.ui.replace.edit.ReplaceEditActivity 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.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -950,6 +951,13 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
} }
/**
* 长按图片
*/
override fun onImageLongPress(src: String) {
showDialogFragment(PhotoDialog(src))
}
/** /**
* colorSelectDialog * colorSelectDialog
*/ */

@ -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.ChapterProvider
import io.legado.app.ui.book.read.page.provider.ImageProvider 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.book.read.page.provider.TextPageFactory
import io.legado.app.ui.widget.dialog.PhotoDialog import io.legado.app.utils.activity
import io.legado.app.utils.* import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.toastOnUi
import kotlin.math.min import kotlin.math.min
/** /**
@ -217,16 +219,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
/** /**
* * 长按
*/ */
fun longPress( fun longPress(
x: Float, x: Float,
y: Float, y: Float,
select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit, 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) { if (textChar.isImage) {
activity?.showDialogFragment(PhotoDialog(textPage.chapterIndex, textChar.charData)) callBack.onImageLongPress(textChar.charData)
} else { } else {
if (!selectAble) return@touch if (!selectAble) return@touch
textChar.selected = true textChar.selected = true
@ -459,12 +461,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
interface CallBack { interface CallBack {
fun upSelectedStart(x: Float, y: Float, top: Float)
fun upSelectedEnd(x: Float, y: Float)
fun onCancelSelect()
val headerHeight: Int val headerHeight: Int
val pageFactory: TextPageFactory val pageFactory: TextPageFactory
val isScroll: Boolean val isScroll: Boolean
var isSelectingSearchResult: Boolean var isSelectingSearchResult: Boolean
fun upSelectedStart(x: Float, y: Float, top: Float)
fun upSelectedEnd(x: Float, y: Float)
fun onCancelSelect()
fun onImageLongPress(src: String)
} }
} }

@ -17,19 +17,12 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
*/ */
class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) { class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) {
constructor(chapterIndex: Int, src: String) : this() { constructor(src: String) : this() {
arguments = Bundle().apply { arguments = Bundle().apply {
putInt("chapterIndex", chapterIndex)
putString("src", src) putString("src", src)
} }
} }
constructor(path: String) : this() {
arguments = Bundle().apply {
putString("path", path)
}
}
private val binding by viewBinding(DialogPhotoViewBinding::bind) private val binding by viewBinding(DialogPhotoViewBinding::bind)
override fun onStart() { override fun onStart() {
@ -38,19 +31,16 @@ class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) {
} }
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
arguments?.let { arguments?.getString("src")?.let { src ->
val path = it.getString("path") val file = ReadBook.book?.let { book ->
if (path.isNullOrEmpty()) { BookHelp.getImage(book, src)
ReadBook.book?.let { book -> }
it.getString("src")?.let { src -> if (file?.exists() == true) {
val file = BookHelp.getImage(book, src) ImageLoader.load(requireContext(), file)
ImageLoader.load(requireContext(), file) .error(R.drawable.image_loading_error)
.error(R.drawable.image_loading_error) .into(binding.photoView)
.into(binding.photoView)
}
}
} else { } else {
BookCover.load(requireContext(), path = path) BookCover.load(requireContext(), path = src)
.into(binding.photoView) .into(binding.photoView)
} }
} }

Loading…
Cancel
Save