feat(itch): collections filter in the Library (#1597)

* Add itch.io collections to the Library

A Collections button on the Library's itch tab filters the library to one collection of the signed-in account. Its games that are not installed show in the Not installed section.

* Keep itch collections complete across failures, sign-out and empty libraries

A failed later page no longer publishes a partial collection, selecting a collection refreshes it, pagination runs until an empty page, signing out clears collection state, and the itch chip shows for a signed-in account with no owned games.

* Tie itch collection requests to the account that started them

Requests capture the account generation before reading the key and dedupe per generation, sign-out clears collections after the token is removed, and the collections load follows the itch sign-in state.

* Keep paging itch collections past a page of already seen games

* Run the itch collections tests under Robolectric like the other itch tests

* Let the Installed filter apply inside a collection and keep the grid for an empty itch account

* fix(itch): stop paging a collection when a page adds no new games

* Keep the collections icon on the itch collections tab when it opens

---------

Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
FX1922andmaxjivi05 authored and GitHub committed 2026-10-26 18:15:24 -04:00
1 parent f13916ee25
commit d905f03bf7
41 files changed
+313 -12

No files matched your search

@@ -0,0 +1,31 @@
package com.droiddeck.launcher.stores.itch
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Test
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
class ItchCollectionsTest {
@Test fun collectionsKeepTheirIdTitleAndCount() {
val body = JSONArray()
.put(JSONObject().put("id", 8356509).put("title", "library").put("games_count", 12))
.put(JSONObject().put("id", 7).put("title", "").put("games_count", 3))
.put(JSONObject().put("title", "no id"))
val list = ItchCollections.parseCollections(body)
assertEquals(listOf("8356509"), list.map { it.id })
assertEquals("library", list.single().title)
assertEquals(12, list.single().count)
}
@Test fun collectionGamesReadBothKeyStylesAndSkipRowsWithoutAGame() {
val game = JSONObject().put("id", 99).put("title", "Celeste 64").put("url", "https://noel.itch.io/celeste64")
val snake = JSONObject().put("collection_games", JSONArray().put(JSONObject().put("game", game)).put(JSONObject().put("position", 1)))
val camel = JSONObject().put("collectionGames", JSONArray().put(JSONObject().put("game", game)))
assertEquals(listOf("noel.itch.io/celeste64"), ItchCollections.parseGames(snake).map { it.id })
assertEquals(1, ItchCollections.parseGames(camel).size)
assertEquals(false, ItchCollections.parseGames(snake).single().owned)
assertEquals(0, ItchCollections.parseGames(JSONObject()).size)
}
}
@@ -94,4 +94,23 @@ class LibraryEntriesTest {
GameRef.parse("xbox:9NBLGGH4R315").let { assertEquals(Store.XBOX, it.store); assertEquals("9NBLGGH4R315", it.storeId) }
GameRef.parse("app:nope:1").let { assertNull(it.store); assertNull(it.appId) }
}
@Test fun aCollectionKeepsItsInstalledGamesAndListsTheRestAsNotInstalled() {
val games = listOf(
Library.SteamGame(440, "Team Fortress 2", null, "Steam library"),
Library.SteamGame(-5, "Celeste", null, Library.ADDED, source = "itch", storeId = "a/celeste"),
Library.SteamGame(-6, "Other", null, Library.ADDED, source = "itch", storeId = "a/other"),
)
val library = mapOf(Store.ITCH to listOf(owned(Store.ITCH, "a/celeste"), owned(Store.ITCH, "a/other"), owned(Store.ITCH, "b/owned")))
val all = libraryEntries(games, library, setOf("itch:a/celeste", "itch:a/other"))
val collection = listOf(owned(Store.ITCH, "a/celeste"), owned(Store.ITCH, "b/owned"), owned(Store.ITCH, "c/new"))
val out = collectionEntries(all, collection)
assertEquals(listOf("app:-5", "app:itch:b/owned", "app:itch:c/new"), out.map { it.key })
assertEquals(listOf(true, false, false), out.map { it.installed })
}
@Test fun anEmptyCollectionHidesEveryGame() {
val all = libraryEntries(listOf(Library.SteamGame(440, "Team Fortress 2", null, "Steam library")), emptyMap(), emptySet())
assertEquals(emptyList<String>(), collectionEntries(all, emptyList()).map { it.key })
}
}