Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Implement library tags + rest of the collection item types
Browse files Browse the repository at this point in the history
Signed-off-by: iTaysonLab <[email protected]>
  • Loading branch information
iTaysonLab committed May 24, 2022
1 parent d91d776 commit 1f17ecc
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 69 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class SpCollectionWriter(
CollectionPinnedItem(
uri = AlbumId.fromHex(Utils.bytesToHex(album.gid)).toSpotifyUri(),
name = album.name,
subtitle = album.artistList.joinToString(",") { artist -> artist.name },
subtitle = album.artistList.joinToString { artist -> artist.name },
picture = bytesToPicUrl(album.coverGroup.imageList.first { it.size == Metadata.Image.Size.DEFAULT }.fileId),
addedAt = mappedRequest[AlbumId.fromHex(Utils.bytesToHex(album.gid)).toSpotifyUri()]!!
)
Expand Down Expand Up @@ -244,7 +244,7 @@ class SpCollectionWriter(
Log.d("SpCollectionWriter", "collection-insert [ins -> ${mappedRequest.keys.joinToString(",")}, del -> ${mappedDeleteRequest.values.joinToString(",")}]")

if (mappedRequest.isNotEmpty()) {
val metadata = getExtendedMetadata(mappedRequest.keys)
val metadata = getExtendedMetadata(mappedRequest.keys.toList())

val trackDescriptors = if (metadata.tracks.isNotEmpty()) {
// also request descriptors to get genre data
Expand Down Expand Up @@ -319,7 +319,9 @@ class SpCollectionWriter(
}
}

private suspend fun getExtendedMetadata(of: Iterable<String>): UnpackedMetadataResponse {
private suspend fun getExtendedMetadata(of: List<String>): UnpackedMetadataResponse {
if (of.isEmpty()) return UnpackedMetadataResponse(emptyList())

val requests = mutableListOf<ExtendedMetadata.EntityRequest>()

of.forEach { ci ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface LocalCollectionDao {
@Query("SELECT * from lcTracks WHERE mainArtistId = :id")
suspend fun getTracksByArtist(id: String): List<CollectionTrack>

@Query("SELECT * from lcPins ORDER BY addedAt DESC")
@Query("SELECT * from lcPins ORDER BY addedAt ASC")
suspend fun getPins(): List<CollectionPinnedItem>

@Query("SELECT * from rootlist ORDER BY timestamp DESC")
Expand Down Expand Up @@ -101,6 +101,9 @@ interface LocalCollectionDao {
@Query("SELECT * from lcTracks ORDER BY addedAt DESC")
suspend fun getTracks(): List<CollectionTrack>

@Query("SELECT COUNT(id) FROM lcTracks")
suspend fun trackCount(): Int

@RawQuery
suspend fun getTracksRaw(query: SupportSQLiteQuery): List<CollectionTrack>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ data class CollectionAlbum(
val addedAt: Int
): CollectionEntry {
override fun ceId() = id
override fun ceUri() = uri
override fun ceTimestamp() = addedAt.toLong()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ data class CollectionArtist(
val addedAt: Int
): CollectionEntry {
override fun ceId() = id
override fun ceUri() = uri
override fun ceTimestamp() = addedAt.toLong()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ package bruhcollective.itaysonlab.jetispot.core.collection.db.model2

interface CollectionEntry {
fun ceId(): String
fun ceUri(): String
fun ceTimestamp(): Long
fun ceModifyPredef(type: PredefCeType, dyn: String) {}
}

enum class PredefCeType {
COLLECTION, EPISODES
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ data class CollectionPinnedItem(
val picture: String,
val addedAt: Int
): CollectionEntry {
@Transient var predefType: PredefCeType? = null
@Transient var predefDyn: String = ""

override fun ceId() = uri
override fun ceUri() = uri
override fun ceTimestamp() = addedAt.toLong()

override fun ceModifyPredef(type: PredefCeType, dyn: String) {
predefType = type
predefDyn = dyn
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ data class CollectionRootlistItem(
val picture: String
): CollectionEntry {
override fun ceId() = uri
override fun ceUri() = uri
override fun ceTimestamp() = timestamp / 1000L
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Pin
import androidx.compose.material.icons.filled.PinDrop
import androidx.compose.material.icons.filled.PushPin
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import bruhcollective.itaysonlab.jetispot.core.collection.db.model2.CollectionEntry
import bruhcollective.itaysonlab.jetispot.core.collection.db.model2.CollectionPinnedItem
import bruhcollective.itaysonlab.jetispot.R
import bruhcollective.itaysonlab.jetispot.core.collection.db.model2.*
import bruhcollective.itaysonlab.jetispot.core.collection.db.model2.rootlist.CollectionRootlistItem
import bruhcollective.itaysonlab.jetispot.ui.shared.ImagePreview
import bruhcollective.itaysonlab.jetispot.ui.shared.PreviewableAsyncImage
import coil.compose.AsyncImage

Expand All @@ -32,6 +33,8 @@ fun YlRenderer(
when (item) {
is CollectionPinnedItem -> YLRPinned(item, modifier)
is CollectionRootlistItem -> YLRRootlist(item, modifier)
is CollectionAlbum -> YLRAlbum(item, modifier)
is CollectionArtist -> YLRArtist(item, modifier)
else -> Text(item.toString())
}
}
Expand All @@ -42,26 +45,61 @@ fun YLRPinned(
modifier: Modifier
) {
Row(modifier) {
AsyncImage(
model = "https://i.scdn.co/image/${item.picture}",
contentDescription = null,
modifier = Modifier
.size(64.dp).clip(RoundedCornerShape(8.dp))
)
val isPredef = item.predefType != null

if (isPredef) {
ImagePreview(
if (item.predefType == PredefCeType.COLLECTION) Icons.Default.Favorite else Icons.Default.Podcasts,
true,
modifier = Modifier
.size(64.dp)
.clip(RoundedCornerShape(8.dp))
)
} else {
if (item.picture.isEmpty()) {
ImagePreview(
Icons.Default.Photo,
false,
modifier = Modifier
.size(64.dp)
.clip(RoundedCornerShape(8.dp))
)
} else {
AsyncImage(
model = "https://i.scdn.co/image/${item.picture}",
contentDescription = null,
modifier = Modifier
.size(64.dp)
.clip(RoundedCornerShape(8.dp))
)
}
}

Column(
Modifier
.padding(start = 16.dp)
.align(Alignment.CenterVertically)) {
Text(text = item.name, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text(text = when (item.predefType) {
PredefCeType.COLLECTION -> stringResource(id = R.string.liked_songs)
PredefCeType.EPISODES -> stringResource(id = R.string.new_episodes)
null -> item.name
}, maxLines = 1, overflow = TextOverflow.Ellipsis)
Row(Modifier.padding(top = 4.dp)) {
Icon(Icons.Default.PushPin, tint = MaterialTheme.colorScheme.primary, contentDescription = null, modifier = Modifier.size(16.dp).align(Alignment.CenterVertically))
Icon(Icons.Default.PushPin, tint = MaterialTheme.colorScheme.primary, contentDescription = null, modifier = Modifier
.size(16.dp)
.align(Alignment.CenterVertically))
Text(
text = item.subtitle,
text = when (item.predefType) {
PredefCeType.COLLECTION -> stringResource(id = R.string.liked_songs_desc, item.predefDyn)
PredefCeType.EPISODES -> stringResource(id = R.string.new_episodes_desc, item.predefDyn)
null -> item.subtitle
},
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(start = 6.dp).align(Alignment.CenterVertically)
modifier = Modifier
.padding(start = 6.dp)
.align(Alignment.CenterVertically)
)
}
}
Expand All @@ -72,26 +110,79 @@ fun YLRPinned(
fun YLRRootlist(
item: CollectionRootlistItem,
modifier: Modifier
) {
YLRGenericItem(
picUrl = item.picture,
picCircle = false,
picPlaceholder = "playlist",
title = item.name,
subtitle = item.ownerUsername,
modifier = modifier
)
}

@Composable
fun YLRAlbum(
item: CollectionAlbum,
modifier: Modifier
) {
YLRGenericItem(
picUrl = "https://i.scdn.co/image/${item.picture}",
picCircle = false,
picPlaceholder = "album",
title = item.name,
subtitle = item.rawArtistsData.split("|").joinToString { it.split("=")[1] },
modifier = modifier
)
}

@Composable
fun YLRArtist(
item: CollectionArtist,
modifier: Modifier
) {
YLRGenericItem(
picUrl = "https://i.scdn.co/image/${item.picture}",
picCircle = true,
picPlaceholder = "artist",
title = item.name,
subtitle = null,
modifier = modifier
)
}

@Composable
fun YLRGenericItem(
picUrl: String,
picCircle: Boolean,
picPlaceholder: String,
title: String,
subtitle: String?,
modifier: Modifier
) {
Row(modifier) {
PreviewableAsyncImage(
imageUrl = item.picture,
placeholderType = "playlist",
modifier = Modifier.size(64.dp).clip(RoundedCornerShape(8.dp))
imageUrl = picUrl,
placeholderType = picPlaceholder,
modifier = Modifier
.size(64.dp)
.clip(if (picCircle) CircleShape else RoundedCornerShape(8.dp))
)

Column(
Modifier
.padding(start = 16.dp)
.align(Alignment.CenterVertically)) {
Text(text = item.name, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text(
text = item.ownerUsername,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(top = 4.dp)
)
Text(text = title, maxLines = 1, overflow = TextOverflow.Ellipsis)
if (!subtitle.isNullOrEmpty()) {
Text(
text = subtitle,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(top = 4.dp)
)
}
}
}
}
Loading

0 comments on commit 1f17ecc

Please sign in to comment.