From 9c43f8ef5d964dd6c5d00e457aad6322bfbf4287 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 16 Apr 2019 09:13:10 +0200 Subject: [PATCH] #837 simplify location history slider --- res/layout/bottom_map_sheet.xml | 2 ++ res/values/strings.xml | 1 - .../rangeslider/TimeRangeSlider.java | 31 ++----------------- .../securesms/map/MapActivity.java | 7 ----- .../securesms/map/MapDataManager.java | 9 ++---- .../securesms/map/model/FilterProvider.java | 17 +--------- 6 files changed, 7 insertions(+), 60 deletions(-) diff --git a/res/layout/bottom_map_sheet.xml b/res/layout/bottom_map_sheet.xml index 038c28804..39ee176bc 100644 --- a/res/layout/bottom_map_sheet.xml +++ b/res/layout/bottom_map_sheet.xml @@ -62,6 +62,8 @@ android:paddingRight="40dp" android:layout_width="match_parent" android:layout_height="120dp" + app:minValue="50" + app:maxValue="100" /> diff --git a/res/values/strings.xml b/res/values/strings.xml index 6d0eb8bc1..61cf04d9e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -221,7 +221,6 @@ Show locations in time frame - Last position Show traces diff --git a/src/org/thoughtcrime/securesms/components/rangeslider/TimeRangeSlider.java b/src/org/thoughtcrime/securesms/components/rangeslider/TimeRangeSlider.java index 68d0fd800..0e9e503f0 100644 --- a/src/org/thoughtcrime/securesms/components/rangeslider/TimeRangeSlider.java +++ b/src/org/thoughtcrime/securesms/components/rangeslider/TimeRangeSlider.java @@ -18,7 +18,6 @@ import java.util.Locale; public class TimeRangeSlider extends RangeSliderView implements RangeSliderView.OnValueChangedListener { private static final int DEFAULT_TIMEFRAME_2D = 60 * 60 * 24 * 2; // 2d private static final float DEFAULT_DELTA = 1000 * 60 * 30; // 30 min - private static final float LAST_POSITON_DELTA = 1000 * 60 * 60 * 24; //1d int timeFrame; // timeframe in seconds Locale locale; @@ -91,12 +90,6 @@ public class TimeRangeSlider extends RangeSliderView implements RangeSliderView. public interface OnTimestampChangedListener { void onTimestampChanged(long startTimestamp, long stopTimestamp); - - /** - * filter for lastPosition beginning from startTimestamp to now - * @param startTimestamp begin of time frame - */ - void onFilterLastPosition(long startTimestamp); } @@ -109,13 +102,8 @@ public class TimeRangeSlider extends RangeSliderView implements RangeSliderView. if (listener != null) { long minTimeStamp = getTimestampForValue(minValue); if (minValue == maxValue) { - if (minValue == getCount()) { - // filter last location - listener.onFilterLastPosition(System.currentTimeMillis() - (long) LAST_POSITON_DELTA); - } else { - // filter for time of event with delta before and after - listener.onTimestampChanged(minTimeStamp - (long) DEFAULT_DELTA, minTimeStamp + (long) DEFAULT_DELTA); - } + // filter for time of event with delta before and after + listener.onTimestampChanged(minTimeStamp - (long) DEFAULT_DELTA, minTimeStamp + (long) DEFAULT_DELTA); } else { //filter for time span listener.onTimestampChanged(minTimeStamp, getTimestampForValue(maxValue)); @@ -133,9 +121,6 @@ public class TimeRangeSlider extends RangeSliderView implements RangeSliderView. @Override public String parseMaxValueDisplayText(int maxValue) { - if (minValue == maxValue && maxValue == getCount()) { - return getContext().getResources().getString(R.string.filter_last_position); - } return getStringForValue(maxValue); } @@ -157,20 +142,8 @@ public class TimeRangeSlider extends RangeSliderView implements RangeSliderView. * @return normalized delta */ private float getDelta() { - if (minValue == getCount()) { - return getLastPositionDelta(); - } else { - return getDefaultDelta(); - } - } - - private float getDefaultDelta() { return DEFAULT_DELTA / (timeFrame * 1000) * getCount(); } - private float getLastPositionDelta() { - return LAST_POSITON_DELTA / (timeFrame * 1000) * getCount(); - } - } diff --git a/src/org/thoughtcrime/securesms/map/MapActivity.java b/src/org/thoughtcrime/securesms/map/MapActivity.java index e994238a3..6b3ad3dc5 100644 --- a/src/org/thoughtcrime/securesms/map/MapActivity.java +++ b/src/org/thoughtcrime/securesms/map/MapActivity.java @@ -235,11 +235,4 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid } - @Override - public void onFilterLastPosition(long startTimestamp) { - if (this.mapboxMap == null) { - return; - } - mapDataManager.filterLastPositions(startTimestamp); - } } diff --git a/src/org/thoughtcrime/securesms/map/MapDataManager.java b/src/org/thoughtcrime/securesms/map/MapDataManager.java index 43e8a074d..077888f9f 100644 --- a/src/org/thoughtcrime/securesms/map/MapDataManager.java +++ b/src/org/thoughtcrime/securesms/map/MapDataManager.java @@ -110,7 +110,8 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn initInfoWindowLayer(); filterProvider.setMessageFilter(true); - filterProvider.setLastPositionFilter(System.currentTimeMillis() - DEFAULT_LAST_POSITION_DELTA); + long now = System.currentTimeMillis(); + filterProvider.setRangeFilter(now - DEFAULT_LAST_POSITION_DELTA, now); for (int contactId : contactIds) { updateSource(chatId, contactId, boundingBuilder); MapSource source = contactMapSources.get(contactId); @@ -224,12 +225,6 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn applyFilters(contactIds); } - public void filterLastPositions(long startTimestamp) { - int[] contactIds = getContactIds(chatId); - filterProvider.setLastPositionFilter(startTimestamp); - applyFilters(contactIds); - } - public void showTraces(boolean show) { int[] contactIds = getContactIds(chatId); this.showTraces = show; diff --git a/src/org/thoughtcrime/securesms/map/model/FilterProvider.java b/src/org/thoughtcrime/securesms/map/model/FilterProvider.java index ffb42701a..da1483437 100644 --- a/src/org/thoughtcrime/securesms/map/model/FilterProvider.java +++ b/src/org/thoughtcrime/securesms/map/model/FilterProvider.java @@ -7,16 +7,13 @@ import com.mapbox.mapboxsdk.style.expressions.Expression; import java.util.HashMap; 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.gte; import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; import static com.mapbox.mapboxsdk.style.expressions.Expression.lte; import static com.mapbox.mapboxsdk.style.expressions.Expression.neq; -import static org.thoughtcrime.securesms.map.MapDataManager.LAST_LOCATION; import static org.thoughtcrime.securesms.map.MapDataManager.MESSAGE_ID; import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP; -import static org.thoughtcrime.securesms.map.model.FilterProvider.FilterType.LAST_POSITION; import static org.thoughtcrime.securesms.map.model.FilterProvider.FilterType.MESSAGES; import static org.thoughtcrime.securesms.map.model.FilterProvider.FilterType.RANGE; @@ -27,7 +24,6 @@ import static org.thoughtcrime.securesms.map.model.FilterProvider.FilterType.RAN public class FilterProvider { public enum FilterType { RANGE, - LAST_POSITION, MESSAGES } @@ -35,17 +31,9 @@ public class FilterProvider { public void setRangeFilter(long startTimestamp, long endTimestamp) { - expressions.remove(LAST_POSITION); addFilter(RANGE, all( lte(get(TIMESTAMP), endTimestamp), gte(get(TIMESTAMP), startTimestamp))); - - } - public void setLastPositionFilter(long startTimestamp) { - expressions.remove(RANGE); - addFilter(LAST_POSITION, all( - eq((get(LAST_LOCATION)), literal(true)), - gte(get(TIMESTAMP), startTimestamp))); } public void setMessageFilter(boolean filter) { @@ -69,12 +57,9 @@ public class FilterProvider { } public Expression getLineFilter() { - if (expressions.get(LAST_POSITION) != null) { - return expressions.get(LAST_POSITION); - } else if (expressions.get(RANGE) != null) { + if (expressions.get(RANGE) != null) { return expressions.get(RANGE); } - return all(); }