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
Reducer
and handlesMainState
andMainEvent
. reduce
method:- The
Increase
event increases the value of thedata
in the state. - The
Decrease
event decreases the value ofdata
.
- The
- A data class representing the state of the counter.
data
: Stores the current value of the counter.
- A
sealed
class representing events of the counter. - Two types of events:
Increase
andDecrease
.
- Connects the UI with the Reducer.
- Transmits events to the
Reducer
and relays the state from theReducer
to the UI.
- An Android activity that sets up the UI and interacts with the UI using
MainViewModel
.
- The user triggers an
Increase
orDecrease
event through the UI. MainViewModel
passes this event to theMainReducer
.MainReducer
changes theMainState
based on the event.- The updated
MainState
is reflected in the UI, visible to the user.