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.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
*/

@ -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)
}
}

@ -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)
}
}

Loading…
Cancel
Save