From 21f941c64b36ae45fbffa8835f9e8ffff25360b6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 11 Sep 2020 16:07:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=8C=E6=99=AF=E9=85=8D=E7=BD=AE=E8=87=AA?= =?UTF-8?q?=E7=94=B1=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/config/ReadStyleDialog.kt | 24 ++++++++++++++++--- .../app/ui/widget/image/CircleImageView.kt | 13 +++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 5696a638d..12201ae29 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -31,7 +31,7 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { val callBack get() = activity as? ReadBookActivity - lateinit var styleAdapter: StyleAdapter + private lateinit var styleAdapter: StyleAdapter override fun onStart() { super.onStart() @@ -88,6 +88,18 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { dsb_paragraph_spacing.valueFormat = { (it / 10f).toString() } styleAdapter = StyleAdapter() rv_style.adapter = styleAdapter + val footerView = LayoutInflater.from(requireContext()) + .inflate(R.layout.item_read_style, rv_style, false) + footerView.iv_style.setPadding(6.dp, 6.dp, 6.dp, 6.dp) + footerView.iv_style.setText(null) + footerView.iv_style.setColorFilter(textColor) + footerView.iv_style.borderColor = textColor + footerView.iv_style.setImageResource(R.drawable.ic_add) + styleAdapter.addFooterView(footerView) + footerView.onClick { + ReadBookConfig.configList.add(ReadBookConfig.Config()) + showBgTextConfig(ReadBookConfig.configList.lastIndex) + } } private fun initData() { @@ -251,10 +263,16 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { iv_style.onClick { - changeBg(holder.layoutPosition) + if (iv_style.isInView) { + changeBg(holder.layoutPosition) + } } iv_style.onLongClick { - showBgTextConfig(holder.layoutPosition) + if (iv_style.isInView) { + showBgTextConfig(holder.layoutPosition) + } else { + false + } } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt index 661992931..43e3f5506 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt @@ -119,6 +119,7 @@ class CircleImageView(context: Context, attrs: AttributeSet) : private var textColor = context.getCompatColor(R.color.primaryText) private var textBold = false + var isInView = false init { super.setScaleType(SCALE_TYPE) @@ -223,6 +224,11 @@ class CircleImageView(context: Context, attrs: AttributeSet) : } } + fun setText(text: String?) { + this.text = text + invalidate() + } + fun setTextColor(@ColorInt textColor: Int) { this.textColor = textColor invalidate() @@ -422,7 +428,12 @@ class CircleImageView(context: Context, attrs: AttributeSet) : @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent): Boolean { - return inTouchableArea(event.x, event.y) && super.onTouchEvent(event) + when (event.action) { + MotionEvent.ACTION_DOWN -> { + isInView = (inTouchableArea(event.x, event.y)) + } + } + return super.onTouchEvent(event) } private fun inTouchableArea(x: Float, y: Float): Boolean {