From c58df447ebea1408b33209098851557847e6c652 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 21 Jun 2017 12:44:12 -0700 Subject: Minute to text --- library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'library') diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index 8aaadaf..d3db05e 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -1,12 +1,12 @@ package ca.allanwang.kau.utils import android.content.Context +import android.content.pm.PackageManager import android.content.res.Resources import android.os.Build import android.os.Looper +import ca.allanwang.kau.R import ca.allanwang.kau.logging.KL -import android.content.pm.PackageManager - /** @@ -48,4 +48,17 @@ fun Context.isAppInstalled(packageName: String): Boolean { installed = false } return installed +} + +/** + * Converts minute value to string + * Whole hours and days will be converted as such, otherwise it will default to x minutes + */ +fun Context.minuteToText(minutes: Long): String = with(minutes) { + if (this < 0L) string(R.string.kau_none) + else if (this == 60L) string(R.string.kau_one_hour) + else if (this == 1440L) string(R.string.kau_one_day) + else if (this % 1440L == 0L) String.format(string(R.string.kau_x_days), this / 1440L) + else if (this % 60L == 0L) String.format(string(R.string.kau_x_hours), this / 60L) + else String.format(string(R.string.kau_x_minutes), this) } \ No newline at end of file -- cgit v1.2.3