@@ -40,7 +40,8 @@ class MatchesRepository(
40
40
matchStatus : MatchStatus ,
41
41
cache : Boolean = true,
42
42
pageSize : Int = PAGE_SIZE_WORLD_RUGBY_MATCHES_NETWORK ,
43
- fetchMultiplePages : Boolean = true
43
+ fetchMultiplePages : Boolean = true,
44
+ fetchMinutes : Boolean = false
44
45
): Pair <Boolean , List <WorldRugbyMatch >> {
45
46
val sports = when (sport) {
46
47
Sport .MENS -> WorldRugbyService .SPORT_MENS
@@ -74,7 +75,15 @@ class MatchesRepository(
74
75
return try {
75
76
while (page < pageCount) {
76
77
val worldRugbyMatchesResponse = worldRugbyService.getMatches(sports, states, startDate, endDate, sort, page, pageSize)
77
- val matches = MatchesDataConverter .getWorldRugbyMatchesFromWorldRugbyMatchesResponse(worldRugbyMatchesResponse, sport)
78
+ val matches = MatchesDataConverter .getWorldRugbyMatchesFromWorldRugbyMatchesResponse(worldRugbyMatchesResponse, sport).map { match ->
79
+ if (fetchMinutes) {
80
+ val worldRugbyMatchSummaryResponse = worldRugbyService.getMatchSummary(match.matchId)
81
+ val minute = MatchesDataConverter .getMinuteFromWorldRugbyMatchSummaryResponse(worldRugbyMatchSummaryResponse)
82
+ match.copy(minute = minute)
83
+ } else {
84
+ match
85
+ }
86
+ }
78
87
if (cache) worldRugbyMatchDao.insert(matches)
79
88
page++
80
89
pageCount = if (fetchMultiplePages && ! initialMatchesFetched) worldRugbyMatchesResponse.pageInfo.numPages else 1
@@ -92,7 +101,8 @@ class MatchesRepository(
92
101
if (matchStatus == MatchStatus .LIVE ) throw IllegalArgumentException (" Cannot handle MatchStatus type $matchStatus in fetchAndCacheLatestWorldRugbyMatchesSync" )
93
102
coroutineScope.launch {
94
103
val result = withContext(Dispatchers .IO ) {
95
- fetchAndCacheLatestWorldRugbyMatchesSync(sport, matchStatus, cache = true , pageSize = PAGE_SIZE_WORLD_RUGBY_MATCHES_NETWORK_REFRESH , fetchMultiplePages = false )
104
+ fetchAndCacheLatestWorldRugbyMatchesSync(
105
+ sport, matchStatus, cache = true , pageSize = PAGE_SIZE_WORLD_RUGBY_MATCHES_NETWORK_REFRESH , fetchMultiplePages = false , fetchMinutes = false )
96
106
}
97
107
val success = result.first
98
108
onComplete(success)
@@ -102,7 +112,8 @@ class MatchesRepository(
102
112
fun fetchLatestWorldRugbyMatchesAsync (sport : Sport , matchStatus : MatchStatus , coroutineScope : CoroutineScope , onComplete : (success: Boolean , worldRugbyMatches: List <WorldRugbyMatch >) -> Unit ) {
103
113
coroutineScope.launch {
104
114
val result = withContext(Dispatchers .IO ) {
105
- fetchAndCacheLatestWorldRugbyMatchesSync(sport, matchStatus, cache = false , pageSize = PAGE_SIZE_WORLD_RUGBY_MATCHES_NETWORK_REFRESH , fetchMultiplePages = false )
115
+ fetchAndCacheLatestWorldRugbyMatchesSync(
116
+ sport, matchStatus, cache = false , pageSize = PAGE_SIZE_WORLD_RUGBY_MATCHES_NETWORK_REFRESH , fetchMultiplePages = false , fetchMinutes = true )
106
117
}
107
118
val success = result.first
108
119
val worldRugbyMatches = result.second
0 commit comments