Skip to content

Commit b097e04

Browse files
committed
fix(ui): Display death date and age for deceased persons
This commit adds support for displaying death dates and calculating the age at death on the person detail screen. It also refactors the birthdate display to handle deceased individuals by omitting the "years old" suffix when a death date is present. ### Key Changes: * **`PersonDetailContent.kt`**: * Updated the UI to check for and display a person's death date (`endDate`). * Calculates and displays the age at death if both birth and death dates are available. * Modified the birthdate display logic: if the person is deceased, it now only shows the birthdate without the current age. * Refactored `DateTimeFormatter` initialization for better consistency across date fields. * **`AfinityPersonDetail.kt` & `JellyfinModelExtensions.kt`**: * Added `endDate` to the `AfinityPersonDetail` model and updated the mapping logic to extract this field from the data source. * **`strings.xml`**: * Added new string resources for deceased status: `person_born_deceased_fmt`, `person_died_fmt`, and `person_died_no_age_fmt`.
1 parent e19a51e commit b097e04

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

app/src/main/java/com/makd/afinity/data/models/extensions/JellyfinModelExtensions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ fun BaseItemDto.toAfinityPersonDetail(baseUrl: String): AfinityPersonDetail {
375375
overview = overview.orEmpty(),
376376
images = toAfinityImages(baseUrl),
377377
premiereDate = premiereDate,
378+
endDate = endDate,
378379
productionLocations = productionLocations ?: emptyList(),
379380
externalUrls = externalUrls?.map { it.toAfinityExternalUrl() },
380381
favorite = userData?.isFavorite ?: false,

app/src/main/java/com/makd/afinity/data/models/media/AfinityPersonDetail.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ data class AfinityPersonDetail(
1111
val overview: String,
1212
val images: AfinityImages,
1313
val premiereDate: LocalDateTime?,
14+
val endDate: LocalDateTime?,
1415
val productionLocations: List<String>,
1516
val externalUrls: List<AfinityExternalUrl>?,
1617
val favorite: Boolean = false,
@@ -23,6 +24,7 @@ fun BaseItemDto.toAfinityPersonDetail(repository: JellyfinRepository): AfinityPe
2324
overview = overview.orEmpty(),
2425
images = toAfinityImages(repository),
2526
premiereDate = premiereDate,
27+
endDate = endDate,
2628
productionLocations = productionLocations ?: emptyList(),
2729
externalUrls = externalUrls?.map { it.toAfinityExternalUrl() },
2830
favorite = userData?.isFavorite ?: false,

app/src/main/java/com/makd/afinity/ui/person/components/PersonDetailContent.kt

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,22 +436,49 @@ private fun PersonMetadataSection(
436436
modifier: Modifier = Modifier,
437437
) {
438438
val hasBirthday = person.premiereDate != null
439+
val hasDeathDate = person.endDate != null
439440
val hasBirthplace = person.productionLocations.isNotEmpty()
440441
val hasExternalLinks = !person.externalUrls.isNullOrEmpty()
441442

442-
if (hasBirthday || hasBirthplace || hasExternalLinks) {
443+
if (hasBirthday || hasDeathDate || hasBirthplace || hasExternalLinks) {
443444
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
445+
val datePattern = stringResource(R.string.person_date_fmt)
446+
val formatter =
447+
remember(datePattern) {
448+
java.time.format.DateTimeFormatter.ofPattern(datePattern)
449+
}
450+
444451
person.premiereDate?.let { birthday ->
445-
val datePattern = stringResource(R.string.person_date_fmt)
446-
val formatter =
447-
remember(datePattern) {
448-
java.time.format.DateTimeFormatter.ofPattern(datePattern)
452+
val isDeceased = person.endDate != null
453+
Text(
454+
text =
455+
if (isDeceased) {
456+
stringResource(R.string.person_born_deceased_fmt, birthday.format(formatter))
457+
} else {
458+
val age =
459+
java.time.Period.between(
460+
birthday.toLocalDate(),
461+
java.time.LocalDate.now(),
462+
).years
463+
stringResource(R.string.person_born_fmt, birthday.format(formatter), age)
464+
},
465+
style = MaterialTheme.typography.bodyMedium,
466+
color = MaterialTheme.colorScheme.onSurfaceVariant,
467+
)
468+
}
469+
470+
person.endDate?.let { deathDate ->
471+
val age =
472+
person.premiereDate?.let { birthday ->
473+
java.time.Period.between(birthday.toLocalDate(), deathDate.toLocalDate()).years
449474
}
450-
val now = java.time.LocalDateTime.now()
451-
val age = java.time.Period.between(birthday.toLocalDate(), now.toLocalDate()).years
452475
Text(
453476
text =
454-
stringResource(R.string.person_born_fmt, birthday.format(formatter), age),
477+
if (age != null) {
478+
stringResource(R.string.person_died_fmt, deathDate.format(formatter), age)
479+
} else {
480+
stringResource(R.string.person_died_no_age_fmt, deathDate.format(formatter))
481+
},
455482
style = MaterialTheme.typography.bodyMedium,
456483
color = MaterialTheme.colorScheme.onSurfaceVariant,
457484
)

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@
243243
<!--Person Detail Screen-->
244244
<string name="person_biography">Biography</string>
245245
<string name="person_born_fmt">Born: %1$s (%2$d years old)</string>
246+
<string name="person_born_deceased_fmt">Born: %1$s</string>
247+
<string name="person_died_fmt">Died: %1$s (aged %2$d)</string>
248+
<string name="person_died_no_age_fmt">Died: %1$s</string>
246249
<string name="person_birthplace_fmt">Birth Place: %1$s</string>
247250
<string name="person_movies_fmt">Movies (%1$d)</string>
248251
<string name="person_shows_fmt">TV Shows (%1$d)</string>

0 commit comments

Comments
 (0)