feat(android): a history page

History sits second in the navigation, as on the desktop: every played
episode, newest first, under Today, Yesterday, a weekday or a date. The
still plays the episode, the text opens its title, and the cross takes
it off the page — forgetting its position and watched mark — with Undo.

The list is the desktop's Library::history rule over the records the
library already holds, so no bridge call is added; HistoryTest pins the
rule and the day headings.
This commit is contained in:
nvrl committed 2026-10-03 05:23:26 +02:00
1 parent 8d40b211ed
commit 1c61aadb22
7 files changed
+275 -2

No files matched your search

@@ -0,0 +1,55 @@
package io.narl.protonstream.ui
import java.time.LocalDate
import java.util.Locale
import org.junit.Assert.assertEquals
import org.junit.Test
import uniffi.pstr_android.EpisodeRecord
import uniffi.pstr_android.SeasonRecord
import uniffi.pstr_android.TitleRecord
import uniffi.pstr_android.TitleType
class HistoryTest {
private fun episode(link: String, watched: Boolean, progress: Double?, lastPlayed: Long) = EpisodeRecord(
shareId = "s", volumeId = "v", linkId = link, name = "$link.mkv", label = link, detail = "$link.mkv",
season = 1u, number = null, size = null, progress = progress, resumeAt = progress?.let { it * 1000 },
watched = watched, offline = false, providerName = null, providerOverview = null, stillUrl = null,
airDate = null, lastPlayed = lastPlayed,
)
private fun title(key: String, vararg episodes: EpisodeRecord) = TitleRecord(
key = key, name = key, year = null, kind = TitleType.SERIES, watchedCount = 0uL,
episodeCount = episodes.size.toULong(), canonicalName = null, originalName = null, overview = null,
metadataProvider = null, metadataId = null, metadataYear = null, metadataKind = null, posterUrl = null,
backdropUrl = null, rating = null, genres = emptyList(), providerEpisodeCount = null, externalUrl = null,
manualMatch = false, seasons = listOf(SeasonRecord(1u, "Season 1", episodes.toList())),
)
@Test
fun `history is every started or finished episode, newest first, across titles`() {
val titles = listOf(
title(
"a",
episode("a1", watched = true, progress = 1.0, lastPlayed = 30),
// Marked unwatched again: a row at zero, which is not a play.
episode("a2", watched = false, progress = 0.0, lastPlayed = 40),
episode("a3", watched = false, progress = null, lastPlayed = 0),
),
title("b", episode("b1", watched = false, progress = 0.4, lastPlayed = 50)),
)
val played = history(titles)
assertEquals(listOf("b1", "a1"), played.map { it.episode.linkId })
assertEquals(0, played.last().index)
}
@Test
fun `days are headed relative to today, then by date`() {
val today = LocalDate.of(2026, 10, 3) // a Saturday
val english = Locale.ENGLISH
assertEquals("Today", dayHeading(today, today, english))
assertEquals("Yesterday", dayHeading(today.minusDays(1), today, english))
assertEquals("Monday", dayHeading(LocalDate.of(2026, 9, 28), today, english))
assertEquals("26 September", dayHeading(LocalDate.of(2026, 9, 26), today, english))
assertEquals("3 October 2025", dayHeading(LocalDate.of(2025, 10, 3), today, english))
}
}
@@ -14,6 +14,8 @@ import androidx.work.testing.WorkManagerTestInitHelper
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.captureRoboImage
import io.narl.protonstream.ui.theme.ProtonStreamTheme
import java.time.LocalDate
import java.time.ZoneOffset
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -98,6 +100,13 @@ class ScreenshotTest {
SettingsScreen(LIBRARY, { _, _, _, _ -> }, {}, {}, {}, PaddingValues())
}
@Test
fun `the history page`() = capture("history-phone") {
// Fixed day and zone: "Today" and "Yesterday" are relative, and an
// image that changes with the date is no baseline.
HistoryScreen(LIBRARY, { _, _ -> }, {}, { _, _ -> }, PaddingValues(), ZoneOffset.UTC, LocalDate.of(2026, 9, 21))
}
@Test
fun `the downloads page with nothing offline`() = capture("downloads-empty") {
DownloadsScreen(LIBRARY, {}, {}, {}, {}, PaddingValues())
@@ -129,7 +138,12 @@ class ScreenshotTest {
providerOverview = null,
stillUrl = null,
airDate = null,
lastPlayed = if (progress != null) 1_790_000_000L else 0L,
// 2026-09-21 for the part-watched one, the day before for the rest.
lastPlayed = when {
progress != null -> 1_790_000_000L
watched -> 1_789_900_000L - number.toLong() * 600
else -> 0L
},
)
fun title(key: String, name: String, seasons: List<SeasonRecord>, overview: String? = null) = TitleRecord(