Integrate libraries and correct Home review blockers
This commit is contained in:
commit
14a74ac43b
642 changed files with 2377 additions and 169 deletions
|
|
@ -25,12 +25,16 @@ class HomeFixture(context: Context) {
|
|||
val continuation = if (status == HomeAvailability.SignedOut || status == HomeAvailability.Unavailable) listOf(homeDiscoverState(status)) else continuation(profile, state)
|
||||
var rows = buildHomeRows(library, continuation, state != "jf-down", state == "loading")
|
||||
rows = rows.map { row ->
|
||||
if (!row.catalogue) row else row.copy(cards = row.cards.map { title ->
|
||||
val names = owners[title.tmdbId?.let { "${title.type}:$it" } ?: title.id].orEmpty()
|
||||
val held = title.held || profile.getString("name") in names
|
||||
val other = if (held) null else names.filter { it != profile.getString("name") }.takeIf { it.isNotEmpty() }?.joinToString(" and ")
|
||||
if (held == title.held && other == title.otherOwner) title else title.copy(held = held, otherOwner = other)
|
||||
})
|
||||
if (!row.catalogue) row else {
|
||||
fun owned(title: HomeTitle): HomeTitle {
|
||||
val names = owners[title.tmdbId?.let { "${title.type}:$it" } ?: title.id].orEmpty()
|
||||
val held = title.held || profile.getString("name") in names
|
||||
val other = if (held) null else names.filter { it != profile.getString("name") }.takeIf { it.isNotEmpty() }?.joinToString(" and ")
|
||||
return if (held == title.held && other == title.otherOwner) title else title.copy(held = held, otherOwner = other)
|
||||
}
|
||||
val cards = row.cards.map(::owned)
|
||||
row.copy(cards = cards, allCards = if (row.allCards === row.cards) cards else row.allCards.map(::owned))
|
||||
}
|
||||
}
|
||||
if (state == "missing") {
|
||||
val missing = profiles.flatMap { person -> listOf("movies", "shows", "anime", "discover", "nextUp", "recentlyAdded").flatMap { key -> person.items(key).filterIndexed { index, _ -> index % 3 == 0 } } }.map { it.getString("id") }.toSet()
|
||||
|
|
@ -60,10 +64,10 @@ class HomeFixture(context: Context) {
|
|||
val showRow = take(shows, minOf(12, kotlin.math.ceil(shows.size.toDouble() / (groupRows.size + 1)).toInt()))
|
||||
val remaining = (movies + shows).count { it.identity() !in seen }
|
||||
val size = if (groupRows.isEmpty()) 0 else minOf(8, kotlin.math.ceil(remaining.toDouble() / groupRows.size).toInt())
|
||||
val watchedRows = groupRows.map { (seed, items) -> Triple(seed, take(items, size), items.size) }.filter { it.second.size >= 3 }
|
||||
if (movieRow.isNotEmpty()) add(shelf("pk-m", "Movies for you", movieRow, movies.size))
|
||||
if (showRow.isNotEmpty()) add(shelf("pk-s", "Series for you", showRow, shows.size))
|
||||
watchedRows.take(2).forEachIndexed { index, (seed, items, total) -> add(shelf("pk-w$index", "Because you watched ${seed.getString("title")}", items, total)) }
|
||||
val watchedRows = groupRows.map { (seed, items) -> Triple(seed, take(items, size), items) }.filter { it.second.size >= 3 }
|
||||
if (movieRow.isNotEmpty()) add(shelf("pk-m", "Movies for you", movieRow, movies.size, movies))
|
||||
if (showRow.isNotEmpty()) add(shelf("pk-s", "Series for you", showRow, shows.size, shows))
|
||||
watchedRows.take(2).forEachIndexed { index, (seed, items, all) -> add(shelf("pk-w$index", "Because you watched ${seed.getString("title")}", items, all.size, all)) }
|
||||
}
|
||||
val excluded = flatMap { row -> row.cards }.map { it.id }.toSet()
|
||||
val base = pool.filter { it.getString("id") !in excluded }
|
||||
|
|
@ -72,15 +76,18 @@ class HomeFixture(context: Context) {
|
|||
val rotated = base.drop(shift) + base.take(shift)
|
||||
add(shelf("new-$index", "New on $service", rotated.take(12).sortedByDescending { it.optInt("year") }))
|
||||
}
|
||||
add(shelf("trending", "Trending", base.take(WolfskinTokens.Behaviour.rowLimit.toInt()), base.size))
|
||||
add(shelf("trending", "Trending", base.take(WolfskinTokens.Behaviour.rowLimit.toInt()), base.size, base))
|
||||
listOf("Comedy", "Animation", "Science Fiction", "Horror", "Romance").forEach { genre ->
|
||||
val titles = base.filter { genre in genres(it) && (genre !in setOf("Science Fiction", "Horror", "Romance") || it.getString("type") == "movie") }
|
||||
if (titles.isNotEmpty()) add(shelf("genre-$genre", genre, titles.take(WolfskinTokens.Behaviour.rowLimit.toInt()), titles.size))
|
||||
if (titles.isNotEmpty()) add(shelf("genre-$genre", genre, titles.take(WolfskinTokens.Behaviour.rowLimit.toInt()), titles.size, titles))
|
||||
}
|
||||
add(HomeRow("explore", HomeRowKind.Explore, "Explore more in Discover"))
|
||||
}
|
||||
|
||||
private fun shelf(id: String, name: String, items: List<JSONObject>, total: Int = items.size) = HomeRow(id, HomeRowKind.Shelf, name, items.map(::title), catalogue = true, total = total, target = "see-all:$id")
|
||||
private fun shelf(id: String, name: String, items: List<JSONObject>, total: Int = items.size, allItems: List<JSONObject> = items): HomeRow {
|
||||
val cards = items.map(::title)
|
||||
return HomeRow(id, HomeRowKind.Shelf, name, cards, catalogue = true, total = total, allCards = if (allItems === items) cards else allItems.map(::title))
|
||||
}
|
||||
|
||||
private fun title(item: JSONObject): HomeTitle = HomeTitle(
|
||||
id = item.getString("id"), title = item.getString("title"), type = item.getString("type"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue