mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-09-18 15:32:35 +00:00
Freeze fix when clicking link in description.
This commit is contained in:
parent
b93447f712
commit
5b50ac926e
2 changed files with 54 additions and 29 deletions
|
@ -8,11 +8,14 @@ import android.text.method.LinkMovementMethod
|
||||||
import android.text.style.URLSpan
|
import android.text.style.URLSpan
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.activities.MainActivity
|
import com.futo.platformplayer.activities.MainActivity
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.receivers.MediaControlReceiver
|
import com.futo.platformplayer.receivers.MediaControlReceiver
|
||||||
import com.futo.platformplayer.timestampRegex
|
import com.futo.platformplayer.timestampRegex
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class PlatformLinkMovementMethod(private val _context: Context) : LinkMovementMethod() {
|
class PlatformLinkMovementMethod(private val _context: Context) : LinkMovementMethod() {
|
||||||
|
|
||||||
|
@ -60,31 +63,39 @@ class PlatformLinkMovementMethod(private val _context: Context) : LinkMovementMe
|
||||||
val dx = event.x - downX
|
val dx = event.x - downX
|
||||||
val dy = event.y - downY
|
val dy = event.y - downY
|
||||||
if (Math.abs(dx) <= touchSlop && Math.abs(dy) <= touchSlop && isTouchInside(widget, event)) {
|
if (Math.abs(dx) <= touchSlop && Math.abs(dy) <= touchSlop && isTouchInside(widget, event)) {
|
||||||
runBlocking {
|
for (link in pressedLinks!!) {
|
||||||
for (link in pressedLinks!!) {
|
Logger.i(TAG) { "Link clicked '${link.url}'." }
|
||||||
Logger.i(TAG) { "Link clicked '${link.url}'." }
|
|
||||||
|
|
||||||
if (_context is MainActivity) {
|
val c = _context
|
||||||
if (_context.handleUrl(link.url)) continue
|
if (c is MainActivity) {
|
||||||
if (timestampRegex.matches(link.url)) {
|
c.lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val tokens = link.url.split(':')
|
if (c.handleUrl(link.url)) {
|
||||||
var time_s = -1L
|
return@launch
|
||||||
when (tokens.size) {
|
}
|
||||||
2 -> time_s = tokens[0].toLong() * 60 + tokens[1].toLong()
|
if (timestampRegex.matches(link.url)) {
|
||||||
3 -> time_s = tokens[0].toLong() * 3600 +
|
val tokens = link.url.split(':')
|
||||||
tokens[1].toLong() * 60 +
|
var time_s = -1L
|
||||||
tokens[2].toLong()
|
when (tokens.size) {
|
||||||
}
|
2 -> time_s = tokens[0].toLong() * 60 + tokens[1].toLong()
|
||||||
|
3 -> time_s = tokens[0].toLong() * 3600 +
|
||||||
|
tokens[1].toLong() * 60 +
|
||||||
|
tokens[2].toLong()
|
||||||
|
}
|
||||||
|
|
||||||
if (time_s != -1L) {
|
if (time_s != -1L) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
MediaControlReceiver.onSeekToReceived.emit(time_s * 1000)
|
MediaControlReceiver.onSeekToReceived.emit(time_s * 1000)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
return@launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
pressedLinks = null
|
pressedLinks = null
|
||||||
linkPressed = false
|
linkPressed = false
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -8,12 +8,16 @@ import android.text.Spannable
|
||||||
import android.text.style.URLSpan
|
import android.text.style.URLSpan
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.activities.MainActivity
|
import com.futo.platformplayer.activities.MainActivity
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.others.PlatformLinkMovementMethod
|
import com.futo.platformplayer.others.PlatformLinkMovementMethod
|
||||||
import com.futo.platformplayer.receivers.MediaControlReceiver
|
import com.futo.platformplayer.receivers.MediaControlReceiver
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.timestampRegex
|
import com.futo.platformplayer.timestampRegex
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class NonScrollingTextView : androidx.appcompat.widget.AppCompatTextView {
|
class NonScrollingTextView : androidx.appcompat.widget.AppCompatTextView {
|
||||||
private var _lastTouchedLinks: Array<URLSpan>? = null
|
private var _lastTouchedLinks: Array<URLSpan>? = null
|
||||||
|
@ -77,12 +81,14 @@ class NonScrollingTextView : androidx.appcompat.widget.AppCompatTextView {
|
||||||
val dx = event.x - downX
|
val dx = event.x - downX
|
||||||
val dy = event.y - downY
|
val dy = event.y - downY
|
||||||
if (Math.abs(dx) <= touchSlop && Math.abs(dy) <= touchSlop && isTouchInside(event)) {
|
if (Math.abs(dx) <= touchSlop && Math.abs(dy) <= touchSlop && isTouchInside(event)) {
|
||||||
runBlocking {
|
for (link in _lastTouchedLinks!!) {
|
||||||
for (link in _lastTouchedLinks!!) {
|
Logger.i(PlatformLinkMovementMethod.TAG) { "Link clicked '${link.url}'." }
|
||||||
Logger.i(PlatformLinkMovementMethod.TAG) { "Link clicked '${link.url}'." }
|
val c = context
|
||||||
val c = context
|
if (c is MainActivity) {
|
||||||
if (c is MainActivity) {
|
c.lifecycleScope.launch(Dispatchers.IO) {
|
||||||
if (c.handleUrl(link.url)) continue
|
if (c.handleUrl(link.url)) {
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
if (timestampRegex.matches(link.url)) {
|
if (timestampRegex.matches(link.url)) {
|
||||||
val tokens = link.url.split(':')
|
val tokens = link.url.split(':')
|
||||||
var time_s = -1L
|
var time_s = -1L
|
||||||
|
@ -92,13 +98,21 @@ class NonScrollingTextView : androidx.appcompat.widget.AppCompatTextView {
|
||||||
tokens[1].toLong() * 60 +
|
tokens[1].toLong() * 60 +
|
||||||
tokens[2].toLong()
|
tokens[2].toLong()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time_s != -1L) {
|
if (time_s != -1L) {
|
||||||
MediaControlReceiver.onSeekToReceived.emit(time_s * 1000)
|
withContext(Dispatchers.Main) {
|
||||||
continue
|
MediaControlReceiver.onSeekToReceived.emit(time_s * 1000)
|
||||||
|
}
|
||||||
|
return@launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
|
||||||
} else {
|
withContext(Dispatchers.Main) {
|
||||||
|
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
StateApp.instance.scopeOrNull?.launch(Dispatchers.Main) {
|
||||||
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue