Skip to content

Commit 26adc93

Browse files
committed
Show minute in live matches
1 parent add7547 commit 26adc93

File tree

8 files changed

+97
-10
lines changed

8 files changed

+97
-10
lines changed

Diff for: core/src/main/java/com/ricknout/rugbyranker/core/api/WorldRugbyResponses.kt

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ data class Venue(
4141
val country: String
4242
)
4343

44+
data class Clock(
45+
val secs: Int,
46+
val label: String
47+
)
48+
4449
data class Event(
4550
val id: Long,
4651
val label: String,
@@ -59,6 +64,7 @@ data class Match(
5964
val teams: List<Team>,
6065
val scores: List<Int>,
6166
val status: String,
67+
val clock: Clock?,
6268
val events: List<Event>
6369
)
6470

@@ -67,6 +73,10 @@ data class WorldRugbyMatchesResponse(
6773
val content: List<Match>
6874
)
6975

76+
data class WorldRugbyMatchSummaryResponse(
77+
val match: Match
78+
)
79+
7080
data class TeamDetail(
7181
val id: Long,
7282
val country: String,

Diff for: core/src/main/java/com/ricknout/rugbyranker/core/api/WorldRugbyService.kt

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ interface WorldRugbyService {
2323
@Query("pageSize") pageSize: Int
2424
): WorldRugbyMatchesResponse
2525

26+
@GET("rugby/match/{id}/summary")
27+
suspend fun getMatchSummary(
28+
@Path("id") id: Long
29+
): WorldRugbyMatchSummaryResponse
30+
2631
@GET("rugby/team/{id}")
2732
suspend fun getTeams(
2833
@Path("id") id: Long

Diff for: core/src/main/java/com/ricknout/rugbyranker/core/util/DateUtils.kt

+1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ object DateUtils {
5656
const val DAY_MILLIS = 1000L * 60L * 60L * 24L
5757
const val HOUR_MILLIS = 1000L * 60L * 60L
5858
const val MINUTE_MILLIS = 1000L * 60L
59+
const val MINUTE_SECS = 60
5960
}

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class MatchesRepository(
4040
matchStatus: MatchStatus,
4141
cache: Boolean = true,
4242
pageSize: Int = PAGE_SIZE_WORLD_RUGBY_MATCHES_NETWORK,
43-
fetchMultiplePages: Boolean = true
43+
fetchMultiplePages: Boolean = true,
44+
fetchMinutes: Boolean = false
4445
): Pair<Boolean, List<WorldRugbyMatch>> {
4546
val sports = when (sport) {
4647
Sport.MENS -> WorldRugbyService.SPORT_MENS
@@ -74,7 +75,15 @@ class MatchesRepository(
7475
return try {
7576
while (page < pageCount) {
7677
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+
}
7887
if (cache) worldRugbyMatchDao.insert(matches)
7988
page++
8089
pageCount = if (fetchMultiplePages && !initialMatchesFetched) worldRugbyMatchesResponse.pageInfo.numPages else 1
@@ -92,7 +101,8 @@ class MatchesRepository(
92101
if (matchStatus == MatchStatus.LIVE) throw IllegalArgumentException("Cannot handle MatchStatus type $matchStatus in fetchAndCacheLatestWorldRugbyMatchesSync")
93102
coroutineScope.launch {
94103
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)
96106
}
97107
val success = result.first
98108
onComplete(success)
@@ -102,7 +112,8 @@ class MatchesRepository(
102112
fun fetchLatestWorldRugbyMatchesAsync(sport: Sport, matchStatus: MatchStatus, coroutineScope: CoroutineScope, onComplete: (success: Boolean, worldRugbyMatches: List<WorldRugbyMatch>) -> Unit) {
103113
coroutineScope.launch {
104114
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)
106117
}
107118
val success = result.first
108119
val worldRugbyMatches = result.second

Diff for: matches/src/main/java/com/ricknout/rugbyranker/matches/ui/WorldRugbyMatchViewHolder.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ class WorldRugbyMatchViewHolder(itemView: View) : RecyclerView.ViewHolder(itemVi
3535
}
3636
if (showTime) {
3737
if (worldRugbyMatch.status == MatchStatus.LIVE) {
38+
val minute = worldRugbyMatch.minute
3839
val half = when (worldRugbyMatch.half) {
3940
MatchHalf.FIRST_HALF -> itemView.context.getString(R.string.text_match_first_half)
4041
MatchHalf.SECOND_HALF -> itemView.context.getString(R.string.text_match_second_half)
4142
MatchHalf.HALF_TIME -> itemView.context.getString(R.string.text_match_half_time)
4243
else -> null
4344
}
44-
itemView.timeTextView.text = half
45+
itemView.timeTextView.text = if (minute != null && half != null) {
46+
itemView.context.getString(R.string.text_match_minute_half, minute, half)
47+
} else {
48+
half
49+
}
4550
itemView.timeTextView.isVisible = true
4651
} else {
4752
val time = DateUtils.getDate(DateUtils.DATE_FORMAT_HH_MM, worldRugbyMatch.timeMillis)

Diff for: matches/src/main/java/com/ricknout/rugbyranker/matches/vo/MatchesDataConverter.kt

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.ricknout.rugbyranker.matches.vo
22

33
import com.ricknout.rugbyranker.core.api.Match
4+
import com.ricknout.rugbyranker.core.api.WorldRugbyMatchSummaryResponse
45
import com.ricknout.rugbyranker.core.api.WorldRugbyMatchesResponse
56
import com.ricknout.rugbyranker.core.api.WorldRugbyService
7+
import com.ricknout.rugbyranker.core.util.DateUtils
68
import com.ricknout.rugbyranker.core.vo.Sport
79
import java.lang.IllegalArgumentException
810

@@ -39,8 +41,10 @@ object MatchesDataConverter {
3941
eventStartTimeGmtOffset = match.events.firstOrNull()?.start?.gmtOffset?.toInt(),
4042
eventEndTimeLabel = match.events.firstOrNull()?.end?.label,
4143
eventEndTimeMillis = match.events.firstOrNull()?.end?.millis,
42-
eventEndTimeGmtOffset = match.events.firstOrNull()?.end?.gmtOffset?.toInt()
43-
).apply { half = getMatchHalfFromMatch(match) }
44+
eventEndTimeGmtOffset = match.events.firstOrNull()?.end?.gmtOffset?.toInt(),
45+
half = getMatchHalfFromMatch(match),
46+
minute = null
47+
)
4448
}
4549
}
4650

@@ -61,4 +65,12 @@ object MatchesDataConverter {
6165
else -> null
6266
}
6367
}
68+
69+
fun getMinuteFromWorldRugbyMatchSummaryResponse(worldRugbyMatchSummaryResponse: WorldRugbyMatchSummaryResponse): Int? {
70+
return if (worldRugbyMatchSummaryResponse.match.clock != null) {
71+
worldRugbyMatchSummaryResponse.match.clock!!.secs / DateUtils.MINUTE_SECS
72+
} else {
73+
null
74+
}
75+
}
6476
}

Diff for: matches/src/main/java/com/ricknout/rugbyranker/matches/vo/WorldRugbyMatch.kt

+45-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,50 @@ data class WorldRugbyMatch(
3636
val eventStartTimeGmtOffset: Int?,
3737
val eventEndTimeLabel: String?,
3838
val eventEndTimeMillis: Long?,
39-
val eventEndTimeGmtOffset: Int?
40-
) {
39+
val eventEndTimeGmtOffset: Int?,
40+
@Ignore
41+
val half: MatchHalf?,
4142
@Ignore
42-
var half: MatchHalf? = null
43+
val minute: Int?
44+
) {
45+
46+
constructor(
47+
matchId: Long,
48+
description: String?,
49+
status: MatchStatus,
50+
attendance: Int,
51+
firstTeamId: Long,
52+
firstTeamName: String,
53+
firstTeamAbbreviation: String?,
54+
firstTeamScore: Int,
55+
secondTeamId: Long,
56+
secondTeamName: String,
57+
secondTeamAbbreviation: String?,
58+
secondTeamScore: Int,
59+
timeLabel: String,
60+
timeMillis: Long,
61+
timeGmtOffset: Int,
62+
venueId: Long?,
63+
venueName: String?,
64+
venueCity: String?,
65+
venueCountry: String?,
66+
eventId: Long?,
67+
eventLabel: String?,
68+
eventSport: Sport,
69+
eventRankingsWeight: Float?,
70+
eventStartTimeLabel: String?,
71+
eventStartTimeMillis: Long?,
72+
eventStartTimeGmtOffset: Int?,
73+
eventEndTimeLabel: String?,
74+
eventEndTimeMillis: Long?,
75+
eventEndTimeGmtOffset: Int?
76+
) : this(matchId, description, status, attendance,
77+
firstTeamId, firstTeamName, firstTeamAbbreviation, firstTeamScore,
78+
secondTeamId, secondTeamName, secondTeamAbbreviation, secondTeamScore,
79+
timeLabel, timeMillis, timeGmtOffset, venueId, venueName, venueCity, venueCountry,
80+
eventId, eventLabel, eventSport, eventRankingsWeight,
81+
eventStartTimeLabel, eventStartTimeMillis, eventStartTimeGmtOffset,
82+
eventEndTimeLabel, eventEndTimeMillis, eventEndTimeGmtOffset,
83+
half = null, minute = null
84+
)
4385
}

Diff for: matches/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
<string name="text_match_first_half">1st half</string>
1414
<string name="text_match_second_half">2nd half</string>
1515
<string name="text_match_half_time">Half time</string>
16+
<string name="text_match_minute_half">%1$02d\' (%2$s)</string>
1617

1718
</resources>

0 commit comments

Comments
 (0)