|
| 1 | +package br.com.mob1st.core.design.molecules.keyboard |
| 2 | + |
| 3 | +import androidx.compose.runtime.Immutable |
| 4 | + |
| 5 | +/** |
| 6 | + * A key that can be clicked in the [Keyboard] component. |
| 7 | + */ |
| 8 | +sealed interface Key |
| 9 | + |
| 10 | +/** |
| 11 | + * A numeric key that can be clicked in the [Keyboard] component. |
| 12 | + * It can be any number between 0 and 9. |
| 13 | + * The constructor is private to avoid creating instances with invalid numbers. |
| 14 | + * Use the [NumericKey.Instances] object to get the available instances. |
| 15 | + */ |
| 16 | +@Immutable |
| 17 | +@JvmInline |
| 18 | +value class NumericKey private constructor( |
| 19 | + val number: Int, |
| 20 | +) : Key { |
| 21 | + init { |
| 22 | + require(number in 0..9) { "Number must be between 0 and 9. Current is $number" } |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * The available instances of the [NumericKey]. |
| 27 | + */ |
| 28 | + companion object Instances { |
| 29 | + val Zero = NumericKey(0) |
| 30 | + val One = NumericKey(1) |
| 31 | + val Two = NumericKey(2) |
| 32 | + val Three = NumericKey(3) |
| 33 | + val Four = NumericKey(4) |
| 34 | + val Five = NumericKey(5) |
| 35 | + val Six = NumericKey(6) |
| 36 | + val Seven = NumericKey(7) |
| 37 | + val Eight = NumericKey(8) |
| 38 | + val Nine = NumericKey(9) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * Keys that, differently from the [NumericKey], have a specific behavior when clicked. |
| 44 | + */ |
| 45 | +sealed interface FunctionKey : Key { |
| 46 | + /** |
| 47 | + * When clicked, it indicates the amount type should be undone and the original value should be restored. |
| 48 | + */ |
| 49 | + data object Undo : FunctionKey |
| 50 | + |
| 51 | + /** |
| 52 | + * Removes the last character from the amount. |
| 53 | + */ |
| 54 | + data object Delete : FunctionKey |
| 55 | + |
| 56 | + /** |
| 57 | + * Submits the information on screen and dismisses the keyboard. |
| 58 | + */ |
| 59 | + data object Done : FunctionKey |
| 60 | + |
| 61 | + /** |
| 62 | + * Allows the user to select a date. |
| 63 | + */ |
| 64 | + data object Calendar : FunctionKey |
| 65 | + |
| 66 | + /** |
| 67 | + * Allows the user to set cents for the amount. |
| 68 | + */ |
| 69 | + data object Decimal : FunctionKey |
| 70 | +} |
0 commit comments