mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
Merge pull request #2872 from Isira-Seneviratne/parseAsHtml
Use parseAsHtml() extension.
This commit is contained in:
commit
fef76e3be1
@ -7,7 +7,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.parseAsHtml
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -67,10 +67,7 @@ class CommentsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
commentInfos.text = comment.author + TextUtils.SEPARATOR + comment.commentedTime
|
commentInfos.text = comment.author + TextUtils.SEPARATOR + comment.commentedTime
|
||||||
commentText.text = HtmlCompat.fromHtml(
|
commentText.text = comment.commentText.parseAsHtml()
|
||||||
comment.commentText,
|
|
||||||
HtmlCompat.FROM_HTML_MODE_LEGACY
|
|
||||||
)
|
|
||||||
|
|
||||||
ImageHelper.loadImage(comment.thumbnail, commentorImage)
|
ImageHelper.loadImage(comment.thumbnail, commentorImage)
|
||||||
likesTextView.text = comment.likeCount.formatShort()
|
likesTextView.text = comment.likeCount.formatShort()
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package com.github.libretube.ui.extensions
|
|
||||||
|
|
||||||
import android.text.util.Linkify
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.core.text.HtmlCompat
|
|
||||||
|
|
||||||
fun TextView.setFormattedHtml(text: String) {
|
|
||||||
Linkify.addLinks(this, Linkify.WEB_URLS)
|
|
||||||
this.text = HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)
|
|
||||||
}
|
|
@ -31,7 +31,7 @@ import androidx.constraintlayout.motion.widget.MotionLayout
|
|||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.os.ConfigurationCompat
|
import androidx.core.os.ConfigurationCompat
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.parseAsHtml
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
@ -1033,12 +1033,8 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
// detect whether the description is html formatted
|
// detect whether the description is html formatted
|
||||||
if (description.contains("<") && description.contains(">")) {
|
if (description.contains("<") && description.contains(">")) {
|
||||||
descTextView.movementMethod = LinkMovementMethod.getInstance()
|
descTextView.movementMethod = LinkMovementMethod.getInstance()
|
||||||
descTextView.text = HtmlCompat.fromHtml(
|
descTextView.text = description
|
||||||
description,
|
.parseAsHtml(tagHandler = HtmlParser(LinkHandler(this::handleLink)))
|
||||||
HtmlCompat.FROM_HTML_MODE_LEGACY,
|
|
||||||
null,
|
|
||||||
HtmlParser(LinkHandler { link -> handleLink(link) })
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
// Links can be present as plain text
|
// Links can be present as plain text
|
||||||
descTextView.autoLinkMask = Linkify.WEB_URLS
|
descTextView.autoLinkMask = Linkify.WEB_URLS
|
||||||
|
@ -8,10 +8,11 @@ import android.view.View
|
|||||||
import org.xml.sax.Attributes
|
import org.xml.sax.Attributes
|
||||||
|
|
||||||
class LinkHandler(
|
class LinkHandler(
|
||||||
private val clickCallback: ((String) -> Unit)?
|
private val clickCallback: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
private var linkTagStartIndex = -1
|
private var linkTagStartIndex = -1
|
||||||
private var link: String? = null
|
private var link: String? = null
|
||||||
|
|
||||||
fun handleTag(
|
fun handleTag(
|
||||||
opening: Boolean,
|
opening: Boolean,
|
||||||
tag: String?,
|
tag: String?,
|
||||||
@ -38,7 +39,7 @@ class LinkHandler(
|
|||||||
output.setSpan(
|
output.setSpan(
|
||||||
object : ClickableSpan() {
|
object : ClickableSpan() {
|
||||||
override fun onClick(widget: View) {
|
override fun onClick(widget: View) {
|
||||||
clickCallback?.invoke(link)
|
clickCallback(link)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateDrawState(ds: TextPaint) {
|
override fun updateDrawState(ds: TextPaint) {
|
||||||
|
@ -9,6 +9,7 @@ import android.util.TypedValue
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
|
import androidx.core.text.parseAsHtml
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.github.libretube.ui.adapters.IconsSheetAdapter
|
import com.github.libretube.ui.adapters.IconsSheetAdapter
|
||||||
@ -133,9 +134,7 @@ object ThemeHelper {
|
|||||||
fun getStyledAppName(context: Context): Spanned {
|
fun getStyledAppName(context: Context): Spanned {
|
||||||
val colorPrimary = getThemeColor(context, R.attr.colorPrimaryDark)
|
val colorPrimary = getThemeColor(context, R.attr.colorPrimaryDark)
|
||||||
val hexColor = String.format("#%06X", (0xFFFFFF and colorPrimary))
|
val hexColor = String.format("#%06X", (0xFFFFFF and colorPrimary))
|
||||||
return HtmlCompat.fromHtml(
|
return "Libre<span style='color:$hexColor';>Tube</span>"
|
||||||
"Libre<span style='color:$hexColor';>Tube</span>",
|
.parseAsHtml(HtmlCompat.FROM_HTML_MODE_COMPACT)
|
||||||
HtmlCompat.FROM_HTML_MODE_COMPACT
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user