Skip to content

Commit 8e29d64

Browse files
committed
TraktTools4: use pagination to get collected movies
1 parent 80fed60 commit 8e29d64

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

app/src/main/java/com/battlelancer/seriesguide/traktapi/TraktTools4.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import timber.log.Timber
2727
*/
2828
object TraktTools4 {
2929

30+
// 1000 is the maximum limit according to https://github.com/trakt/trakt-api/discussions/681
31+
private const val COLLECTION_MAX_LIMIT = 1000
32+
3033
sealed interface TraktResponse<T> {
3134
data class Success<T>(
3235
/**
@@ -82,8 +85,7 @@ object TraktTools4 {
8285
action = "get collected shows",
8386
reportIsNotVip = true // Should work even if not VIP
8487
) { page ->
85-
// 1000 is the maximum limit according to https://github.com/trakt/trakt-api/discussions/681
86-
traktSync.collectionShows(page, 1000, null)
88+
traktSync.collectionShows(page, COLLECTION_MAX_LIMIT, null)
8789
}
8890
}
8991

@@ -185,11 +187,12 @@ object TraktTools4 {
185187
suspend fun getCollectedMoviesByTmdbId(
186188
traktSync: Sync
187189
): TraktNonNullResponse<MutableSet<Int>> {
188-
val response = awaitTraktCallNonNull(
189-
traktSync.collectionMovies(null),
190-
"get movie collection",
190+
val response = fetchAllPages(
191+
action = "get collected movies",
191192
reportIsNotVip = true // Should work even if not VIP
192-
)
193+
) { page ->
194+
traktSync.collectionMovies(page, COLLECTION_MAX_LIMIT, null)
195+
}
193196
return mapResponseData(response) { mapMoviesToTmdbIdSet(it) }
194197
}
195198

0 commit comments

Comments
 (0)