Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating locale helper references in new display models. #576

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading