From cf18adc75b06c28d940ccd0ba76fa067b924e803 Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Fri, 25 Nov 2022 23:20:00 +0530 Subject: [PATCH] Fix link opening issues --- .../ui/extensions/SetFormattedHtml.kt | 10 +++++++++ .../libretube/ui/fragments/PlayerFragment.kt | 22 +++++++------------ .../ui/fragments/PlaylistFragment.kt | 2 +- app/src/main/res/layout/fragment_player.xml | 1 - 4 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/ui/extensions/SetFormattedHtml.kt diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetFormattedHtml.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetFormattedHtml.kt new file mode 100644 index 000000000..bd9b0ee7d --- /dev/null +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetFormattedHtml.kt @@ -0,0 +1,10 @@ +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) +} diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 0eab64d17..f66f46550 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -15,7 +15,6 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.os.PowerManager -import android.text.Html import android.text.format.DateUtils import android.util.Base64 import android.util.Log @@ -73,6 +72,7 @@ import com.github.libretube.ui.base.BaseFragment import com.github.libretube.ui.dialogs.AddToPlaylistDialog import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.ShareDialog +import com.github.libretube.ui.extensions.setFormattedHtml import com.github.libretube.ui.extensions.setInvisible import com.github.libretube.ui.extensions.setupSubscriptionButton import com.github.libretube.ui.interfaces.OnlinePlayerOptions @@ -940,19 +940,13 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { initializeRelatedVideos(response.relatedStreams) // set video description val description = response.description!! - binding.playerDescription.text = - // detect whether the description is html formatted - if (description.contains("<") && description.contains(">")) { - if (SDK_INT >= Build.VERSION_CODES.N) { - Html.fromHtml(description, Html.FROM_HTML_MODE_COMPACT) - .trim() - } else { - @Suppress("DEPRECATION") - Html.fromHtml(description).trim() - } - } else { - description - } + + // detect whether the description is html formatted + if (description.contains("<") && description.contains(">")) { + binding.playerDescription.setFormattedHtml(description) + } else { + binding.playerDescription.text = description + } binding.playerChannel.setOnClickListener { val activity = view?.context as MainActivity diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index 8205dafdc..591a873b3 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -53,7 +53,7 @@ class PlaylistFragment : BaseFragment() { super.onCreate(savedInstanceState) arguments?.let { playlistId = it.getString(IntentData.playlistId) - playlistType = it.serializable(IntentData.playlistType)!! + playlistType = it.serializable(IntentData.playlistType) ?: PlaylistType.PUBLIC } } diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index dd944b6e9..9a9bb75db 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -125,7 +125,6 @@ android:id="@+id/player_description" android:layout_width="match_parent" android:layout_height="wrap_content" - android:autoLink="web" android:padding="8dp" android:textIsSelectable="true" android:textSize="14sp" />