mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-24 18:08:24 +01:00
* 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
This commit is contained in:
parent
ab02568ac6
commit
07f963d5ae
@ -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<HistoryWithRelations>.toHistoryUiModels(): List<HistoryUiModel> {
|
||||
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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,11 @@
|
||||
<item quantity="other">%1$d days ago</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="upcoming_relative_time">
|
||||
<item quantity="one">Tomorrow</item>
|
||||
<item quantity="other">In %1$d days</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="num_categories">
|
||||
<item quantity="one">%d category</item>
|
||||
<item quantity="other">%d categories</item>
|
||||
|
Loading…
Reference in New Issue
Block a user