Skip to content

Commit ed4c8d0

Browse files
committed
Only show matches with at least 1 ranked team
1 parent 5cdba20 commit ed4c8d0

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

Diff for: match/src/main/kotlin/dev/ricknout/rugbyranker/match/data/MatchDataConverter.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ object MatchDataConverter {
6969
eventEndTimeLabel = event?.end?.label,
7070
eventEndTimeMillis = event?.end?.millis,
7171
eventEndTimeGmtOffset = event?.end?.gmtOffset?.toInt(),
72-
predictable = teamIds.containsAll(listOf(firstTeam.id, secondTeam.id)),
72+
numberOfRankedTeams = teamIds.count { teamId ->
73+
teamId == firstTeam.id || teamId == secondTeam.id
74+
},
7375
half = getHalfFromResponse(content),
7476
minute = null,
7577
)

Diff for: match/src/main/kotlin/dev/ricknout/rugbyranker/match/data/MatchRepository.kt

+17-15
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,24 @@ class MatchRepository(
6565
return try {
6666
val response = service.getMatches(sports, states, startDate, endDate, sort, page, pageSize)
6767
val teamIds = dao.loadTeamIds(sport)
68-
val matches = MatchDataConverter.getMatchesFromResponse(response, sport, teamIds).map { match ->
69-
when (match.status) {
70-
Status.LIVE -> {
71-
val summaryResponse = service.getMatchSummary(match.id)
72-
val minute = MatchDataConverter.getMinuteFromResponse(summaryResponse)
73-
match.copy(minute = minute)
68+
val matches = MatchDataConverter.getMatchesFromResponse(response, sport, teamIds)
69+
.filter { match -> match.displayable }
70+
.map { match ->
71+
when (match.status) {
72+
Status.LIVE -> {
73+
val summaryResponse = service.getMatchSummary(match.id)
74+
val minute = MatchDataConverter.getMinuteFromResponse(summaryResponse)
75+
match.copy(minute = minute)
76+
}
77+
else -> match
78+
}
79+
}.run {
80+
if (sort == WorldRugbyService.SORT_ASC) {
81+
sortedBy { match -> match.timeMillis }
82+
} else {
83+
sortedByDescending { match -> match.timeMillis }
7484
}
75-
else -> match
76-
}
77-
}.run {
78-
if (sort == WorldRugbyService.SORT_ASC) {
79-
sortedBy { match -> match.timeMillis }
80-
} else {
81-
sortedByDescending { match -> match.timeMillis }
8285
}
83-
}
8486
true to matches
8587
} catch (e: Exception) {
8688
Log.e(TAG, e.toString())
@@ -96,7 +98,7 @@ class MatchRepository(
9698
val response = service.getMatchSummary(id)
9799
val teamIds = dao.loadTeamIds(sport)
98100
val match = MatchDataConverter.getMatchFromResponse(response, sport, teamIds)
99-
true to match
101+
match.displayable to match
100102
} catch (e: Exception) {
101103
Log.e(TAG, e.toString())
102104
false to null

Diff for: match/src/main/kotlin/dev/ricknout/rugbyranker/match/model/Match.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ data class Match(
3434
val eventEndTimeLabel: String?,
3535
val eventEndTimeMillis: Long?,
3636
val eventEndTimeGmtOffset: Int?,
37-
val predictable: Boolean,
37+
val numberOfRankedTeams: Int,
3838
val half: Half?,
3939
val minute: Int?,
4040
) {
41+
val displayable: Boolean
42+
get() = numberOfRankedTeams >= 1
43+
val predictable: Boolean
44+
get() = numberOfRankedTeams == 2
4145

4246
fun toPrediction(): Prediction {
4347
val switched = secondTeamName == venueCountry

0 commit comments

Comments
 (0)