Add share button for YouTube albums and playlists

This commit is contained in:
vfsfitvnm 2022-06-06 19:29:16 +02:00
parent 4d5af502cc
commit b11d5d30d0
3 changed files with 40 additions and 3 deletions

View file

@ -1,5 +1,6 @@
package it.vfsfitvnm.vimusic.ui.screens
import android.content.Intent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
@ -13,6 +14,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
@ -76,6 +78,7 @@ fun PlaylistOrAlbumScreen(
}
host {
val context = LocalContext.current
val density = LocalDensity.current
val player = LocalYoutubePlayer.current
val colorPalette = LocalColorPalette.current
@ -184,6 +187,24 @@ fun PlaylistOrAlbumScreen(
}
}
)
MenuEntry(
icon = R.drawable.share_social,
text = "Share",
onClick = {
menuState.hide()
playlistOrAlbum.valueOrNull?.url?.let { url ->
val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, url)
}
context.startActivity(Intent.createChooser(sendIntent, null))
}
}
)
}
}
}

View file

@ -589,7 +589,8 @@ object YouTube {
val authors: List<Info<NavigationEndpoint.Endpoint.Browse>>?,
val year: String?,
val thumbnail: ThumbnailRenderer.MusicThumbnailRenderer.Thumbnail.Thumbnail?,
val items: List<Item>?
val items: List<Item>?,
val url: String?
) {
open class Item(
val info: Info<NavigationEndpoint.Endpoint.Watch>,
@ -686,7 +687,11 @@ object YouTube {
?.firstOrNull()
)
}
?.filter { it.info.endpoint != null }
?.filter { it.info.endpoint != null },
url = body
.microformat
?.microformatDataRenderer
?.urlCanonical
)
}
}

View file

@ -6,7 +6,8 @@ import kotlinx.serialization.Serializable
@Serializable
data class BrowseResponse(
val contents: Contents,
val header: Header?
val header: Header?,
val microformat: Microformat?
) {
@Serializable
data class Contents(
@ -46,4 +47,14 @@ data class BrowseResponse(
)
}
}
@Serializable
data class Microformat(
val microformatDataRenderer: MicroformatDataRenderer?
) {
@Serializable
data class MicroformatDataRenderer(
val urlCanonical: String?
)
}
}