mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05: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
4 changed files with 20 additions and 13 deletions
|
@ -28,7 +28,6 @@ import tachiyomi.domain.history.interactor.RemoveHistory
|
||||||
import tachiyomi.domain.history.model.HistoryWithRelations
|
import tachiyomi.domain.history.model.HistoryWithRelations
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.time.LocalDate
|
|
||||||
|
|
||||||
class HistoryScreenModel(
|
class HistoryScreenModel(
|
||||||
private val getHistory: GetHistory = Injekt.get(),
|
private val getHistory: GetHistory = Injekt.get(),
|
||||||
|
@ -60,12 +59,10 @@ class HistoryScreenModel(
|
||||||
private fun List<HistoryWithRelations>.toHistoryUiModels(): List<HistoryUiModel> {
|
private fun List<HistoryWithRelations>.toHistoryUiModels(): List<HistoryUiModel> {
|
||||||
return map { HistoryUiModel.Item(it) }
|
return map { HistoryUiModel.Item(it) }
|
||||||
.insertSeparators { before, after ->
|
.insertSeparators { before, after ->
|
||||||
val beforeDate = before?.item?.readAt?.time?.toLocalDate() ?: LocalDate.MIN
|
val beforeDate = before?.item?.readAt?.time?.toLocalDate()
|
||||||
val afterDate = after?.item?.readAt?.time?.toLocalDate() ?: LocalDate.MIN
|
val afterDate = after?.item?.readAt?.time?.toLocalDate()
|
||||||
when {
|
when {
|
||||||
beforeDate.isAfter(afterDate)
|
beforeDate != afterDate && afterDate != null -> HistoryUiModel.Header(afterDate)
|
||||||
or afterDate.equals(LocalDate.MIN)
|
|
||||||
or beforeDate.equals(LocalDate.MIN) -> HistoryUiModel.Header(afterDate)
|
|
||||||
// Return null to avoid adding a separator between two items.
|
// Return null to avoid adding a separator between two items.
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ import tachiyomi.domain.updates.interactor.GetUpdates
|
||||||
import tachiyomi.domain.updates.model.UpdatesWithRelations
|
import tachiyomi.domain.updates.model.UpdatesWithRelations
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.time.LocalDate
|
|
||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
|
|
||||||
class UpdatesScreenModel(
|
class UpdatesScreenModel(
|
||||||
|
@ -374,12 +373,10 @@ class UpdatesScreenModel(
|
||||||
return items
|
return items
|
||||||
.map { UpdatesUiModel.Item(it) }
|
.map { UpdatesUiModel.Item(it) }
|
||||||
.insertSeparators { before, after ->
|
.insertSeparators { before, after ->
|
||||||
val beforeDate = before?.item?.update?.dateFetch?.toLocalDate() ?: LocalDate.MIN
|
val beforeDate = before?.item?.update?.dateFetch?.toLocalDate()
|
||||||
val afterDate = after?.item?.update?.dateFetch?.toLocalDate() ?: LocalDate.MIN
|
val afterDate = after?.item?.update?.dateFetch?.toLocalDate()
|
||||||
when {
|
when {
|
||||||
beforeDate.isAfter(afterDate)
|
beforeDate != afterDate && afterDate != null -> UpdatesUiModel.Header(afterDate)
|
||||||
or afterDate.equals(LocalDate.MIN)
|
|
||||||
or beforeDate.equals(LocalDate.MIN) -> UpdatesUiModel.Header(afterDate)
|
|
||||||
// Return null to avoid adding a separator between two items.
|
// Return null to avoid adding a separator between two items.
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.time.format.DateTimeFormatter
|
||||||
import java.time.format.FormatStyle
|
import java.time.format.FormatStyle
|
||||||
import java.time.temporal.ChronoUnit
|
import java.time.temporal.ChronoUnit
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
fun LocalDateTime.toDateTimestampString(dateTimeFormatter: DateTimeFormatter): String {
|
fun LocalDateTime.toDateTimestampString(dateTimeFormatter: DateTimeFormatter): String {
|
||||||
val date = dateTimeFormatter.format(this)
|
val date = dateTimeFormatter.format(this)
|
||||||
|
@ -49,13 +50,20 @@ fun LocalDate.toRelativeString(
|
||||||
val now = LocalDate.now()
|
val now = LocalDate.now()
|
||||||
val difference = ChronoUnit.DAYS.between(this, now)
|
val difference = ChronoUnit.DAYS.between(this, now)
|
||||||
return when {
|
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 < 1 -> context.stringResource(MR.strings.relative_time_today)
|
||||||
difference < 7 -> context.pluralStringResource(
|
difference < 7 -> context.pluralStringResource(
|
||||||
MR.plurals.relative_time,
|
MR.plurals.relative_time,
|
||||||
difference.toInt(),
|
difference.toInt(),
|
||||||
difference.toInt(),
|
difference.toInt(),
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> dateFormat.format(this)
|
else -> dateFormat.format(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
<item quantity="other">%1$d days ago</item>
|
<item quantity="other">%1$d days ago</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
|
<plurals name="upcoming_relative_time">
|
||||||
|
<item quantity="one">Tomorrow</item>
|
||||||
|
<item quantity="other">In %1$d days</item>
|
||||||
|
</plurals>
|
||||||
|
|
||||||
<plurals name="num_categories">
|
<plurals name="num_categories">
|
||||||
<item quantity="one">%d category</item>
|
<item quantity="one">%d category</item>
|
||||||
<item quantity="other">%d categories</item>
|
<item quantity="other">%d categories</item>
|
||||||
|
|
Loading…
Reference in a new issue