Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jeziellago authored Jul 16, 2024
2 parents f6eecb0 + 9198c58 commit 2e330c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@ import android.view.MotionEvent
import androidx.appcompat.widget.AppCompatTextView

class CustomTextView(context: Context) : AppCompatTextView(context) {

private var isTextSelectable: Boolean = false

override fun onTouchEvent(event: MotionEvent): Boolean {
performClick()
if (event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_DOWN) {
val link = getClickableSpans(event)

if (link.isNotEmpty()) {
if (event.action == MotionEvent.ACTION_UP) {
link[0].onClick(this)
if (isTextSelectable) {
return super.onTouchEvent(event)
} else {
if (event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_DOWN) {
val link = getClickableSpans(event)

if (link.isNotEmpty()) {
if (event.action == MotionEvent.ACTION_UP) {
link[0].onClick(this)
}
return true
}
return true
}
return false
}
return false
}

private fun getClickableSpans(event: MotionEvent): Array<ClickableSpan> {
Expand All @@ -43,4 +50,9 @@ class CustomTextView(context: Context) : AppCompatTextView(context) {
override fun performClick(): Boolean {
return super.performClick()
}

override fun setTextIsSelectable(selectable: Boolean) {
super.setTextIsSelectable(selectable)
isTextSelectable = selectable
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.jeziellago.compose.markdown

import android.os.Bundle
import android.text.util.Linkify
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -76,6 +77,17 @@ class MainActivity : AppCompatActivity() {
""".trimIndent(),
)
}
item {
MarkdownText(
markdown = """
## Selectable item
This is a selectable text. You can select this text by long pressing on it.
""".trimIndent(),
isTextSelectable = true
)
}
item {
MarkdownText(
markdown = """
Expand Down

0 comments on commit 2e330c4

Please sign in to comment.