Skip to content

Instantly share code, notes, and snippets.

@iVamsi
Created September 14, 2025 03:51
Show Gist options
  • Save iVamsi/8623493907041dfe23831eca029caa0e to your computer and use it in GitHub Desktop.
Save iVamsi/8623493907041dfe23831eca029caa0e to your computer and use it in GitHub Desktop.
sealed class SnackbarDurationWrapper {
data class Standard(val duration: SnackbarDuration) : SnackbarDurationWrapper()
data class Custom(val millis: Long) : SnackbarDurationWrapper()
companion object {
fun fromMillis(milliseconds: Long): SnackbarDurationWrapper {
require(milliseconds > 0) { "Duration must be positive" }
return Custom(milliseconds)
}
fun fromSeconds(seconds: Double): SnackbarDurationWrapper {
return Custom((seconds * 1000).toLong())
}
}
fun getMilliseconds(): Long {
return when (this) {
is Standard -> when (duration) {
SnackbarDuration.Short -> 4000L
SnackbarDuration.Long -> 10000L
SnackbarDuration.Indefinite -> Long.MAX_VALUE
}
is Custom -> millis
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment