mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Fix: Links in Description not clickable (Closes #91)
This commit is contained in:
parent
745d0dbfed
commit
d85fe7a128
@ -22,6 +22,7 @@ import android.view.Gravity
|
|||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
import androidx.appcompat.widget.LinearLayoutCompat
|
import androidx.appcompat.widget.LinearLayoutCompat
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
@ -52,6 +53,7 @@ import com.looker.droidify.utility.Utils
|
|||||||
import com.looker.droidify.utility.extension.android.*
|
import com.looker.droidify.utility.extension.android.*
|
||||||
import com.looker.droidify.utility.extension.resources.*
|
import com.looker.droidify.utility.extension.resources.*
|
||||||
import com.looker.droidify.utility.extension.text.*
|
import com.looker.droidify.utility.extension.text.*
|
||||||
|
import com.looker.droidify.widget.ClickableMovementMethod
|
||||||
import com.looker.droidify.widget.StableRecyclerAdapter
|
import com.looker.droidify.widget.StableRecyclerAdapter
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -406,7 +408,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
|
|||||||
|
|
||||||
private class TextViewHolder(context: Context) :
|
private class TextViewHolder(context: Context) :
|
||||||
RecyclerView.ViewHolder(MaterialTextView(context)) {
|
RecyclerView.ViewHolder(MaterialTextView(context)) {
|
||||||
val text: MaterialTextView
|
val text: TextView
|
||||||
get() = itemView as MaterialTextView
|
get() = itemView as MaterialTextView
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -414,6 +416,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
|
|||||||
itemView.setTextSizeScaled(15)
|
itemView.setTextSizeScaled(15)
|
||||||
itemView.setTextColor(itemView.context.getColorFromAttr(android.R.attr.textColor))
|
itemView.setTextColor(itemView.context.getColorFromAttr(android.R.attr.textColor))
|
||||||
itemView.resources.sizeScaled(16).let { itemView.setPadding(it, it, it, it) }
|
itemView.resources.sizeScaled(16).let { itemView.setPadding(it, it, it, it) }
|
||||||
|
itemView.movementMethod = ClickableMovementMethod
|
||||||
itemView.layoutParams = RecyclerView.LayoutParams(
|
itemView.layoutParams = RecyclerView.LayoutParams(
|
||||||
RecyclerView.LayoutParams.MATCH_PARENT,
|
RecyclerView.LayoutParams.MATCH_PARENT,
|
||||||
RecyclerView.LayoutParams.WRAP_CONTENT
|
RecyclerView.LayoutParams.WRAP_CONTENT
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.looker.droidify.widget
|
||||||
|
|
||||||
|
import android.text.Selection
|
||||||
|
import android.text.Spannable
|
||||||
|
import android.text.method.MovementMethod
|
||||||
|
import android.text.style.ClickableSpan
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.widget.TextView
|
||||||
|
|
||||||
|
object ClickableMovementMethod : MovementMethod {
|
||||||
|
override fun initialize(widget: TextView, text: Spannable) {
|
||||||
|
Selection.removeSelection(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTouchEvent(widget: TextView, text: Spannable, event: MotionEvent): Boolean {
|
||||||
|
val action = event.action
|
||||||
|
val down = action == MotionEvent.ACTION_DOWN
|
||||||
|
val up = action == MotionEvent.ACTION_UP
|
||||||
|
return (down || up) && run {
|
||||||
|
val x = event.x.toInt() - widget.totalPaddingLeft + widget.scrollX
|
||||||
|
val y = event.y.toInt() - widget.totalPaddingTop + widget.scrollY
|
||||||
|
val layout = widget.layout
|
||||||
|
val line = layout.getLineForVertical(y)
|
||||||
|
val offset = layout.getOffsetForHorizontal(line, x.toFloat())
|
||||||
|
val span = text.getSpans(offset, offset, ClickableSpan::class.java)?.firstOrNull()
|
||||||
|
if (span != null) {
|
||||||
|
if (down) {
|
||||||
|
Selection.setSelection(text, text.getSpanStart(span), text.getSpanEnd(span))
|
||||||
|
} else {
|
||||||
|
span.onClick(widget)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
Selection.removeSelection(text)
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onKeyDown(
|
||||||
|
widget: TextView,
|
||||||
|
text: Spannable,
|
||||||
|
keyCode: Int,
|
||||||
|
event: KeyEvent,
|
||||||
|
): Boolean = false
|
||||||
|
|
||||||
|
override fun onKeyUp(
|
||||||
|
widget: TextView,
|
||||||
|
text: Spannable,
|
||||||
|
keyCode: Int,
|
||||||
|
event: KeyEvent,
|
||||||
|
): Boolean = false
|
||||||
|
|
||||||
|
override fun onKeyOther(view: TextView, text: Spannable, event: KeyEvent): Boolean = false
|
||||||
|
override fun onTakeFocus(widget: TextView, text: Spannable, direction: Int) = Unit
|
||||||
|
override fun onTrackballEvent(widget: TextView, text: Spannable, event: MotionEvent): Boolean =
|
||||||
|
false
|
||||||
|
|
||||||
|
override fun onGenericMotionEvent(
|
||||||
|
widget: TextView,
|
||||||
|
text: Spannable,
|
||||||
|
event: MotionEvent,
|
||||||
|
): Boolean = false
|
||||||
|
|
||||||
|
override fun canSelectArbitrarily(): Boolean = false
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user