Merge pull request #2080 from Kruna1Pate1/fix/link-open-issue

Fix link opening issues
This commit is contained in:
Bnyro 2022-11-26 14:48:56 +01:00 committed by GitHub
commit c6b1338aaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 16 deletions

View File

@ -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)
}

View File

@ -15,7 +15,6 @@ import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.os.PowerManager import android.os.PowerManager
import android.text.Html
import android.text.format.DateUtils import android.text.format.DateUtils
import android.util.Base64 import android.util.Base64
import android.util.Log 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.AddToPlaylistDialog
import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.DownloadDialog
import com.github.libretube.ui.dialogs.ShareDialog 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.setInvisible
import com.github.libretube.ui.extensions.setupSubscriptionButton import com.github.libretube.ui.extensions.setupSubscriptionButton
import com.github.libretube.ui.interfaces.OnlinePlayerOptions import com.github.libretube.ui.interfaces.OnlinePlayerOptions
@ -940,18 +940,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
initializeRelatedVideos(response.relatedStreams) initializeRelatedVideos(response.relatedStreams)
// set video description // set video description
val description = response.description!! val description = response.description!!
binding.playerDescription.text =
// detect whether the description is html formatted // detect whether the description is html formatted
if (description.contains("<") && description.contains(">")) { if (description.contains("<") && description.contains(">")) {
if (SDK_INT >= Build.VERSION_CODES.N) { binding.playerDescription.setFormattedHtml(description)
Html.fromHtml(description, Html.FROM_HTML_MODE_COMPACT)
.trim()
} else { } else {
@Suppress("DEPRECATION") binding.playerDescription.text = description
Html.fromHtml(description).trim()
}
} else {
description
} }
binding.playerChannel.setOnClickListener { binding.playerChannel.setOnClickListener {

View File

@ -53,7 +53,7 @@ class PlaylistFragment : BaseFragment() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
arguments?.let { arguments?.let {
playlistId = it.getString(IntentData.playlistId) playlistId = it.getString(IntentData.playlistId)
playlistType = it.serializable(IntentData.playlistType)!! playlistType = it.serializable(IntentData.playlistType) ?: PlaylistType.PUBLIC
} }
} }

View File

@ -125,7 +125,6 @@
android:id="@+id/player_description" android:id="@+id/player_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:autoLink="web"
android:padding="8dp" android:padding="8dp"
android:textIsSelectable="true" android:textIsSelectable="true"
android:textSize="14sp" /> android:textSize="14sp" />