TradeMe / MapMe

The Android maps adapter
MIT License
841 stars 75 forks source link

Reduce Factory.createMarker parameters #9

Open marcelpinto opened 7 years ago

marcelpinto commented 7 years ago

Hi,

In general, the library is pretty simple to use but there are few parts that might be confusing.

onCreateAnnotation should use the factory to create the marker and then onBindAnnotation should actually set up the marker attributes, the way is implemented feels you have to do it onCreatAnnotation since the factory requires position, bitmap and title but also during onBindAnnotation so feels like duplicating the job.

My suggestion would be that the factory only requires a position, so the MapAnnotation constructor. Then on the create Annotation you only make sure to create the marker on the position and during onBindAnnotation you set the attrs.

interface AnnotationFactory<in Map> {
    fun createMarker(latLng: LatLng): MarkerAnnotation
    ...
}

abstract class MarkerAnnotation(latLng: LatLng) : MapAnnotation() {
...
}

// MyAdapter...
override fun onBindAnnotation(annotation: MapAnnotation, position: Int, payload: Any?) {
    // Set the attributes to the annotation
}

override fun onCreateAnnotation(factory: AnnotationFactory, position: Int, annotationType: Int): MapAnnotation {
    val item = this.markers[position]
    return factory.createMarker(LatLng(item.latitude, item.longitude)
}