mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
add markers with single characters to map
This commit is contained in:
BIN
Binary file not shown.
|
After Width: | Height: | Size: 423 B |
@@ -21,6 +21,7 @@ import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.geojson.LineString;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
@@ -46,9 +47,12 @@ import java.util.Map;
|
||||
|
||||
import static com.b44t.messenger.DcContext.DC_EVENT_LOCATION_CHANGED;
|
||||
import static com.b44t.messenger.DcContext.DC_GCL_ADD_SELF;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.all;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.length;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.not;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.switchCase;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.toBool;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ANCHOR_BOTTOM_LEFT;
|
||||
@@ -64,6 +68,9 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAllowOverlap;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textIgnorePlacement;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
|
||||
import static org.thoughtcrime.securesms.map.model.MapSource.INFO_WINDOW_LAYER;
|
||||
import static org.thoughtcrime.securesms.map.model.MapSource.LINE_FEATURE_LIST;
|
||||
@@ -81,6 +88,9 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
public static final String TIMESTAMP = "TIMESTAMP";
|
||||
public static final String MESSAGE_ID = "MESSAGE_ID";
|
||||
public static final String ACCURACY = "ACCURACY";
|
||||
public static final String MARKER_CHAR = "MARKER_CHAR";
|
||||
public static final String MARKER_ICON = "MARKER_ICON";
|
||||
public static final String LAST_POSITION_ICON = "LAST_POSITION_ICON";
|
||||
private static final String INFO_WINDOW_SRC = "INFO_WINDOW_SRC";
|
||||
private static final String LAST_POSITION_LAYER = "LAST_POSITION_LAYER";
|
||||
private static final String LAST_POSITION_SOURCE = "LAST_POSITION_SRC";
|
||||
@@ -181,6 +191,7 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
if (contactMapSources.containsKey(contactId)) {
|
||||
updateSource(chatId, contactId);
|
||||
}
|
||||
Log.d(TAG, "updateEvent in MapDataManager called. finished: " + eventId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -311,6 +322,12 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
Point point = Point.fromLngLat(locations.getLongitude(i), locations.getLatitude(i));
|
||||
|
||||
String codepointChar =
|
||||
locations.getMarker(i) != null && locations.getMarker(i).length() > 0 ?
|
||||
new StringBuilder().appendCodePoint(locations.getMarker(i).codePointAt(0)).toString() :
|
||||
"";
|
||||
Log.d(TAG, "codepointChar: " + codepointChar);
|
||||
|
||||
Feature pointFeature = Feature.fromGeometry(point, new JsonObject(), String.valueOf(locations.getLocationId(i)));
|
||||
pointFeature.addBooleanProperty(MARKER_SELECTED, false);
|
||||
pointFeature.addBooleanProperty(LAST_LOCATION, false);
|
||||
@@ -318,6 +335,8 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
pointFeature.addNumberProperty(TIMESTAMP, locations.getTimestamp(i));
|
||||
pointFeature.addNumberProperty(MESSAGE_ID, locations.getMsgId(i));
|
||||
pointFeature.addNumberProperty(ACCURACY, locations.getAccuracy(i));
|
||||
pointFeature.addStringProperty(MARKER_CHAR, codepointChar);
|
||||
pointFeature.addStringProperty(MARKER_ICON, contactMapMetadata.getMarkerIcon());
|
||||
sortedPointFeatures.addFirst(pointFeature);
|
||||
|
||||
if (sortedPointFeatures.size() > 1) {
|
||||
@@ -337,10 +356,11 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
}
|
||||
|
||||
if (sortedPointFeatures.size() > 0) {
|
||||
sortedPointFeatures.get(0).addStringProperty(LAST_POSITION_ICON_ID, contactMapMetadata.getMarkerLastPositon());
|
||||
sortedPointFeatures.get(0).addBooleanProperty(LAST_LOCATION, true);
|
||||
lastPositions.remove(contactId);
|
||||
lastPositions.put(contactId, sortedPointFeatures.get(0));
|
||||
Feature lastPostion = sortedPointFeatures.getFirst();
|
||||
lastPostion.addStringProperty(LAST_POSITION_ICON, contactMapMetadata.getMarkerLastPositon());
|
||||
lastPostion.removeProperty(MARKER_ICON);
|
||||
lastPostion.addBooleanProperty(LAST_LOCATION, true);
|
||||
lastPositions.put(contactId, lastPostion);
|
||||
}
|
||||
|
||||
featureCollections.put(contactMapMetadata.getMarkerFeatureCollection(), sortedPointFeatures);
|
||||
@@ -403,14 +423,14 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
GeoJsonSource lastPositionSource = new GeoJsonSource(LAST_POSITION_SOURCE);
|
||||
mapboxStyle.addSource(lastPositionSource);
|
||||
Expression markerSize =
|
||||
switchCase(toBool(get(MARKER_SELECTED)), literal(1.5f), literal(1.0f));
|
||||
mapboxStyle.addLayer(new SymbolLayer(LAST_POSITION_LAYER, LAST_POSITION_SOURCE).withProperties(
|
||||
iconImage("{" + LAST_POSITION_ICON_ID + "}"),
|
||||
switchCase(toBool(get(MARKER_SELECTED)), literal(1.75f), literal(1.25f));
|
||||
mapboxStyle.addLayerBelow(new SymbolLayer(LAST_POSITION_LAYER, LAST_POSITION_SOURCE).withProperties(
|
||||
iconImage(get(LAST_POSITION_ICON)),
|
||||
/* all info window and marker image to appear at the same time*/
|
||||
iconAllowOverlap(true),
|
||||
iconIgnorePlacement(true),
|
||||
iconSize(markerSize)
|
||||
).withFilter(filterProvider.getRangeFilter()));
|
||||
).withFilter(filterProvider.getRangeFilter()), INFO_WINDOW_LAYER);
|
||||
}
|
||||
|
||||
private void initContactBasedLayers(MapSource source) {
|
||||
@@ -420,10 +440,13 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
generateColoredLocationIcon(source.getColorArgb()));
|
||||
|
||||
Expression markerSize =
|
||||
switchCase(toBool(get(MARKER_SELECTED)), literal(1.5f),
|
||||
switchCase(toBool(get(LAST_LOCATION)), literal(0f),
|
||||
switchCase(eq(get(MESSAGE_ID), literal(0)), literal(0.7f), literal(1.1f))));
|
||||
Expression markerIcon = switchCase(toBool(get(LAST_LOCATION)), literal(""), literal(source.getMarkerIcon()));
|
||||
switchCase(
|
||||
eq(length(get(MARKER_CHAR)), literal(1)),
|
||||
switchCase(toBool(get(MARKER_SELECTED)), literal(2.25f), literal(2.0f)),
|
||||
eq(get(MESSAGE_ID), literal(0)),
|
||||
switchCase(toBool(get(MARKER_SELECTED)), literal(1.1f), literal(1.0f)),
|
||||
switchCase(toBool(get(MARKER_SELECTED)), literal(1.1f), literal(0.7f)));
|
||||
Expression markerIcon = get(MARKER_ICON);
|
||||
|
||||
mapboxStyle.addLayerBelow(new LineLayer(source.getLineLayer(), source.getLineSource())
|
||||
.withProperties(PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
|
||||
@@ -431,20 +454,25 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
lineWidth(3f),
|
||||
lineOpacity(0.5f),
|
||||
lineColor(source.getColorArgb()),
|
||||
visibility(NONE),
|
||||
iconAllowOverlap(true),
|
||||
iconIgnorePlacement(true)
|
||||
visibility(NONE)
|
||||
)
|
||||
.withFilter(filterProvider.getRangeFilter()),
|
||||
INFO_WINDOW_LAYER);
|
||||
LAST_POSITION_LAYER);
|
||||
|
||||
|
||||
mapboxStyle.addLayerBelow(new SymbolLayer(source.getMarkerLayer(), source.getMarkerSource())
|
||||
.withProperties(
|
||||
iconImage(markerIcon),
|
||||
iconSize(markerSize))
|
||||
.withFilter(filterProvider.getMarkerFilter()),
|
||||
INFO_WINDOW_LAYER);
|
||||
iconSize(markerSize),
|
||||
textAllowOverlap(true),
|
||||
textIgnorePlacement(true),
|
||||
iconIgnorePlacement(false),
|
||||
iconAllowOverlap(false),
|
||||
textField(get(MARKER_CHAR))
|
||||
)
|
||||
.withFilter(all(filterProvider.getMarkerFilter(),
|
||||
not(get(LAST_LOCATION)))),
|
||||
LAST_POSITION_LAYER);
|
||||
}
|
||||
|
||||
private MapSource addContactMapSource(int contactId) {
|
||||
@@ -462,7 +490,7 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
|
||||
}
|
||||
|
||||
private Bitmap generateColoredLastPositionIcon(int colorFilter) {
|
||||
return generateColoredBitmap(colorFilter, R.drawable.ic_location_on_white_24dp);
|
||||
return generateColoredBitmap(colorFilter, R.drawable.ic_location_on_white_48dp);
|
||||
}
|
||||
|
||||
private Bitmap generateColoredLocationIcon(int colorFilter) {
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package org.thoughtcrime.securesms.map.model;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.Point;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Created by cyberta on 21.03.19.
|
||||
*/
|
||||
|
||||
public class FeatureTreeSet extends TreeSet<TimeComparableFeature> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param obj
|
||||
* @return true if element was added newly, false if element was replaced
|
||||
*/
|
||||
@Override
|
||||
public boolean add(@NonNull TimeComparableFeature obj) {
|
||||
boolean existed = remove(obj);
|
||||
super.add(obj);
|
||||
return !existed;
|
||||
}
|
||||
|
||||
public ArrayList<Feature> getFeatureList() {
|
||||
ArrayList<Feature> featureList = new ArrayList<>();
|
||||
Iterator<TimeComparableFeature> iterator = this.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TimeComparableFeature timeComparableFeature = iterator.next();
|
||||
featureList.add(timeComparableFeature.getFeature());
|
||||
}
|
||||
return featureList;
|
||||
}
|
||||
|
||||
public ArrayList<Point> getPointList() {
|
||||
ArrayList<Point> points = new ArrayList<>();
|
||||
Iterator<TimeComparableFeature> iterator = this.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TimeComparableFeature timeComparableFeature = iterator.next();
|
||||
try {
|
||||
points.add(Point.fromJson(timeComparableFeature.getFeature().geometry().toJson()));
|
||||
} catch (JsonSyntaxException | NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return points;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package org.thoughtcrime.securesms.map.model;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP;
|
||||
|
||||
/**
|
||||
* Created by cyberta on 21.03.19.
|
||||
*/
|
||||
|
||||
public class TimeComparableFeature implements Comparable<TimeComparableFeature> {
|
||||
private Feature feature;
|
||||
|
||||
public TimeComparableFeature(@NonNull Feature feature) {
|
||||
if (!feature.hasProperty(TIMESTAMP)) {
|
||||
throw new IllegalArgumentException("Time comparable features need to have a TIMESTAMP property");
|
||||
}
|
||||
|
||||
this.feature = feature;
|
||||
}
|
||||
|
||||
public Feature getFeature() {
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param o for same timestamps but different featureIds, this object is considered lower
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(@NonNull TimeComparableFeature o) {
|
||||
if (this.equals(o) && this.feature.getNumberProperty(TIMESTAMP).longValue() == o.getFeature().getNumberProperty(TIMESTAMP).longValue()) {
|
||||
return 0;
|
||||
}
|
||||
return this.feature.getNumberProperty(TIMESTAMP).longValue() > o.getFeature().getNumberProperty(TIMESTAMP).longValue() ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.feature.id().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || !(obj instanceof TimeComparableFeature)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TimeComparableFeature compare = (TimeComparableFeature) obj;
|
||||
return this.feature.id() != null &&
|
||||
compare.feature.id() != null &&
|
||||
this.feature.id().equals(compare.feature.id());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package org.thoughtcrime.securesms.map.model;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.Point;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP;
|
||||
import static utils.TestUtils.getPointFeature;
|
||||
|
||||
/**
|
||||
* Created by cyberta on 22.03.19.
|
||||
*/
|
||||
public class FeatureTreeSetTest {
|
||||
|
||||
@Test
|
||||
public void add_differentFeaturesIds_differentTimestamps_descendingOrder() {
|
||||
FeatureTreeSet featureTreeSet = new FeatureTreeSet();
|
||||
|
||||
Feature point2 = getPointFeature("3");
|
||||
point2.addNumberProperty(TIMESTAMP, 2);
|
||||
featureTreeSet.add(new TimeComparableFeature(point2));
|
||||
|
||||
Feature point = getPointFeature("2");
|
||||
point.addNumberProperty(TIMESTAMP, 1);
|
||||
featureTreeSet.add(new TimeComparableFeature(point));
|
||||
|
||||
featureTreeSet.add(new TimeComparableFeature(getPointFeature("1")));
|
||||
|
||||
Iterator<TimeComparableFeature> iterator = featureTreeSet.iterator();
|
||||
assertEquals(123456789, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue());
|
||||
assertEquals(2, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue());
|
||||
assertEquals(1, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void add_sameFeaturesIds_differentTimestamps_descendingOrder() {
|
||||
FeatureTreeSet featureTreeSet = new FeatureTreeSet();
|
||||
|
||||
Feature point2 = getPointFeature();
|
||||
point2.addNumberProperty(TIMESTAMP, 2);
|
||||
featureTreeSet.add(new TimeComparableFeature(point2));
|
||||
|
||||
Feature point = getPointFeature();
|
||||
point.addNumberProperty(TIMESTAMP, 1);
|
||||
featureTreeSet.add(new TimeComparableFeature(point));
|
||||
|
||||
featureTreeSet.add(new TimeComparableFeature(getPointFeature("1")));
|
||||
|
||||
|
||||
Iterator<TimeComparableFeature> iterator = featureTreeSet.iterator();
|
||||
assertEquals(123456789, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue());
|
||||
assertEquals(2, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue());
|
||||
assertEquals(1, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void add_sameFeaturesIds_sameTimestamps_noDuplicatedEntries() {
|
||||
FeatureTreeSet featureTreeSet = new FeatureTreeSet();
|
||||
featureTreeSet.add(new TimeComparableFeature(getPointFeature()));
|
||||
featureTreeSet.add(new TimeComparableFeature(getPointFeature()));
|
||||
assertEquals(1, featureTreeSet.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void add_sameFeaturesIds_sameTimestamps_elementReplaced() {
|
||||
FeatureTreeSet featureTreeSet = new FeatureTreeSet();
|
||||
Feature feature = getPointFeature();
|
||||
feature.addStringProperty("Test", "element1");
|
||||
featureTreeSet.add(new TimeComparableFeature(feature));
|
||||
featureTreeSet.add(new TimeComparableFeature(getPointFeature()));
|
||||
assertFalse(featureTreeSet.first().getFeature().hasProperty("Test"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void getFeatureList_returnsOrderedList() throws Exception {
|
||||
FeatureTreeSet featureTreeSet = new FeatureTreeSet();
|
||||
|
||||
Feature point2 = getPointFeature();
|
||||
point2.addNumberProperty(TIMESTAMP, 2);
|
||||
featureTreeSet.add(new TimeComparableFeature(point2));
|
||||
|
||||
Feature point = getPointFeature();
|
||||
point.addNumberProperty(TIMESTAMP, 1);
|
||||
featureTreeSet.add(new TimeComparableFeature(point));
|
||||
|
||||
featureTreeSet.add(new TimeComparableFeature(getPointFeature("1")));
|
||||
|
||||
ArrayList<Feature> features = featureTreeSet.getFeatureList();
|
||||
assertEquals(123456789, features.get(0).getNumberProperty(TIMESTAMP).longValue());
|
||||
assertEquals(2, features.get(1).getNumberProperty(TIMESTAMP).longValue());
|
||||
assertEquals(1, features.get(2).getNumberProperty(TIMESTAMP).longValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPointList_returnsOrderedPointList() throws Exception {
|
||||
FeatureTreeSet featureTreeSet = new FeatureTreeSet();
|
||||
|
||||
Feature point = getPointFeature("id2", 1.00, 1.00);
|
||||
point.addNumberProperty(TIMESTAMP, 2);
|
||||
featureTreeSet.add(new TimeComparableFeature(point));
|
||||
|
||||
Feature point2 = getPointFeature("id1", 2.00, 2.00);
|
||||
point2.addNumberProperty(TIMESTAMP, 1);
|
||||
featureTreeSet.add(new TimeComparableFeature(point2));
|
||||
|
||||
|
||||
Feature point3 = getPointFeature("id3", 3.00, 3.00);
|
||||
point3.addNumberProperty(TIMESTAMP, 3);
|
||||
|
||||
featureTreeSet.add(new TimeComparableFeature(point3));
|
||||
|
||||
|
||||
ArrayList<Point> points = featureTreeSet.getPointList();
|
||||
assertEquals(new Double(3.00), points.get(0).coordinates().get(0));
|
||||
assertEquals(new Double(1.00), points.get(1).coordinates().get(0));
|
||||
assertEquals(new Double(2.00), points.get(2).coordinates().get(0));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package org.thoughtcrime.securesms.map.model;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP;
|
||||
import static utils.TestUtils.getPointFeature;
|
||||
|
||||
/**
|
||||
* Created by cyberta on 22.03.19.
|
||||
*/
|
||||
|
||||
public class TimeComparableFeatureTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void init_noTimestamp_throwIllegalStateException() throws Exception {
|
||||
Feature feature = getPointFeature();
|
||||
feature.removeProperty(TIMESTAMP);
|
||||
new TimeComparableFeature(feature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_sameTimestamp_return0() throws Exception {
|
||||
TimeComparableFeature tcf1 = new TimeComparableFeature(getPointFeature());
|
||||
TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature());
|
||||
|
||||
assertEquals(0, tcf1.compareTo(tcf2));
|
||||
assertEquals(0, tcf2.compareTo(tcf1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_biggerTimestamp_return1() throws Exception {
|
||||
Feature feature = getPointFeature();
|
||||
feature.addNumberProperty(TIMESTAMP, 234567890);
|
||||
TimeComparableFeature tcf1 = new TimeComparableFeature(getPointFeature());
|
||||
TimeComparableFeature tcf2 = new TimeComparableFeature(feature);
|
||||
|
||||
assertEquals(1, tcf1.compareTo(tcf2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_biggerTimestamp_returnMinus1() throws Exception {
|
||||
Feature feature = getPointFeature();
|
||||
feature.addNumberProperty(TIMESTAMP, 234567890);
|
||||
TimeComparableFeature tcf1 = new TimeComparableFeature(feature);
|
||||
TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature());
|
||||
|
||||
assertEquals(-1, tcf1.compareTo(tcf2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo_sameTimestamp_differntId_returnMinus1() throws Exception {
|
||||
Feature feature = getPointFeature();
|
||||
feature.addNumberProperty(TIMESTAMP, 234567890);
|
||||
TimeComparableFeature tcf1 = new TimeComparableFeature(feature);
|
||||
TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature());
|
||||
|
||||
assertEquals(-1, tcf1.compareTo(tcf2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_differentObjects_sameId_returnTrue() throws Exception {
|
||||
TimeComparableFeature tcf1 = new TimeComparableFeature(getPointFeature());
|
||||
TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature());
|
||||
|
||||
assertEquals(true, tcf1.equals(tcf2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_differentObjects_differentId_returnFalse() throws Exception {
|
||||
Feature feature = getPointFeature("id2");
|
||||
TimeComparableFeature tcf1 = new TimeComparableFeature(feature);
|
||||
TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature());
|
||||
|
||||
assertEquals(false, tcf1.equals(tcf2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_differentObjects_differentId_sameTimeStamp_returnFalse() throws Exception {
|
||||
Feature feature = getPointFeature("id2");
|
||||
TimeComparableFeature tcf1 = new TimeComparableFeature(feature);
|
||||
TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature());
|
||||
|
||||
assertEquals(false, tcf1.equals(tcf2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_differentObjects_sameId_differentTimeStamp_returnTrue() throws Exception {
|
||||
Feature feature = getPointFeature();
|
||||
feature.addNumberProperty(TIMESTAMP, 234567890);
|
||||
TimeComparableFeature tcf1 = new TimeComparableFeature(feature);
|
||||
TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature());
|
||||
|
||||
assertEquals(true, tcf1.equals(tcf2));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package utils;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.Point;
|
||||
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.ACCURACY;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.CONTACT_ID;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.INFO_WINDOW_ID;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.LAST_LOCATION;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.MARKER_SELECTED;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.MESSAGE_ID;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP;
|
||||
|
||||
/**
|
||||
* Created by cyberta on 22.03.19.
|
||||
*/
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
public static Feature getPointFeature(String id) {
|
||||
return getPointFeature(id, 10.00, 52.00);
|
||||
}
|
||||
|
||||
public static Feature getPointFeature() {
|
||||
return getPointFeature("id1");
|
||||
}
|
||||
|
||||
public static Feature getPointFeature(String id, double latitude, double longitude) {
|
||||
Point p = Point.fromLngLat(longitude, latitude);
|
||||
Feature pointFeature = Feature.fromGeometry(p, new JsonObject(), id);
|
||||
pointFeature.addBooleanProperty(MARKER_SELECTED, false);
|
||||
pointFeature.addBooleanProperty(LAST_LOCATION, false);
|
||||
pointFeature.addNumberProperty(CONTACT_ID, 1);
|
||||
pointFeature.addStringProperty(INFO_WINDOW_ID, "0_1_info_2");
|
||||
pointFeature.addNumberProperty(TIMESTAMP, 123456789);
|
||||
pointFeature.addNumberProperty(MESSAGE_ID, 1);
|
||||
pointFeature.addNumberProperty(ACCURACY, 12);
|
||||
return Feature.fromJson(pointFeature.toJson());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user