Skip to content

Commit

Permalink
SchedulePage: show seconds only when remaining time < 10min to avoid …
Browse files Browse the repository at this point in the history
…log file pollution and recomposing every second
  • Loading branch information
hg42 committed Jul 27, 2024
1 parent 55c35ce commit e8fb40d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/machiav3lli/backup/utils/ScheduleUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,15 @@ fun calcTimeLeft(schedule: Schedule): Pair<String, String> {
val at = calculateTimeToRun(schedule, now)
absTime = ISO_DATE_TIME_FORMAT_MIN.format(at)
val timeDiff = max(at - now, 0)
val remainingMinutes = TimeUnit.MILLISECONDS.toMinutes(timeDiff).toInt()
val days = TimeUnit.MILLISECONDS.toDays(timeDiff).toInt()
if (days != 0) {
relTime +=
"${OABX.context.resources.getQuantityString(R.plurals.days_left, days, days)} + "
}
val hours = TimeUnit.MILLISECONDS.toHours(timeDiff).toInt() % 24
val minutes = TimeUnit.MILLISECONDS.toMinutes(timeDiff).toInt() % 60
if (useSeconds) {
if (useSeconds && remainingMinutes < 10) {
val seconds = TimeUnit.MILLISECONDS.toSeconds(timeDiff).toInt() % 60
relTime += LocalTime.of(hours, minutes, seconds).toString()
} else {
Expand Down

0 comments on commit e8fb40d

Please sign in to comment.