Skip to content

Commit

Permalink
Adding locale helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamMc331 committed Nov 30, 2024
1 parent ecfa90c commit 799d6e6
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.adammcneilly.pocketleague.shared.app.core.displaymodels

import com.adammcneilly.pocketleague.shared.app.core.datetime.DateTimeFormatter
import com.adammcneilly.pocketleague.shared.app.core.datetime.TimeZone
import com.adammcneilly.pocketleague.shared.app.core.locale.LocaleHelper
import com.adammcneilly.pocketleague.shared.app.core.models.Event
import com.adammcneilly.pocketleague.shared.app.core.models.EventStage

Expand Down Expand Up @@ -33,14 +34,18 @@ data class EventSummaryDisplayModel(
val winningTeam: TeamOverviewDisplayModel? = null,
private val location: LocationDisplayModel? = null,
) {
constructor(event: Event, dateTimeFormatter: DateTimeFormatter) : this(
constructor(
event: Event,
dateTimeFormatter: DateTimeFormatter,
localeHelper: LocaleHelper,
) : this(
name = event.name,
imageURL = ThemedImageURL(
lightThemeImageURL = event.imageURL,
),
eventId = event.id,
isMajor = event.lan,
location = event.location(),
location = event.location(localeHelper),
dateRange = parseDateRange(
formattedStartDate = event.startDateUTC?.toEventDate(dateTimeFormatter).orEmpty(),
formattedEndDate = event.endDateUTC?.toEventDate(dateTimeFormatter).orEmpty(),
Expand All @@ -65,12 +70,16 @@ data class EventSummaryDisplayModel(
* It's unlikely that an event had more than one location, but we'll default to the
* last one because it's most likely the main stage if so.
*/
private fun Event.location(): LocationDisplayModel? {
private fun Event.location(
localeHelper: LocaleHelper,
): LocationDisplayModel? {
val lastLocation = this.stages
.mapNotNull(EventStage::location)
.lastOrNull()

return lastLocation?.let(::LocationDisplayModel)
return lastLocation?.let { location ->
LocationDisplayModel(location, localeHelper)
}
}

private fun String.toEventDate(
Expand Down

0 comments on commit 799d6e6

Please sign in to comment.