MVI (Model-View-Intent) is an architectural pattern that clearly defines states and events for modeling user interfaces. This architecture focuses on processing user interactions as events and updating the UI by changing the state.
- The Reducer is a core class that handles the state (
UiState) and events (UiEvent). - It maintains the current state and generates a new state in response to events to update the UI.
- Inherits from
Reducerand handlesMainStateandMainEvent. reducemethod:- The
Increaseevent increases the value of thedatain the state. - The
Decreaseevent decreases the value ofdata.
- The
- A data class representing the state of the counter.
data: Stores the current value of the counter.
- A
sealedclass representing events of the counter. - Two types of events:
IncreaseandDecrease.
- Connects the UI with the Reducer.
- Transmits events to the
Reducerand relays the state from theReducerto the UI.
- An Android activity that sets up the UI and interacts with the UI using
MainViewModel.
- The user triggers an
IncreaseorDecreaseevent through the UI. MainViewModelpasses this event to theMainReducer.MainReducerchanges theMainStatebased on the event.- The updated
MainStateis reflected in the UI, visible to the user.