-
-
Save mikimn/82884000a0fb79004a4cc6c1a7fff5d8 to your computer and use it in GitHub Desktop.
Extensions for Duration and CallType
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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