Skip to content

Native Android client for Spotify, built with Jetpack Compose

Recents: a play whose context row was not announced is listed as its own row instead of dropped

kota-zo30e0e6d36043
diff --git a/base/api/src/main/kotlin/app/myspoti/api/Recents.kt b/base/api/src/main/kotlin/app/myspoti/api/Recents.kt
index 45db6b81..f0dfff87 100644
--- a/base/api/src/main/kotlin/app/myspoti/api/Recents.kt
+++ b/base/api/src/main/kotlin/app/myspoti/api/Recents.kt
@@ -90,18 +90,18 @@ fun groupRecents(entries: List<RecentEntry>): List<RecentSection> {
openPlays += entry.item
continue
}
- // No group key at all: the server gave this row on its own, so it is its own row.
- if (group == null) {
- closeOpen()
- rows += RecentGroup(
- context = entry.item,
- count = 1,
- saved = entry.saved,
- music = entry.music,
- plays = listOf(entry.item),
- dayMs = entry.item.playedAtMs,
- )
- }
+ // No group key at all, or a key no open context announced (a page that starts mid-group, a
+ // play listed away from its context): the row is its own, never dropped. A keyed stray
+ // leaves the open group as it is, so the plays that follow still join it.
+ if (group == null) closeOpen()
+ rows += RecentGroup(
+ context = entry.item,
+ count = 1,
+ saved = entry.saved,
+ music = entry.music,
+ plays = listOf(entry.item),
+ dayMs = entry.item.playedAtMs,
+ )
}
closeOpen()
diff --git a/base/app/src/test/java/com/music/spotui/ui/screens/RecentsGroupingTest.kt b/base/app/src/test/java/com/music/spotui/ui/screens/RecentsGroupingTest.kt
index c993e8e8..11e600cc 100644
--- a/base/app/src/test/java/com/music/spotui/ui/screens/RecentsGroupingTest.kt
+++ b/base/app/src/test/java/com/music/spotui/ui/screens/RecentsGroupingTest.kt
@@ -133,6 +133,27 @@ class RecentsGroupingTest {
assertEquals(1, groups[1].count)
}
+ @Test
+ fun aPlayWhoseContextWasNotAnnouncedStaysItsOwnRow() {
+ // A page that starts mid-group (the context row sits on the page before), or a play filed
+ // under another group than the open one: the play is listed, not dropped.
+ val sections = groupRecents(
+ listOf(
+ play("spotify:track:orphan", "9"),
+ context("spotify:album:ep", MediaKind.ALBUM, "1", count = 2),
+ play("spotify:track:a", "1"),
+ play("spotify:track:stray", "8"),
+ play("spotify:track:b", "1"),
+ ),
+ )
+ val groups = sections.single().groups
+ assertEquals(
+ listOf("spotify:track:orphan", "spotify:track:stray", "spotify:album:ep"),
+ groups.map { it.context.uri },
+ )
+ assertEquals(listOf("spotify:track:a", "spotify:track:b"), groups.last().plays.map { it.uri })
+ }
+
@Test
fun daysAreSectionsNewestFirst() {
val sections = groupRecents(