Skip to content

Instantly share code, notes, and snippets.

@mikimn
Created August 29, 2021 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikimn/82884000a0fb79004a4cc6c1a7fff5d8 to your computer and use it in GitHub Desktop.
Save mikimn/82884000a0fb79004a4cc6c1a7fff5d8 to your computer and use it in GitHub Desktop.
Extensions for Duration and CallType
fun Duration.humanReadable(): String {
if (this.seconds < 60) {
return "${this.seconds} seconds"
}
val minutes = this.toMinutes()
if (minutes < 60) {
if (this.seconds == 0L) {
return "$minutes min."
}
val fractionalSeconds = this.seconds % 60
return "${this.toMinutes()}:${fractionalSeconds} min."
}
return "over an hour"
}
@Composable
fun CallType.Icon() {
return when {
this == CallType.INCOMING -> Icon(
Icons.Default.CallMade,
contentDescription = "Incoming Call",
tint = androidx.compose.ui.graphics.Color.Green
)
this == CallType.OUTGOING -> Icon(
Icons.Default.CallReceived,
contentDescription = "Outgoing Call",
tint = androidx.compose.ui.graphics.Color.Blue
)
else -> Icon(
Icons.Default.CallMissed,
contentDescription = "Missed Call",
tint = androidx.compose.ui.graphics.Color.Blue
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment