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 19bcb14d0..01c8b80cc 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 @@ -31,6 +31,7 @@ import io.legado.app.help.config.ReadTipConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.storage.AppWebDav import io.legado.app.help.storage.Backup +import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.accentColor @@ -50,6 +51,7 @@ import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_COLOR import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.ReadView import io.legado.app.ui.book.read.page.entities.PageDirection +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.searchContent.SearchContentActivity import io.legado.app.ui.book.searchContent.SearchResult @@ -60,6 +62,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.PopupAction import io.legado.app.ui.widget.dialog.PhotoDialog import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* @@ -131,7 +134,9 @@ class ReadBookActivity : BaseReadBookActivity(), val textActionMenu: TextActionMenu by lazy { TextActionMenu(this, this) } - + private val popupAction by lazy { + PopupAction(this) + } override val isInitFinish: Boolean get() = viewModel.isInitFinish override val isScroll: Boolean get() = binding.readView.isScroll private var keepScreenJon: Job? = null @@ -954,8 +959,29 @@ class ReadBookActivity : BaseReadBookActivity(), /** * 长按图片 */ - override fun onImageLongPress(src: String) { - showDialogFragment(PhotoDialog(src)) + override fun onImageLongPress(x: Float, y: Float, src: String) { + popupAction.setItems( + listOf( + SelectItem("查看", "show"), + SelectItem("刷新", "refresh") + ) + ) + popupAction.onActionClick = { + when (it) { + "show" -> showDialogFragment(PhotoDialog(src)) + "refresh" -> { + ImageProvider.bitmapLruCache.remove(src) + } + } + popupAction.dismiss() + } + val navigationBarHeight = + if (!ReadBookConfig.hideNavigationBar && navigationBarGravity == Gravity.BOTTOM) + navigationBarHeight else 0 + popupAction.showAtLocation( + binding.readView, Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL, x.toInt(), + binding.root.height + navigationBarHeight - y.toInt() + ) } /** @@ -1076,6 +1102,7 @@ class ReadBookActivity : BaseReadBookActivity(), override fun onDestroy() { super.onDestroy() textActionMenu.dismiss() + popupAction.dismiss() binding.readView.onDestroy() ReadBook.msg = null ReadBook.callBack = null 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 ea8aacc3f..936412622 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 @@ -228,7 +228,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ) { touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar -> if (textChar.isImage) { - callBack.onImageLongPress(textChar.charData) + callBack.onImageLongPress(x, y, textChar.charData) } else { if (!selectAble) return@touch textChar.selected = true @@ -467,7 +467,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at var isSelectingSearchResult: Boolean fun upSelectedStart(x: Float, y: Float, top: Float) fun upSelectedEnd(x: Float, y: Float) + fun onImageLongPress(x: Float, y: Float, src: String) fun onCancelSelect() - fun onImageLongPress(src: String) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index 9b5891cfb..3e7dda69c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -33,7 +33,7 @@ object ImageProvider { private const val M = 1024 * 1024 private val cacheSize = max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt())) - private val bitmapLruCache = object : LruCache(cacheSize) { + val bitmapLruCache = object : LruCache(cacheSize) { override fun sizeOf(key: String, bitmap: Bitmap): Int { return bitmap.byteCount } diff --git a/app/src/main/java/io/legado/app/ui/widget/PopupAction.kt b/app/src/main/java/io/legado/app/ui/widget/PopupAction.kt new file mode 100644 index 000000000..24d434355 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/PopupAction.kt @@ -0,0 +1,63 @@ +package io.legado.app.ui.widget + +import android.content.Context +import android.view.ViewGroup +import android.widget.PopupWindow +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.RecyclerAdapter +import io.legado.app.databinding.ItemTextBinding +import io.legado.app.databinding.PopupActionBinding +import io.legado.app.lib.dialogs.SelectItem +import splitties.systemservices.layoutInflater + +class PopupAction(private val context: Context) : + PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) { + + val binding = PopupActionBinding.inflate(context.layoutInflater) + val adapter by lazy { + Adapter(context) + } + var onActionClick: ((action: String) -> Unit)? = null + + init { + contentView = binding.root + + isTouchable = true + isOutsideTouchable = true + isFocusable = false + + binding.recyclerView.adapter = adapter + } + + fun setItems(items: List>) { + adapter.setItems(items) + } + + inner class Adapter(context: Context) : + RecyclerAdapter, ItemTextBinding>(context) { + + override fun getViewBinding(parent: ViewGroup): ItemTextBinding { + return ItemTextBinding.inflate(inflater, parent, false) + } + + override fun convert( + holder: ItemViewHolder, + binding: ItemTextBinding, + item: SelectItem, + payloads: MutableList + ) { + with(binding) { + textView.text = item.title + } + } + + override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) { + holder.itemView.setOnClickListener { + getItem(holder.layoutPosition)?.let { item -> + onActionClick?.invoke(item.value) + } + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/popup_action.xml b/app/src/main/res/layout/popup_action.xml new file mode 100644 index 000000000..56762ec63 --- /dev/null +++ b/app/src/main/res/layout/popup_action.xml @@ -0,0 +1,21 @@ + + + + + + +