Commit 7271b25e authored by Mudar Noufal's avatar Mudar Noufal

Refactoring Placemarks to support layerType

parent d541948f
......@@ -30,8 +30,9 @@ import com.google.android.gms.maps.model.LatLng;
import java.util.List;
import ca.mudar.mtlaucasou.model.Placemark;
import ca.mudar.mtlaucasou.model.LayerType;
import ca.mudar.mtlaucasou.model.MapType;
import ca.mudar.mtlaucasou.model.Placemark;
import ca.mudar.mtlaucasou.model.SuggestionsPlacemark;
import static ca.mudar.mtlaucasou.util.LogUtils.makeLogTag;
......@@ -71,6 +72,7 @@ public class SuggestionsCursorHelper {
id,
place.getName(),
place.getMapType(),
place.getLayerType(),
place.getLatLng().latitude,
place.getLatLng().longitude
};
......@@ -104,8 +106,14 @@ public class SuggestionsCursorHelper {
cursor.getDouble(PlacemarksQuery.LATITUDE),
cursor.getDouble(PlacemarksQuery.LONGITUDE));
final @MapType String mapType = cursor.getString(PlacemarksQuery.MAP_TYPE);
return new SuggestionsPlacemark(name, position, mapType);
final @LayerType String layerType = cursor.getString(PlacemarksQuery.LAYER_TYPE);
return new SuggestionsPlacemark.Builder()
.name(name)
.latlng(position)
.maptype(mapType)
.layertype(layerType)
.build();
}
/**
......@@ -122,7 +130,8 @@ public class SuggestionsCursorHelper {
String[] PROJECTION = {
"_id",
"title",
"type",
"mapType",
"layerType",
"latitude",
"longitude",
};
......@@ -131,7 +140,8 @@ public class SuggestionsCursorHelper {
int _ID = 0;
int TITLE = 1;
int MAP_TYPE = 2;
int LATITUDE = 3;
int LONGITUDE = 4;
int LAYER_TYPE = 3;
int LATITUDE = 4;
int LONGITUDE = 5;
}
}
......@@ -34,4 +34,7 @@ public interface Placemark {
@MapType
String getMapType();
@LayerType
String getLayerType();
}
......@@ -41,11 +41,11 @@ public class SuggestionsPlacemark implements
LatLng latLng;
@MapType
String mapType;
@LayerType
String layerType;
public SuggestionsPlacemark(String name, LatLng latLng, @MapType String mapType) {
this.name = name;
this.latLng = latLng;
this.mapType = mapType;
public SuggestionsPlacemark() {
// Empty constructor
}
@Override
......@@ -69,10 +69,17 @@ public class SuggestionsPlacemark implements
return mapType;
}
@Override
@LayerType
public String getLayerType() {
return layerType;
}
private SuggestionsPlacemark(Builder builder) {
this.name = builder.name;
this.latLng = builder.latLng;
this.mapType = builder.mapType;
this.layerType = builder.layerType;
}
@Override
......@@ -86,11 +93,43 @@ public class SuggestionsPlacemark implements
LatLng latLng;
@MapType
String mapType;
@LayerType
String layerType;
public Builder() {
}
public Builder(Placemark placemark) {
public Builder placemark(Placemark placemark) {
this.name = placemark.getName();
this.latLng = placemark.getLatLng();
this.mapType = placemark.getMapType();
this.layerType = placemark.getLayerType();
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder latlng(LatLng latLng) {
this.latLng = latLng;
return this;
}
public Builder maptype(@MapType String mapType) {
this.mapType = mapType;
return this;
}
public Builder layertype(@LayerType String layerType) {
this.layerType = layerType;
return this;
}
public SuggestionsPlacemark build() {
......
......@@ -139,8 +139,9 @@ public class PlacemarkSearchAdapter extends CursorAdapter implements
final List<SuggestionsPlacemark> suggestions = new ArrayList<>();
for (RealmPlacemark realmPlacemark : realmPlacemarks) {
// Convert each RealmPlacemark then add it to the results list
suggestions.add(
new SuggestionsPlacemark.Builder(realmPlacemark).build());
suggestions.add(new SuggestionsPlacemark.Builder()
.placemark(realmPlacemark)
.build());
}
Collections.sort(suggestions);
results.values = suggestions;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment