From 07f963d5ae16c3c8d7be025a7e9439ad2110ac71 Mon Sep 17 00:00:00 2001 From: Maddie Witman Date: Sat, 24 Feb 2024 14:33:46 -0500 Subject: [PATCH] Fix some issues from 7ff95e2 (#415) * Fixed extra header introduced in 7ff95e2 * Removed parentheses to make detekt happy * Updated relative date display for dates in the future * Small cleanup for header creation logic * replaced "and" with "&&" for better formatting --- .../kanade/tachiyomi/ui/history/HistoryScreenModel.kt | 9 +++------ .../kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt | 9 +++------ .../eu/kanade/tachiyomi/util/lang/DateExtensions.kt | 10 +++++++++- i18n/src/commonMain/resources/MR/base/plurals.xml | 5 +++++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoryScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoryScreenModel.kt index 7b0cdcf72..c0c2b555f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoryScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoryScreenModel.kt @@ -28,7 +28,6 @@ import tachiyomi.domain.history.interactor.RemoveHistory import tachiyomi.domain.history.model.HistoryWithRelations import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import java.time.LocalDate class HistoryScreenModel( private val getHistory: GetHistory = Injekt.get(), @@ -60,12 +59,10 @@ class HistoryScreenModel( private fun List.toHistoryUiModels(): List { return map { HistoryUiModel.Item(it) } .insertSeparators { before, after -> - val beforeDate = before?.item?.readAt?.time?.toLocalDate() ?: LocalDate.MIN - val afterDate = after?.item?.readAt?.time?.toLocalDate() ?: LocalDate.MIN + val beforeDate = before?.item?.readAt?.time?.toLocalDate() + val afterDate = after?.item?.readAt?.time?.toLocalDate() when { - beforeDate.isAfter(afterDate) - or afterDate.equals(LocalDate.MIN) - or beforeDate.equals(LocalDate.MIN) -> HistoryUiModel.Header(afterDate) + beforeDate != afterDate && afterDate != null -> HistoryUiModel.Header(afterDate) // Return null to avoid adding a separator between two items. else -> null } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt index 2b2c1c25a..c5385d1f0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt @@ -45,7 +45,6 @@ import tachiyomi.domain.updates.interactor.GetUpdates import tachiyomi.domain.updates.model.UpdatesWithRelations import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import java.time.LocalDate import java.time.ZonedDateTime class UpdatesScreenModel( @@ -374,12 +373,10 @@ class UpdatesScreenModel( return items .map { UpdatesUiModel.Item(it) } .insertSeparators { before, after -> - val beforeDate = before?.item?.update?.dateFetch?.toLocalDate() ?: LocalDate.MIN - val afterDate = after?.item?.update?.dateFetch?.toLocalDate() ?: LocalDate.MIN + val beforeDate = before?.item?.update?.dateFetch?.toLocalDate() + val afterDate = after?.item?.update?.dateFetch?.toLocalDate() when { - beforeDate.isAfter(afterDate) - or afterDate.equals(LocalDate.MIN) - or beforeDate.equals(LocalDate.MIN) -> UpdatesUiModel.Header(afterDate) + beforeDate != afterDate && afterDate != null -> UpdatesUiModel.Header(afterDate) // Return null to avoid adding a separator between two items. else -> null } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt index 9e61555ec..8326fe2f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt @@ -13,6 +13,7 @@ import java.time.format.DateTimeFormatter import java.time.format.FormatStyle import java.time.temporal.ChronoUnit import java.util.Date +import kotlin.math.absoluteValue fun LocalDateTime.toDateTimestampString(dateTimeFormatter: DateTimeFormatter): String { val date = dateTimeFormatter.format(this) @@ -49,13 +50,20 @@ fun LocalDate.toRelativeString( val now = LocalDate.now() val difference = ChronoUnit.DAYS.between(this, now) return when { - difference < 0 -> difference.toString() + difference < -7 -> dateFormat.format(this) + difference < 0 -> context.pluralStringResource( + MR.plurals.upcoming_relative_time, + difference.toInt().absoluteValue, + difference.toInt().absoluteValue, + ) + difference < 1 -> context.stringResource(MR.strings.relative_time_today) difference < 7 -> context.pluralStringResource( MR.plurals.relative_time, difference.toInt(), difference.toInt(), ) + else -> dateFormat.format(this) } } diff --git a/i18n/src/commonMain/resources/MR/base/plurals.xml b/i18n/src/commonMain/resources/MR/base/plurals.xml index 2f10b004c..d9c958afc 100644 --- a/i18n/src/commonMain/resources/MR/base/plurals.xml +++ b/i18n/src/commonMain/resources/MR/base/plurals.xml @@ -10,6 +10,11 @@ %1$d days ago + + Tomorrow + In %1$d days + + %d category %d categories