Skip to main content

Components

View State

View that displays different content based on its state.

banner-View State

Usage

Views are responsible for managing their own state. Android View displays different content based on its state. View state in Legion is implemented based on base components forking from Kennyc1012/MultiStateView with some modification and some improvement.


Legion provides 4 different states, where we can customize activities to each layout state.

Default Content

This is default state provided by Legion.

viewstate android default

Empty

This is state that we can use when we have nothing to show in view.

viewstate android empty

Error

This is state that we can use when we have an error activity in view.

viewstate android error

Loading

This is state that we can use when we still waiting for an activity in view.

viewstate android loading

How to use

Static usage in XML

<com.telkom.legion.component.viewstate.LgnViewState
android:id="@+id/msvSample"
android:layout_width="match_parent"
android:layout_height="250dp"
app:loadingView="@layout/layout_sample_one"
app:errorView="@layout/layout_sample_two"
app:emptyView="@layout/layout_sample_three"
app:viewState="content">
<FrameLayout

Change State

...
with(binding) {
lifecycleScope.launch { //For sample we use coroutine delay for automatic change state
//Change to Content View
msvSample.viewState = ViewState.CONTENT
// Or Use Extension Function
msvSample.showDefaultLayout()
delay(1000)ewState.LOADING))) {

Modify Layout In State

...
with(binding) {
//For sample we use state loading with layout : layout_sample_one.xml
with(LayoutSampleOneBinding.bind(msvSample.getView(ViewState.LOADING))) {
//Do Whatever you want with layout
}
}
...

Attributes

Attribute NameXml AttrsRelated method(s)Description
View Stateapp:viewStateviewStateTo set View State in Layout
Loading Viewapp:loadingViewN/ATo set Loading View Layout
Empty Viewapp:emptyViewN/ATo set Empty View Layout
Error Viewapp:errorViewN/ATo set Error View Layout

References