From 36268e01a842c5240575c3a4eb35da2aae6a0546 Mon Sep 17 00:00:00 2001 From: Adam McNeilly Date: Fri, 29 Nov 2024 23:31:45 -0500 Subject: [PATCH] Updating locale helper references in new display models. (#576) --- .../displaymodels/EventSummaryDisplayModel.kt | 17 +++++++++--- .../displaymodels/LocationDisplayModel.kt | 26 ++++++++----------- .../core/displaymodels/PlayerDisplayModel.kt | 3 ++- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/EventSummaryDisplayModel.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/EventSummaryDisplayModel.kt index 672a0a3d..1c8c3d19 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/EventSummaryDisplayModel.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/EventSummaryDisplayModel.kt @@ -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 @@ -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(), @@ -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( diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/LocationDisplayModel.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/LocationDisplayModel.kt index c34ab26a..088ad490 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/LocationDisplayModel.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/LocationDisplayModel.kt @@ -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 /** @@ -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) +} diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/PlayerDisplayModel.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/PlayerDisplayModel.kt index 6f37f22b..23089736 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/PlayerDisplayModel.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/displaymodels/PlayerDisplayModel.kt @@ -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 /** @@ -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 {