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
override fun onAttach(view: HomeView) { | |
view.events() | |
.flatMap(this::processEvent) | |
.subscribe(view::render) | |
.toDisposeBag() | |
} | |
private fun processEvent(event: HomeViewEvent): Observable<HomeViewModel> = when (event) { | |
is HomeViewEvent.MapReady -> Observable.empty() | |
is HomeViewEvent.MapRefresh -> loadStations(event.bounds) | |
else -> illegalAccess() | |
} | |
private fun loadStations(bounds: LatLngBounds): Observable<HomeViewModel> { | |
return stationRepository.find(bounds) | |
.map { | |
viewModel.copy( | |
stations = it.map { HomeViewModel.Station(it, false) } | |
) | |
} | |
} |
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
fun render(viewModel: HomeViewModel) { | |
} | |
fun events(): Observable<out HomeViewEvent> = Observable.merge(mapReady(), mapEvents()) | |
private fun mapReady() = rxMapView.ready(home_view_mapview) | |
.doOnSuccess { map = it } | |
.map { HomeViewEvent.MapReady() } | |
.toObservable() | |
private fun mapEvents() = rxMapView.events | |
.map { event -> | |
when (event) { | |
RxMapView.Event.CameraIdle -> HomeViewEvent.MapRefresh(map.projection.visibleRegion.latLngBounds) | |
else -> throw IllegalAccessException() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment