aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt17
1 files changed, 15 insertions, 2 deletions
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