mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Simplify LinkHandler
and HTMLParser
This commit is contained in:
parent
a5a38a3f66
commit
8ba2824750
@ -1076,7 +1076,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
if (videoId == this.videoId) {
|
||||
// try finding the time stamp of the url and seek to it if found
|
||||
TextUtils.getTimeInSeconds(uri)?.let {
|
||||
exoPlayer.seekTo(it)
|
||||
exoPlayer.seekTo(it * 1000)
|
||||
}
|
||||
} else {
|
||||
// youtube video link without time or not the current video, thus open new player
|
||||
|
@ -5,10 +5,11 @@ import android.text.Html
|
||||
import org.xml.sax.Attributes
|
||||
import org.xml.sax.ContentHandler
|
||||
import org.xml.sax.Locator
|
||||
import org.xml.sax.SAXException
|
||||
import org.xml.sax.XMLReader
|
||||
|
||||
class HtmlParser constructor(private val handler: LinkHandler) : Html.TagHandler, ContentHandler {
|
||||
class HtmlParser(
|
||||
private val handler: LinkHandler
|
||||
) : Html.TagHandler, ContentHandler {
|
||||
private val tagStatus = ArrayDeque<Boolean>()
|
||||
private var wrapped: ContentHandler? = null
|
||||
private var text: Editable? = null
|
||||
@ -25,7 +26,6 @@ class HtmlParser constructor(private val handler: LinkHandler) : Html.TagHandler
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun startElement(
|
||||
uri: String,
|
||||
localName: String,
|
||||
@ -40,7 +40,6 @@ class HtmlParser constructor(private val handler: LinkHandler) : Html.TagHandler
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun endElement(uri: String, localName: String, qName: String) {
|
||||
if (!tagStatus.removeLast()) {
|
||||
wrapped?.endElement(uri, localName, qName)
|
||||
@ -52,42 +51,34 @@ class HtmlParser constructor(private val handler: LinkHandler) : Html.TagHandler
|
||||
wrapped?.setDocumentLocator(locator)
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun startDocument() {
|
||||
wrapped?.startDocument()
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun endDocument() {
|
||||
wrapped?.endDocument()
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun startPrefixMapping(prefix: String, uri: String) {
|
||||
wrapped?.startPrefixMapping(prefix, uri)
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun endPrefixMapping(prefix: String) {
|
||||
wrapped?.endPrefixMapping(prefix)
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun characters(ch: CharArray, start: Int, length: Int) {
|
||||
wrapped?.characters(ch, start, length)
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun ignorableWhitespace(ch: CharArray, start: Int, length: Int) {
|
||||
wrapped?.ignorableWhitespace(ch, start, length)
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun processingInstruction(target: String, data: String) {
|
||||
wrapped?.processingInstruction(target, data)
|
||||
}
|
||||
|
||||
@Throws(SAXException::class)
|
||||
override fun skippedEntity(name: String) {
|
||||
wrapped?.skippedEntity(name)
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ import android.text.style.ClickableSpan
|
||||
import android.view.View
|
||||
import org.xml.sax.Attributes
|
||||
|
||||
class LinkHandler(private val clickCallback: ((String) -> Unit)?) {
|
||||
class LinkHandler(
|
||||
private val clickCallback: ((String) -> Unit)?
|
||||
) {
|
||||
private var linkTagStartIndex = -1
|
||||
private var link: String? = null
|
||||
fun handleTag(
|
||||
@ -17,22 +19,17 @@ class LinkHandler(private val clickCallback: ((String) -> Unit)?) {
|
||||
attributes: Attributes?
|
||||
): Boolean {
|
||||
// if the tag is not an anchor link, ignore for the default handler
|
||||
if (output == null || "a" != tag) {
|
||||
if (output == null || tag != "a") {
|
||||
return false
|
||||
}
|
||||
|
||||
if (opening) {
|
||||
if (attributes != null) {
|
||||
linkTagStartIndex = output.length
|
||||
link = attributes.getValue("href")
|
||||
}
|
||||
} else {
|
||||
if (linkTagStartIndex >= 0 && link != null) {
|
||||
setLinkSpans(output, linkTagStartIndex, output.length, link!!)
|
||||
|
||||
linkTagStartIndex = -1
|
||||
link = null
|
||||
}
|
||||
if (opening && attributes != null) {
|
||||
linkTagStartIndex = output.length
|
||||
link = attributes.getValue("href")
|
||||
} else if (!opening && linkTagStartIndex >= 0 && link != null) {
|
||||
setLinkSpans(output, linkTagStartIndex, output.length, link!!)
|
||||
linkTagStartIndex = -1
|
||||
link = null
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user