Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions odesli/src/main/java/com/prochy/odesliandroid/activity/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,7 @@ fun OdesliLayout() {
strokeCap = StrokeCap.Round
)
if (receivedLinks) {
val thumbnail = songData.entitiesByUniqueId[outputService]?.thumbnailUrl
val title = songData.entitiesByUniqueId[outputService]?.title
val artist = songData.entitiesByUniqueId[outputService]?.artistName
val service = getLabelFromService(outputService)
val link = songData.linksByPlatform[outputService]?.url
val type = songData.entitiesByUniqueId[songData.entitiesByUniqueId.keys.first()]?.type ?: ""

Utils.SongInfo(
thumbnail = thumbnail.toString(),
title = title.toString(),
artist = artist.toString(),
service = service.toString(),
link = link.toString(),
odesliType = type
)
Utils.SongInfoFromData(songData, outputService)
}
}

Expand Down
25 changes: 9 additions & 16 deletions odesli/src/main/java/com/prochy/odesliandroid/activity/Share.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ class Share : ComponentActivity() {
).show()
finish()
}
val platformLink = data.linksByPlatform[service]?.url
if (!platformLink.isNullOrBlank()) {

val serviceLink = Utils.getLinkForService(data, service)
if (!serviceLink.isNullOrBlank()) {
val clipboard = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Link", platformLink)
val clip = ClipData.newPlainText("Link", serviceLink)
clipboard.setPrimaryClip(clip)
finish()
} else {
Expand Down Expand Up @@ -326,19 +327,10 @@ fun ShareActivityLayout(receivedLink: String) {
}

val musicServices = MusicProviders.entries.map { it.service }
val thumbnail = receivedData.value.entitiesByUniqueId[outputService]?.thumbnailUrl
val title = receivedData.value.entitiesByUniqueId[outputService]?.title
val artist = receivedData.value.entitiesByUniqueId[outputService]?.artistName
val service = getLabelFromService(outputService)
val link = receivedData.value.linksByPlatform[outputService]?.url
val type = receivedData.value.entitiesByUniqueId[receivedData.value.entitiesByUniqueId.keys.first()]?.type ?: ""
Utils.SongInfo(
thumbnail = thumbnail.toString(),
title = title.toString(),
artist = artist.toString(),
service = service.toString(),
link = link.toString(),
odesliType = type,

Utils.SongInfoFromData(
receivedData.value,
outputService,
element = {
DynamicSelectTextFieldPopUp(
modifier = Modifier.width(350.dp),
Expand All @@ -351,6 +343,7 @@ fun ShareActivityLayout(receivedLink: String) {
)
}
)

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.annotation.Keep
// Enum class representing different music services
@Keep
enum class MusicProviders(val label: String, val service: String) {
SongLink("SongLink", "SONG_LINK"),
AmazonMusic("Amazon Music", "amazonMusic"),
AmazonStore("Amazon Appstore", "amazonStore"),
Anghami("Anghami", "anghami"),
Expand Down
64 changes: 64 additions & 0 deletions odesli/src/main/java/com/prochy/odesliandroid/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,45 @@ import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import coil.size.Size
import com.prochy.odesliandroid.R
import com.prochy.odesliandroid.utils.MusicProviders.Companion.getLabelFromService

class Utils {
companion object {

/// prioritized list of music providers that get used if the selected music provider doesn't have any metadata
private val fallbackMusicProviders = listOf(
MusicProviders.Spotify,
MusicProviders.AppleMusic,
MusicProviders.YoutubeMusic,
MusicProviders.Deezer,
)

/// adds song metadata extracted from the given [songData] for the given [service]
@Composable
fun SongInfoFromData(
songData: OdesliData,
service: String,
element: @Composable () -> Unit = {},
) {
val entriesData = getEntriesDataFor(songData, service)
val thumbnail = entriesData?.thumbnailUrl
val title = entriesData?.title
val artist = entriesData?.artistName
val serviceLabel = getLabelFromService(service)
val link = getLinkForService(songData, service)
val type = songData.entitiesByUniqueId[songData.entitiesByUniqueId.keys.first()]?.type ?: ""

SongInfo(
thumbnail = thumbnail.toString(),
title = title.toString(),
artist = artist.toString(),
service = serviceLabel.toString(),
link = link.toString(),
odesliType = type,
element = element,
)
}

@Composable
fun SongInfo(
thumbnail: String,
Expand Down Expand Up @@ -261,6 +297,34 @@ class Utils {
startActivity(context, browserIntent, null)
}

private fun getEntriesDataFor(songData: OdesliData, service: String) : EntitiesData? {
val matchingData = songData.entitiesByUniqueId[service]
if(matchingData != null) {
return matchingData
}
// if [service] doesn't have metadata then go through the fallbackMusicProviders
// and use the first one that has metadata
for (fallbackMusicProvider in fallbackMusicProviders) {
val potentialFallbackData = songData.entitiesByUniqueId[fallbackMusicProvider.service]
if(potentialFallbackData != null) {
return potentialFallbackData
}
}
if(songData.entitiesByUniqueId.isNotEmpty()) {
return songData.entitiesByUniqueId[songData.entitiesByUniqueId.keys.first()]
}
return null
}

fun getLinkForService(data: OdesliData, service: String): String? {
// if the selected service is "SongLink" then we return the SongLink URL
if(service == MusicProviders.SongLink.service) {
return data.pageUrl
}
val serviceSpecificLink = data.linksByPlatform[service] ?: return null
return serviceSpecificLink.url
}

fun getMusicData(link: String, context: Context, callback: (OdesliData) -> Unit) {

fun retroFitRequest(countryCode: String) {
Expand Down