From 57f246c52a55e86d3edfedf326d987525a2f2db3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 24 May 2017 19:06:46 +0200 Subject: [PATCH] do not write "before" at the display past events duration --- .../calendar/activities/SettingsActivity.kt | 2 +- .../calendar/extensions/Context.kt | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index acbe5bfe8..702ca3a78 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -240,7 +240,7 @@ class SettingsActivity : SimpleActivity() { return if (displayPastEvents == 0) getString(R.string.never) else - getFormattedMinutes(displayPastEvents) + getFormattedMinutes(displayPastEvents, false) } override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index f7d02de5f..96830b864 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -109,7 +109,7 @@ private fun getNotificationIntent(context: Context, eventId: Int): PendingIntent fun Context.getAppropriateTheme() = if (config.backgroundColor.getContrastColor() == Color.WHITE) R.style.MyDialogTheme_Dark else R.style.MyDialogTheme -fun Context.getFormattedMinutes(minutes: Int) = when (minutes) { +fun Context.getFormattedMinutes(minutes: Int, showBefore: Boolean = true) = when (minutes) { -1 -> getString(R.string.no_reminder) 0 -> getString(R.string.at_start) else -> { @@ -121,10 +121,13 @@ fun Context.getFormattedMinutes(minutes: Int) = when (minutes) { resources.getQuantityString(R.plurals.weeks, minutes / 10080, minutes / 10080) else if (minutes % 1440 == 0) resources.getQuantityString(R.plurals.days, minutes / 1440, minutes / 1440) - else if (minutes % 60 == 0) - resources.getQuantityString(R.plurals.hours_before, minutes / 60, minutes / 60) - else - resources.getQuantityString(R.plurals.minutes_before, minutes, minutes) + else if (minutes % 60 == 0) { + val base = if (showBefore) R.plurals.hours_before else R.plurals.hours + resources.getQuantityString(base, minutes / 60, minutes / 60) + } else { + val base = if (showBefore) R.plurals.minutes_before else R.plurals.minutes + resources.getQuantityString(base, minutes, minutes) + } } }