add a helper function for formatting minutes to string

This commit is contained in:
tibbi 2018-03-06 22:06:19 +01:00
parent 71d35b7ebf
commit 90ac73f614
3 changed files with 29 additions and 1 deletions

View file

@ -6,7 +6,7 @@ buildscript {
propMinSdkVersion = 16
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '3.15.4'
propVersionName = '3.15.5'
kotlin_version = '1.2.30'
support_libs = '27.1.0'
}

View file

@ -360,3 +360,30 @@ fun Context.getSelectedDaysString(bitMask: Int): String {
}
return days.trim().trimEnd(',')
}
fun Context.formatMinutesToTimeString(totalMinutes: Int): String {
val days = totalMinutes / DAY_MINUTES
val hours = (totalMinutes % DAY_MINUTES) / 60
val minutes = totalMinutes % 60
val timesString = StringBuilder()
if (days > 0) {
val daysString = String.format(resources.getQuantityString(R.plurals.days, days, days))
timesString.append("$daysString, ")
}
if (hours > 0) {
val hoursString = String.format(resources.getQuantityString(R.plurals.hours, hours, hours))
timesString.append("$hoursString, ")
}
if (minutes > 0) {
val minutesString = String.format(resources.getQuantityString(R.plurals.minutes, minutes, minutes))
timesString.append(minutesString)
}
var result = timesString.toString().trim().trimEnd(',')
if (result.isEmpty()) {
result = String.format(resources.getQuantityString(R.plurals.minutes, 0, 0))
}
return result
}

View file

@ -12,6 +12,7 @@ const val REAL_FILE_PATH = "real_file_path_2"
const val IS_FROM_GALLERY = "is_from_gallery"
const val BROADCAST_REFRESH_MEDIA = "com.simplemobiletools.REFRESH_MEDIA"
const val OTG_PATH = "otg:/"
const val DAY_MINUTES = 1440
// shared preferences
const val PREFS_KEY = "Prefs"