chore: Minor code cleanups and use #toUri instead of Uri#parse

This commit is contained in:
Bnyro 2023-07-11 12:46:29 +02:00
parent 2c08668a9b
commit 88acb79725
5 changed files with 10 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import kotlinx.serialization.Transient
@Serializable
data class ChapterSegment(
val title: String,
val image: String,
val image: String = "",
val start: Long,
// Used only for video highlights
@Transient var drawable: Drawable? = null

View File

@ -1,8 +1,8 @@
package com.github.libretube.ui.activities
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.core.net.toUri
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.util.PlayingQueue
@ -14,7 +14,7 @@ class AddToQueueActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val uri = Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)!!)
val uri = intent.getStringExtra(Intent.EXTRA_TEXT)!!.toUri()
var videoId: String? = null
listOf("/shorts/", "/v/", "/embed/").forEach {
if (uri.path!!.contains(it)) {

View File

@ -5,6 +5,7 @@ import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.core.net.toUri
import com.github.libretube.constants.IntentData
import com.github.libretube.extensions.TAG
import com.github.libretube.helpers.NavigationHelper
@ -16,7 +17,7 @@ class RouterActivity : BaseActivity() {
super.onCreate(savedInstanceState)
if (intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
// start processing the given text
handleSendText(Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)!!))
handleSendText(intent.getStringExtra(Intent.EXTRA_TEXT)!!.toUri())
} else if (intent.data != null) {
// link shared as text to the app
handleSendText(intent.data!!)

View File

@ -2,8 +2,8 @@ package com.github.libretube.ui.dialogs
import android.app.Dialog
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.core.net.toUri
import androidx.fragment.app.DialogFragment
import com.github.libretube.R
import com.github.libretube.obj.update.UpdateInfo
@ -19,8 +19,7 @@ class UpdateAvailableDialog(
.setMessage(context?.getString(R.string.update_available_text))
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(context?.getString(R.string.okay)) { _, _ ->
val uri = Uri.parse(updateInfo.htmlUrl)
val intent = Intent(Intent.ACTION_VIEW).setData(uri)
val intent = Intent(Intent.ACTION_VIEW).setData(updateInfo.htmlUrl.toUri())
startActivity(intent)
}
.show()

View File

@ -660,10 +660,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
if (!exoPlayer.isPlaying || !PlayerHelper.sponsorBlockEnabled) return
handler.postDelayed(this::checkForSegments, 100)
if (!sponsorBlockEnabled) return
if (segments.isEmpty()) return
if (!sponsorBlockEnabled || segments.isEmpty()) return
exoPlayer.checkForSegments(requireContext(), segments, sponsorBlockConfig)
?.let { segmentEnd ->
@ -1045,12 +1042,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
* Handle a link clicked in the description
*/
private fun handleLink(link: String) {
val uri = Uri.parse(link)
// get video id if the link is a valid youtube video link
val videoId = TextUtils.getVideoIdFromUri(link)
if (videoId.isNullOrEmpty()) {
// not a YouTube video link, thus handle normally
val intent = Intent(Intent.ACTION_VIEW, uri)
val intent = Intent(Intent.ACTION_VIEW, link.toUri())
startActivity(intent)
return
}
@ -1058,7 +1054,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// check if the video is the current video and has a valid time
if (videoId == this.videoId) {
// try finding the time stamp of the url and seek to it if found
uri.getQueryParameter("t")?.toTimeInSeconds()?.let {
link.toUri().getQueryParameter("t")?.toTimeInSeconds()?.let {
exoPlayer.seekTo(it * 1000)
}
} else {
@ -1159,7 +1155,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
}.drawable ?: return
val highlightChapter = ChapterSegment(
title = getString(R.string.chapters_videoHighlight),
image = "",
start = highlight.segmentStartAndEnd.first.toLong(),
drawable = drawable
)