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.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

View File

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

View File

@ -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" />