Skip to content

Commit 0d3b2f3

Browse files
committed
Fix matches fetch logic to ensure refresh Snackbar works
1 parent dc1e530 commit 0d3b2f3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

matches/src/main/java/com/ricknout/rugbyranker/matches/repository/MatchesRepository.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ class MatchesRepository(
6868
var success = false
6969
val worldRugbyMatches = mutableListOf<WorldRugbyMatch>()
7070
val initialMatchesFetched = matchesSharedPreferences.isInitialMatchesFetched(sport, matchStatus)
71-
while (page < pageCount) {
72-
try {
71+
return try {
72+
while (page < pageCount) {
7373
val worldRugbyMatchesResponse = worldRugbyService.getMatches(sports, states, startDate, endDate, sort, page, pageSize)
7474
val matches = MatchesDataConverter.getWorldRugbyMatchesFromWorldRugbyMatchesResponse(worldRugbyMatchesResponse, sport)
7575
if (cache) worldRugbyMatchDao.insert(matches)
7676
page++
7777
pageCount = if (fetchMultiplePages && !initialMatchesFetched) worldRugbyMatchesResponse.pageInfo.numPages else 1
7878
success = true
7979
worldRugbyMatches.addAll(matches)
80-
} catch (_: Exception) {
81-
// If we have successfully loaded other pages of matches, do not consider this a failure
8280
}
81+
if (fetchMultiplePages) matchesSharedPreferences.setInitialMatchesFetched(sport, matchStatus, true)
82+
success to worldRugbyMatches
83+
} catch (_: Exception) {
84+
success to worldRugbyMatches
8385
}
84-
if (fetchMultiplePages) matchesSharedPreferences.setInitialMatchesFetched(sport, matchStatus, true)
85-
return success to worldRugbyMatches
8686
}
8787

8888
fun fetchAndCacheLatestWorldRugbyMatchesAsync(sport: Sport, matchStatus: MatchStatus, coroutineScope: CoroutineScope, onComplete: (success: Boolean) -> Unit) {

0 commit comments

Comments
 (0)