Created
September 14, 2025 03:51
-
-
Save iVamsi/8623493907041dfe23831eca029caa0e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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