|
4 | 4 |
|
5 | 5 | package com.icerockdev.library.sample |
6 | 6 |
|
7 | | -import dev.icerock.moko.mvvm.State |
| 7 | +import dev.icerock.moko.mvvm.ResourceState |
8 | 8 | import dev.icerock.moko.mvvm.livedata.LiveData |
9 | 9 | import dev.icerock.moko.mvvm.livedata.MutableLiveData |
10 | 10 | import dev.icerock.moko.mvvm.livedata.map |
@@ -100,24 +100,24 @@ open class StateScreen( |
100 | 100 | } |
101 | 101 |
|
102 | 102 | interface StateViewModelContract { |
103 | | - val state: LiveData<State<String, String>> |
| 103 | + val state: LiveData<ResourceState<String, String>> |
104 | 104 |
|
105 | 105 | fun onChangeStatePressed() |
106 | 106 | } |
107 | 107 |
|
108 | 108 | class StateViewModel : ViewModel(), StateViewModelContract { |
109 | | - private val _state: MutableLiveData<State<String, String>> = |
110 | | - MutableLiveData(initialValue = State.Empty()) |
111 | | - override val state: LiveData<State<String, String>> = _state |
| 109 | + private val _state: MutableLiveData<ResourceState<String, String>> = |
| 110 | + MutableLiveData(initialValue = ResourceState.Empty()) |
| 111 | + override val state: LiveData<ResourceState<String, String>> = _state |
112 | 112 |
|
113 | 113 | override fun onChangeStatePressed() { |
114 | 114 | when (state.value) { |
115 | | - is State.Empty -> _state.value = State.Loading() |
116 | | - is State.Loading -> { |
117 | | - _state.value = State.Data(data = "hello!") |
| 115 | + is ResourceState.Empty -> _state.value = ResourceState.Loading() |
| 116 | + is ResourceState.Loading -> { |
| 117 | + _state.value = ResourceState.Success(data = "hello!") |
118 | 118 | } |
119 | | - is State.Data -> _state.value = State.Error(error = "this is error") |
120 | | - is State.Error -> _state.value = State.Empty() |
| 119 | + is ResourceState.Success -> _state.value = ResourceState.Failed(error = "this is error") |
| 120 | + is ResourceState.Failed -> _state.value = ResourceState.Empty() |
121 | 121 | } |
122 | 122 | } |
123 | 123 | } |
0 commit comments