This file contains hidden or 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
| override fun render(mainViewState: MainViewState) { | |
| Log.d("MVIState", "New state rendered!") | |
| with(mainViewState) { | |
| showProgressBar(progress) | |
| showError(error) | |
| showRocketList(rocketList) | |
| } | |
| } |
This file contains hidden or 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
| override fun emitButtonClick(): Observable<Boolean> = buttonClickSubject |
This file contains hidden or 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
| override fun onCreate(savedInstanceState: Bundle?) { | |
| ... | |
| showMeRocketsButton.setOnClickListener { buttonClickSubject.onNext(true) } | |
| } |
This file contains hidden or 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 : AppCompatActivity(), MainView { | |
| ... | |
| private val buttonClickSubject = PublishSubject.create<Boolean>() |
This file contains hidden or 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
| private fun reduce(previousState: MainViewState, partialState: PartialMainViewState): MainViewState { | |
| return partialState.reduce(previousState) | |
| } |
This file contains hidden or 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
| object ProgressState : PartialMainViewState() { | |
| override fun reduce(previousState: MainViewState) = MainViewState(progress = true) | |
| } | |
| object ErrorState : PartialMainViewState() { | |
| override fun reduce(previousState: MainViewState) = MainViewState(error = true) | |
| } | |
| class ListFetchedState(private val rocketList: List<Rocket>) : PartialMainViewState() { | |
| override fun reduce(previousState: MainViewState) = MainViewState(rocketList = rocketList) |
This file contains hidden or 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 PartialMainViewState { | |
| abstract fun reduce(previousState: MainViewState): MainViewState |
This file contains hidden or 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 PartialMainViewState { | |
| object ProgressState : PartialMainViewState() | |
| object ErrorState : PartialMainViewState() | |
| class ListFetchedState(val rocketList: List<Rocket>) : PartialMainViewState() | |
| } |
This file contains hidden or 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
| private fun reduce(previousState: EventProfileViewState, partialState: PartialEventProfileViewState) | |
| : EventProfileViewState { | |
| return when (partialState) { | |
| is PartialEventProfileViewState.ProgressState -> | |
| previousState.copy( | |
| progress = true) | |
| is PartialEventProfileViewState.ErrorState -> | |
| previousState.copy( | |
| progress = false, | |
| error = true, |
This file contains hidden or 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 MainPresenter(private val mainInteractor: MainInteractor) { | |
| private val compositeDisposable = CompositeDisposable() | |
| private val stateSubject = BehaviorSubject.createDefault(MainViewState()) | |
| fun bind(mainView: MainView) { | |
| val buttonClickObservable = mainView.emitButtonClick() | |
| .flatMap { mainInteractor.fetchRocketList().startWith(PartialMainViewState.ProgressState) } | |
| val mergedIntentsObservable = Observable.merge(listOf(buttonClickObservable)) |