Skip to content

Commit

Permalink
Updating locale helper references in new display models. (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamMc331 authored Nov 30, 2024
1 parent 39d417e commit 36268e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adammcneilly.pocketleague.shared.app.core.displaymodels

import com.adammcneilly.pocketleague.shared.app.core.locale.LocaleHelper
import com.adammcneilly.pocketleague.shared.app.core.models.Location

/**
Expand All @@ -9,22 +10,17 @@ data class LocationDisplayModel(
val venue: String,
val cityCountry: String,
) {
constructor(location: Location) : this(
constructor(
location: Location,
localeHelper: LocaleHelper,
) : this(
venue = location.venue,
cityCountry = "TODO: Copy Locale Helper",
cityCountry = "${location.city}, ${location.countryName(localeHelper)}",
)
}

// /**
// * Converts a [Location] to a more user friendly [LocationDisplayModel].
// */
// fun Location.toDisplayModel(
// localeHelper: LocaleHelper,
// ): LocationDisplayModel {
// val countryName = localeHelper.getCountryDisplayName(this.countryCode)
//
// return LocationDisplayModel(
// venue = this.venue,
// cityCountry = "${this.city}, $countryName",
// )
// }
private fun Location.countryName(
localeHelper: LocaleHelper,
): String {
return localeHelper.getCountryDisplayName(this.countryCode)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adammcneilly.pocketleague.shared.app.core.displaymodels

import com.adammcneilly.pocketleague.shared.app.core.locale.LocaleHelper
import com.adammcneilly.pocketleague.shared.app.core.models.Player

/**
Expand All @@ -18,7 +19,7 @@ data class PlayerDisplayModel(
name = player.name,
tag = player.tag,
role = player.roleString(),
countryFlagEmojiUnicode = "TODO: Get Locale Helper",
countryFlagEmojiUnicode = LocaleHelper.getFlagEmoji(player.countryCode),
)

companion object {
Expand Down

0 comments on commit 36268e0

Please sign in to comment.