pull/1814/head
kunfei 3 years ago
parent 45d55a1b2d
commit dfcc1c5397
  1. 33
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
  4. 63
      app/src/main/java/io/legado/app/ui/widget/PopupAction.kt
  5. 21
      app/src/main/res/layout/popup_action.xml

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

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

@ -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<String, Bitmap>(cacheSize) {
val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) {
override fun sizeOf(key: String, bitmap: Bitmap): Int {
return bitmap.byteCount
}

@ -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<SelectItem<String>>) {
adapter.setItems(items)
}
inner class Adapter(context: Context) :
RecyclerAdapter<SelectItem<String>, ItemTextBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemTextBinding {
return ItemTextBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemTextBinding,
item: SelectItem<String>,
payloads: MutableList<Any>
) {
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)
}
}
}
}
}

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_card_view"
android:orientation="vertical"
android:padding="5dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
app:flexDirection="row"
app:flexWrap="wrap"
app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager" />
</LinearLayout>
Loading…
Cancel
Save