This file contains 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
open class AacMviDH<STATE, EFFECT> { | |
private val _states: MutableLiveData<STATE> = MutableLiveData() | |
val stateLiveData: LiveData<STATE> | |
get() = _states | |
private var _state: STATE? = null | |
var state: STATE | |
get() = _state | |
?: throw UninitializedPropertyAccessException("\"state\" was queried before being initialized") |
This file contains 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
open class AacMviViewModelDH<STATE, EFFECT, EVENT>(application: Application, private val aacMviDH: AacMviDH<STATE, EFFECT>) : | |
AndroidViewModel(application), ViewModelContract<EVENT> { | |
fun viewStates(): LiveData<STATE> = aacMviDH.stateLiveData | |
fun viewEffects(): LiveData<EFFECT> = aacMviDH.effectLiveData | |
@CallSuper | |
override fun process(viewEvent: EVENT) { | |
Log.d(TAG, "processing viewEvent : $viewEvent") |
This file contains 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 MainViewEvent { | |
data class NewsItemClicked(val newsItem: NewsItem) : MainViewEvent() | |
object FabClicked : MainViewEvent() | |
object OnSwipeRefresh : MainViewEvent() | |
object FetchNews : MainViewEvent() | |
} |
This file contains 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 MainViewEffect { | |
data class ShowSnackbar(val message: String) : MainViewEffect() | |
data class ShowToast(val message: String) : MainViewEffect() | |
} |
This file contains 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
data class MainViewState(val fetchStatus: FetchStatus, val newsList: List<NewsItem>) | |
sealed class FetchStatus { | |
object Fetching : FetchStatus() | |
object Fetched : FetchStatus() | |
object NotFetched : FetchStatus() | |
} |
This file contains 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
class MainActivity : AacMviActivity<MainViewState, MainViewEffect, MainViewEvent, MainActVM>() { | |
override val viewModel: MainActVM by viewModels() | |
override fun renderViewState(viewState: MainViewState) { | |
//Handle new viewState | |
} | |
override fun renderViewEffect(viewEffect: MainViewEffect) { | |
//Show effects | |
} |
This file contains 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
class MainActVM(application: Application) : | |
AacMviViewModel<MainViewState, MainViewEffect, MainViewEvent>(application) { | |
init { | |
viewState = MainViewState(fetchStatus = FetchStatus.NotFetched, newsList = emptyList()) | |
} | |
override fun process(viewEvent: MainViewEvent) { | |
super.process(viewEvent) | |
} |
This file contains 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
open class AacMviViewModel<STATE, EFFECT, EVENT>(application: Application) : | |
AndroidViewModel(application), ViewModelContract<EVENT> { | |
private val _viewStates: MutableLiveData<STATE> = MutableLiveData() | |
fun viewStates(): LiveData<STATE> = _viewStates | |
private var _viewState: STATE? = null | |
protected var viewState: STATE | |
get() = _viewState | |
?: throw UninitializedPropertyAccessException("\"viewState\" was queried before being initialized") |
This file contains 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
abstract class AacMviActivity<STATE, EFFECT, EVENT, ViewModel : AacMviViewModel<STATE, EFFECT, EVENT>> : | |
AppCompatActivity() { | |
abstract val viewModel: ViewModel | |
private val viewStateObserver = Observer<STATE> { | |
Log.d(TAG, "observed viewState : $it") | |
renderViewState(it) | |
} |
This file contains 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
data class MainViewState(val fetchStatus: FetchStatus, val newsList: List<NewsItem>) | |
sealed class MainViewEffect { | |
data class ShowSnackbar(val message: String) : MainViewEffect() | |
data class ShowToast(val message: String) : MainViewEffect() | |
} | |
sealed class MainViewEvent { | |
data class NewsItemClicked(val newsItem: NewsItem) : MainViewEvent() | |
object FabClicked : MainViewEvent() |
NewerOlder