Fix Home navigation ownership and merge watch lanes
This commit is contained in:
parent
c2f7ccc438
commit
12c201dc55
41 changed files with 671 additions and 307 deletions
|
|
@ -0,0 +1,29 @@
|
|||
package com.github.damontecres.wholphin.services
|
||||
|
||||
import com.github.damontecres.wholphin.data.model.HomeRowConfig
|
||||
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
|
||||
import com.github.damontecres.wholphin.data.model.mergeHomeWatchRows
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
/** Legacy saved watch lanes retain the first lane's order and display options after merging. */
|
||||
class HomeWatchRowsTest {
|
||||
@Test fun splitAndAlreadyCombinedRowsBecomeOneWithoutChangingOtherPresets() {
|
||||
val options = HomeRowViewOptions(heightDp = 148)
|
||||
val other = HomeRowConfig.GetItems(name = "Saved shelf", filter = com.github.damontecres.wholphin.data.model.HomeGetItemsFilter())
|
||||
for (watchRows in listOf(
|
||||
listOf(HomeRowConfig.ContinueWatching(options), other, HomeRowConfig.NextUp()),
|
||||
listOf(HomeRowConfig.NextUp(options), other, HomeRowConfig.ContinueWatching()),
|
||||
listOf(HomeRowConfig.ContinueWatchingCombined(options), other, HomeRowConfig.NextUp()),
|
||||
)) {
|
||||
val result = mergeHomeWatchRows(watchRows)
|
||||
assertEquals(listOf(HomeRowConfig.ContinueWatchingCombined(options), other), result)
|
||||
assertEquals(result, mergeHomeWatchRows(result))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun settingsWithoutWatchRowsStayWithoutWatchRows() {
|
||||
val rows = listOf(HomeRowConfig.GetItems(name = "Saved shelf", filter = com.github.damontecres.wholphin.data.model.HomeGetItemsFilter()))
|
||||
assertEquals(rows, mergeHomeWatchRows(rows))
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ import org.justinvisser.wolfskin.tv.read.HomeLibraryCache
|
|||
class HomeLibraryCacheTest {
|
||||
@Test fun savedHomeReopensWithEpisodeMetadataAndFullShelfCount() {
|
||||
val context = ApplicationProvider.getApplicationContext<Application>()
|
||||
val episode = HomeTitle("episode-id", "The next episode", "episode", year = 2025, runtimeSeconds = 1800, overview = "Overview", poster = "poster", backdrop = "backdrop", seriesTitle = "A series", season = 2, episode = 3, resumeSeconds = 125.5, addedAt = "2026-11-05", genres = listOf("Drama"), held = true, tmdbId = 42)
|
||||
val episode = HomeTitle("episode-id", "The next episode", "episode", year = 2025, runtimeSeconds = 1800, overview = "Overview", poster = "poster", backdrop = "backdrop", seriesTitle = "A series", season = 2, episode = 3, resumeSeconds = 125.5, addedAt = "2026-11-05", genres = listOf("Drama"), held = true, tmdbId = 42, seriesId = "series-id", lastPlayedAt = 123456L)
|
||||
val film = HomeTitle("film-id", "A film", "movie", year = 2024, runtimeSeconds = 5400, played = true, held = true, tmdbId = 43)
|
||||
val library = HomeLibrary(listOf(episode), listOf(episode.copy(id = "next", resumeSeconds = 0.0)), listOf(film), mapOf("movies" to listOf(film)), mapOf("movies" to 84))
|
||||
HomeLibraryCache(context).write("server:person", library, 12345L)
|
||||
|
|
@ -26,4 +26,19 @@ class HomeLibraryCacheTest {
|
|||
assertEquals(12345L, saved.second)
|
||||
assertNull(HomeLibraryCache(context).read("server:someone-else"))
|
||||
}
|
||||
|
||||
@Test fun preMergeCacheWithoutWatchIdentityOrTimestampStillReopens() {
|
||||
val context = ApplicationProvider.getApplicationContext<Application>()
|
||||
val cache = HomeLibraryCache(context)
|
||||
val title = HomeTitle("legacy", "An episode", "episode", seriesTitle = "Series", resumeSeconds = 24.0, held = true)
|
||||
cache.write("legacy-scope", HomeLibrary(resume = listOf(title)), 12L)
|
||||
val store = org.justinvisser.wolfskin.conductarr.FileCacheStore(java.io.File(context.filesDir, "wolfskin-home"))
|
||||
val entry = store.read("legacy-scope", "home:jellyfin")!!
|
||||
val body = org.json.JSONObject(entry.body)
|
||||
body.getJSONArray("resume").getJSONObject(0).apply { remove("seriesId"); remove("lastPlayedAt") }
|
||||
store.write("legacy-scope", "home:jellyfin", entry.copy(body = body.toString()))
|
||||
val saved = cache.read("legacy-scope")!!
|
||||
assertEquals(title, saved.first.resume.single())
|
||||
assertEquals(12L, saved.second)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class WatchReadTest {
|
|||
runCurrent()
|
||||
assertFalse(loading.isCompleted)
|
||||
assertTrue(model.snapshot.rows.first().watchReady)
|
||||
assertEquals(1136.274, model.snapshot.rows.single { it.id == "nu" }.cards.single().resumeSeconds, .0001)
|
||||
assertEquals(1136.274, model.snapshot.rows.single { it.id == "cw" }.cards.single().resumeSeconds, .0001)
|
||||
releaseLibrary.complete(Unit)
|
||||
loading.join()
|
||||
assertEquals(96.078, model.snapshot.rows.first().cards.first().resumeSeconds, .0001)
|
||||
|
|
@ -132,4 +132,28 @@ class WatchReadTest {
|
|||
WholphinDispatchers.reset()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun mergedHomeUsesSeriesWatchActivityNotAnUnwatchedNextEpisodeDate() = runTest {
|
||||
val otherSeries = UUID.fromString("00000000-0000-0000-0000-000000000004")
|
||||
val checkpoint = decode(resumeWire).let { it.copy(seriesId = seriesId, seriesName = "Series A",
|
||||
userData = it.userData!!.copy(lastPlayedDate = java.time.LocalDateTime.parse("2026-11-05T12:00:00"))) }
|
||||
val hero = checkpoint.copy(id = UUID.fromString("00000000-0000-0000-0000-000000000005"), type = BaseItemKind.MOVIE, seriesId = null, seriesName = null)
|
||||
val next = decode(nextWire).let { it.copy(seriesId = seriesId, seriesName = "Series A",
|
||||
userData = it.userData!!.copy(playbackPositionTicks = 0, lastPlayedDate = null)) }
|
||||
val otherNext = next.copy(id = UUID.fromString("00000000-0000-0000-0000-000000000006"), seriesId = otherSeries, seriesName = "Series B")
|
||||
coEvery { items.getResumeItems(userId = userId, fields = any(), mediaTypes = any(), limit = 20) } returns successQueryResult(listOf(hero, checkpoint))
|
||||
coEvery { shows.getNextUp(userId = userId, fields = any(), limit = 20, enableUserData = true) } returns successQueryResult(listOf(next, otherNext))
|
||||
for ((id, date) in listOf(seriesId to "2026-11-04T12:00:00", otherSeries to "2026-11-07T12:00:00")) {
|
||||
coEvery { library.getItem(userId = userId, itemId = id) } returns successResponse(BaseItemDto(id = id, type = BaseItemKind.SERIES))
|
||||
val watched = checkpoint.copy(userData = checkpoint.userData!!.copy(lastPlayedDate = java.time.LocalDateTime.parse(date)))
|
||||
coEvery { items.getItems(userId = userId, parentId = id, recursive = true,
|
||||
includeItemTypes = listOf(BaseItemKind.EPISODE), isPlayed = true, enableUserData = true,
|
||||
sortBy = listOf(org.jellyfin.sdk.model.api.ItemSortBy.DATE_PLAYED),
|
||||
sortOrder = listOf(org.jellyfin.sdk.model.api.SortOrder.DESCENDING), limit = 1) } returns successQueryResult(listOf(watched))
|
||||
}
|
||||
val rows = buildHomeRows(HomeReadFacade(api, images, mockk()).readWatch(userId), emptyList())
|
||||
val watching = rows.single { it.id == "cw" }.cards
|
||||
assertEquals(listOf(otherNext.id.toString(), checkpoint.id.toString()), watching.map { it.id })
|
||||
assertEquals(96.078, watching.last().resumeSeconds, .0001)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue