| HERE Public Abstracting the map | June 24, 2018 6 LatLng M arkerOptions M apActivity Som eM apPresenter Som eM apView GoogleM ap Location … SearchRepository PlaceRepository Som eRepository
map | June 24, 2018 8 class MapViewModel: ViewModel() { private val _mapItems = MediatorLiveData<List<MapItem>>() private val searchRepository = SearchRepository() private val placeRepository = PlaceRepository() init { // Add sources to the _mapItems mediator _mapItems.addSource(searchRepository.searchItems) { updateItems() } _mapItems.addSource(placeRepository.placeItems) { updateItems() } } fun getMapItems(): LiveData<List<MapItem>> = _mapItems private fun updateItems() { val searchItems = searchRepository.searchItems.value?.map { MapItem.Point.Marker.Search(it.id, it.position) }.orEmpty() val placeItems = placeRepository.placeItems.value?.map { MapItem.Point.Marker.Place(it.id, it.position) }.orEmpty() // Apply some logic to decide which ones to show or filter... _mapItems.postValue(searchItems.plus(placeItems)) } }
map | June 24, 2018 9 class MapViewModel: ViewModel() { private val _mapItems = MediatorLiveData<List<MapItem>>() private val searchRepository = SearchRepository() private val placeRepository = PlaceRepository() init { // Add sources to the _mapItems mediator _mapItems.addSource(searchRepository.searchItems) { updateItems() } _mapItems.addSource(placeRepository.placeItems) { updateItems() } } fun getMapItems(): LiveData<List<MapItem>> = _mapItems private fun updateItems() { val searchItems = searchRepository.searchItems.value?.map { MapItem.Point.Marker.Search(it.id, it.position) }.orEmpty() val placeItems = placeRepository.placeItems.value?.map { MapItem.Point.Marker.Place(it.id, it.position) }.orEmpty() // Apply some logic to decide which ones to show or filter... _mapItems.postValue(searchItems.plus(placeItems)) } }
map | June 24, 2018 10 class MapViewModel: ViewModel() { private val _mapItems = MediatorLiveData<List<MapItem>>() private val searchRepository = SearchRepository() private val placeRepository = PlaceRepository() init { // Add sources to the _mapItems mediator _mapItems.addSource(searchRepository.searchItems) { updateItems() } _mapItems.addSource(placeRepository.placeItems) { updateItems() } } fun getMapItems(): LiveData<List<MapItem>> = _mapItems private fun updateItems() { val searchItems = searchRepository.searchItems.value?.map { MapItem.Point.Marker.Search(it.id, it.position) }.orEmpty() val placeItems = placeRepository.placeItems.value?.map { MapItem.Point.Marker.Place(it.id, it.position) }.orEmpty() // Apply some logic to decide which ones to show or filter... _mapItems.postValue(searchItems.plus(placeItems)) } }
map | June 24, 2018 11 class MapViewModel: ViewModel() { private val _mapItems = MediatorLiveData<List<MapItem>>() private val searchRepository = SearchRepository() private val placeRepository = PlaceRepository() init { // Add sources to the _mapItems mediator _mapItems.addSource(searchRepository.searchItems) { updateItems() } _mapItems.addSource(placeRepository.placeItems) { updateItems() } } fun getMapItems(): LiveData<List<MapItem>> = _mapItems private fun updateItems() { val searchItems = searchRepository.searchItems.value?.map { MapItem.Point.Marker.Search(it.id, it.position) }.orEmpty() val placeItems = placeRepository.placeItems.value?.map { MapItem.Point.Marker.Place(it.id, it.position) }.orEmpty() // Apply some logic to decide which ones to show or filter... _mapItems.postValue(searchItems.plus(placeItems)) } }
| June 24, 2018 16 data class GeoCoordinate(val latitude: Double, val longitude: Double) sealed class MapItem { abstract val id: String sealed class Path : MapItem() { data class Route(override val id: String, val path: List<Point>) : Path() } sealed class Point : MapItem() { abstract val coordinate: GeoCoordinate sealed class Marker(override val id: String, override val coordinate: GeoCoordinate) : Point() { data class Search(override val id: String, override val coordinate: GeoCoordinate) : Marker(id, coordinate) data class Place(override val id: String, override val coordinate: GeoCoordinate) : Marker(id, coordinate) } } }
| June 24, 2018 17 data class GeoCoordinate(val latitude: Double, val longitude: Double) sealed class MapItem { abstract val id: String sealed class Path : MapItem() { data class Route(override val id: String, val path: List<Point>) : Path() } sealed class Point : MapItem() { abstract val coordinate: GeoCoordinate sealed class Marker(override val id: String, override val coordinate: GeoCoordinate) : Point() { data class Search(override val id: String, override val coordinate: GeoCoordinate) : Marker(id, coordinate) data class Place(override val id: String, override val coordinate: GeoCoordinate) : Marker(id, coordinate) } } }
| June 24, 2018 18 fun getMapItems(): LiveData<List<MapItem>> = _mapItems private fun updateItems() { val searchItems = searchRepository.searchItems.value?.map { MapItem.Point.Marker.Search(it.id, it.position) }.orEmpty() val placeItems = placeRepository.placeItems.value?.map { MapItem.Point.Marker.Place(it.id, it.position) }.orEmpty() // Apply some logic to decide which ones to show or filter... _mapItems.postValue(searchItems.plus(placeItems)) }
| June 24, 2018 19 fun getMapItems(): LiveData<List<MapItem>> = _mapItems private fun updateItems() { val searchItems = searchRepository.searchItems.value?.map { MapItem.Point.Marker.Search(it.id, it.position) }.orEmpty() val placeItems = placeRepository.placeItems.value?.map { MapItem.Point.Marker.Place(it.id, it.position) }.orEmpty() // Apply some logic to decide which ones to show or filter... _mapItems.postValue(searchItems.plus(placeItems)) } Immutable LiveData
| June 24, 2018 20 fun getMapItems(): LiveData<List<MapItem>> = _mapItems private fun updateItems() { val searchItems = searchRepository.searchItems.value?.map { MapItem.Point.Marker.Search(it.id, it.position) }.orEmpty() val placeItems = placeRepository.placeItems.value?.map { MapItem.Point.Marker.Place(it.id, it.position) }.orEmpty() // Apply some logic to decide which ones to show or filter... _mapItems.postValue(searchItems.plus(placeItems)) } Immutable LiveData New Immutable Object
| June 24, 2018 21 fun getMapItems(): LiveData<List<MapItem>> = _mapItems private fun updateItems() { val searchItems = searchRepository.searchItems.value?.map { MapItem.Point.Marker.Search(it.id, it.position) }.orEmpty() val placeItems = placeRepository.placeItems.value?.map { MapItem.Point.Marker.Place(it.id, it.position) }.orEmpty() // Apply some logic to decide which ones to show or filter... _mapItems.postValue(searchItems.plus(placeItems)) } New Immutable list Immutable LiveData New Immutable Object
| June 24, 2018 23 LatLng M arkerOptions GoogleM ap Cam eraUpdate … Som eFragm ent Som eViewM odel M apFragm ent M apViewM odel SearchRepository PlaceRepository M ainInteractor