Skip to content

Issue #9: Improve Factory method #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package nz.co.trademe.mapme.googlemaps

import android.graphics.Bitmap
import com.google.android.gms.maps.GoogleMap
import nz.co.trademe.mapme.LatLng
import nz.co.trademe.mapme.annotations.AnnotationFactory
import nz.co.trademe.mapme.annotations.MarkerAnnotation

class GoogleMapAnnotationFactory : AnnotationFactory<GoogleMap> {

override fun createMarker(latLng: LatLng, icon: Bitmap?, title: String?): MarkerAnnotation {
return GoogleMapMarkerAnnotation(latLng, title, icon)
override fun createMarker(latLng: LatLng): MarkerAnnotation {
return GoogleMapMarkerAnnotation(latLng)
}

override fun clear(map: GoogleMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import com.google.android.gms.maps.model.MarkerOptions
import nz.co.trademe.mapme.LatLng
import nz.co.trademe.mapme.annotations.MarkerAnnotation

class GoogleMapMarkerAnnotation(latLng: LatLng,
title: String?,
icon: Bitmap? = null) : MarkerAnnotation(latLng, title, icon) {
class GoogleMapMarkerAnnotation(latLng: LatLng) : MarkerAnnotation(latLng) {

override fun onUpdateIcon(icon: Bitmap?) {
nativeMarker?.setIcon(icon?.toBitmapDescriptor())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package nz.co.trademe.mapme.mapbox

import android.graphics.Bitmap
import com.mapbox.mapboxsdk.maps.MapboxMap
import nz.co.trademe.mapme.LatLng
import nz.co.trademe.mapme.annotations.AnnotationFactory
import nz.co.trademe.mapme.annotations.MarkerAnnotation

class MapboxAnnotationFactory : AnnotationFactory<MapboxMap> {

override fun createMarker(latLng: LatLng, icon: Bitmap?, title: String?): MarkerAnnotation {
return MapboxMarkerAnnotation(latLng, title, icon)
override fun createMarker(latLng: LatLng): MarkerAnnotation {
return MapboxMarkerAnnotation(latLng)
}

override fun clear(map: MapboxMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap
import nz.co.trademe.mapme.LatLng
import nz.co.trademe.mapme.annotations.MarkerAnnotation

class MapboxMarkerAnnotation(latLng: LatLng,
title: String?,
icon: Bitmap? = null) : MarkerAnnotation(latLng, title, icon) {

class MapboxMarkerAnnotation(latLng: LatLng) : MarkerAnnotation(latLng) {

override fun onUpdateIcon(icon: Bitmap?) {
nativeMarker?.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package nz.co.trademe.mapme.annotations

import android.graphics.Bitmap
import nz.co.trademe.mapme.LatLng

interface AnnotationFactory<in Map> {

fun createMarker(latLng: LatLng, icon: Bitmap?, title: String?): MarkerAnnotation
fun createMarker(latLng: LatLng): MarkerAnnotation

fun clear(map: Map)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,33 @@ package nz.co.trademe.mapme.annotations
import android.graphics.Bitmap
import nz.co.trademe.mapme.LatLng

abstract class MarkerAnnotation(latLng: LatLng,
title: String? = null,
icon: Bitmap? = null,
zIndex: Float = 0f,
alpha: Float = 1f) : MapAnnotation() {
abstract class MarkerAnnotation(latLng: LatLng) : MapAnnotation() {

var latLng: LatLng = latLng
set(value) {
field = value
onUpdatePosition(value)
}

var title: String? = title
var title: String? = null
set(value) {
field = value
onUpdateTitle(value)
}

var icon: Bitmap? = icon
var icon: Bitmap? = null
set(value) {
field = value
onUpdateIcon(value)
}

var zIndex: Float = zIndex
var zIndex: Float = 0f
set(value) {
field = value
onUpdateZIndex(value)
}

var alpha: Float = alpha
var alpha: Float = 1f
set(value) {
field = value
onUpdateAlpha(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package nz.co.trademe.mapme.util

class TestAnnotation : nz.co.trademe.mapme.annotations.MarkerAnnotation(nz.co.trademe.mapme.LatLng(0.0, 0.0), "", null, 0f, 1f) {
import nz.co.trademe.mapme.LatLng
import nz.co.trademe.mapme.annotations.MarkerAnnotation

class TestAnnotation : MarkerAnnotation(LatLng(0.0, 0.0)) {

override fun annotatesObject(nativeObject: Any): Boolean {
return false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package nz.co.trademe.mapme.util

class TestAnnotationFactory : nz.co.trademe.mapme.annotations.AnnotationFactory<TestMap> {
import nz.co.trademe.mapme.LatLng
import nz.co.trademe.mapme.annotations.AnnotationFactory
import nz.co.trademe.mapme.annotations.MarkerAnnotation

override fun createMarker(latLng: nz.co.trademe.mapme.LatLng, icon: android.graphics.Bitmap?, title: String?): nz.co.trademe.mapme.annotations.MarkerAnnotation {
class TestAnnotationFactory : AnnotationFactory<TestMap> {

override fun createMarker(latLng: LatLng): MarkerAnnotation {
return TestAnnotation()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ public SampleMapMeAdapter(@NonNull Context context, @NonNull List<MarkerData> ma
@Override
public MapAnnotation onCreateAnnotation(@NotNull AnnotationFactory<M> mapFactory, int position, int viewType) {
MarkerData item = this.markers.get(position);
return mapFactory.createMarker(item.getLatLng(), getIconBitmap(item), item.getTitle());
return mapFactory.createMarker(item.getLatLng());
}

@Override
public void onBindAnnotation(@NotNull MapAnnotation annotation, int position, Object payload) {
if (annotation instanceof MarkerAnnotation) {
MarkerData item = this.markers.get(position);
((MarkerAnnotation) annotation).setIcon(getIconBitmap(item));
((MarkerAnnotation) annotation).setTitle(item.getTitle());
}
}

Expand Down