mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
#837 simplify location history slider
This commit is contained in:
@@ -62,6 +62,8 @@
|
||||
android:paddingRight="40dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="120dp"
|
||||
app:minValue="50"
|
||||
app:maxValue="100"
|
||||
|
||||
/>
|
||||
|
||||
|
||||
@@ -221,7 +221,6 @@
|
||||
|
||||
<!-- map -->
|
||||
<string name="filter_map_on_time">Show locations in time frame</string>
|
||||
<string name="filter_last_position">Last position</string>
|
||||
<string name="show_location_traces">Show traces</string>
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user