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
| val ChaosDark = Color(0xFF0D0D0D) | |
| @RequiresApi(Build.VERSION_CODES.TIRAMISU) | |
| @Composable | |
| fun ChaosButton( | |
| text: String, | |
| modifier: Modifier = Modifier, | |
| useV2: Boolean = true, | |
| backgroundColor: Color = ChaosDark, | |
| textColor: Color = Color.White, |
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
| @ExperimentalCoroutinesApi | |
| @RunWith(MockitoJUnitRunner::class) | |
| class MainViewModelTest { | |
| @Mock | |
| lateinit var getTodos: IGetTodosUseCase | |
| private lateinit var viewModel: MainViewModel | |
| @get:Rule |
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
| interface TimeCapsule<S : UiState> { | |
| fun addState(state: S) | |
| fun selectState(position: Int) | |
| fun getStates(): List<S> | |
| } | |
| class TimeTravelCapsule<S : UiState>( | |
| private val onStateSelected: (S) -> Unit | |
| ) : TimeCapsule<S> { |
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 MainScreenDialogState() { | |
| object None: MainScreenDialogState() | |
| object ShowAddItemDialogState: MainScreenDialogState() | |
| object ShowDeleteItemDialogState: MainScreenDialogState() | |
| } | |
| data class MainScreenState { | |
| ... | |
| val dialogState = MainScreenDialogState.None | |
| ... |
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
| @Composable | |
| fun MainScreen( | |
| viewModel: MainViewModel | |
| ) { | |
| val state by viewModel.state.collectAsState() | |
| Column { | |
| //Render toolbar | |
| Toolbar(viewModel.timeMachine) | |
| //Render screen content |
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
| @HiltViewModel | |
| class MainViewModel @Inject constructor( | |
| private val getTodos: IGetTodosUseCase, | |
| private val dispatcher: CoroutineDispatcher, | |
| private val viewMapper: MainScreenViewDataMapper, | |
| ) : BaseViewModel<MainScreenState, MainScreenUiEvent>() { | |
| private val reducer = MainReducer(MainScreenState.initial()) | |
| override val state: StateFlow<MainScreenState> |
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
| @Immutable | |
| sealed class MainScreenUiEvent : UiEvent { | |
| data class ShowData(val items: List<MainScreenItem>) : MainScreenUiEvent() | |
| data class OnChangeDialogState(val show: Boolean) : MainScreenUiEvent() | |
| data class AddNewItem(val text: String) : MainScreenUiEvent() | |
| data class OnItemCheckedChanged(val index: Int, val isChecked: Boolean) : MainScreenUiEvent() | |
| object DismissDialog : MainScreenUiEvent() | |
| } | |
| @Immutable |
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
| //Not ok | |
| sealed class MyState { | |
| object ShowProgressBar: MyState() | |
| data class ShowDataWithError(val error: Throwable?, val data: List<Item>): MyState() | |
| } | |
| //Good | |
| data class MyState( | |
| val isShowProgress: Boolean = false, | |
| val error: Throwable? = null, | |
| val data: List<Item> |
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 MyState { | |
| object ShowProgressBar: MyState() | |
| data class ShowDataWithError(val error: Throwable?, val data: List<Item>): MyState() | |
| } |
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 MyState { | |
| object ShowProgressBar: MyState() | |
| data class ShowError(val error: Throwable): MyState() | |
| data class ShowListOfData(val data: List<Item>): MyState() | |
| } |
NewerOlder