Created
May 30, 2017 14:23
-
-
Save lukaspili/36781cb9c5f0c06112313dbc053a6033 to your computer and use it in GitHub Desktop.
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 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 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
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