Add states for the "apply" button; add lines filtering

This commit is contained in:
Alexander Sytnyk 2017-06-26 17:54:19 +03:00
parent 62be4e773e
commit 972ad84196
2 changed files with 42 additions and 14 deletions

View file

@ -107,6 +107,13 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment {
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
view.findViewById(R.id.warning_linear_layout).setVisibility(View.GONE);
if (charSequence.length() > 0 ||
settings.MAPILLARY_FILTER_TO_DATE.get() != 0 ||
settings.MAPILLARY_FILTER_FROM_DATE.get() != 0) {
changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
} else {
changeButtonState((Button) view.findViewById(R.id.button_apply), .5f, false);
}
}
@Override
@ -122,13 +129,14 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment {
final EditText dateFromEt = (EditText) view.findViewById(R.id.date_from_edit_text);
final DatePickerDialog.OnDateSetListener dateFromDialog = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
public void onDateSet(DatePicker v, int year, int monthOfYear, int dayOfMonth) {
Calendar from = Calendar.getInstance();
from.set(Calendar.YEAR, year);
from.set(Calendar.MONTH, monthOfYear);
from.set(Calendar.DAY_OF_MONTH, dayOfMonth);
dateFromEt.setText(dateFormat.format(from.getTime()));
settings.MAPILLARY_FILTER_FROM_DATE.set(from.getTimeInMillis());
changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
}
};
dateFromEt.setOnClickListener(new View.OnClickListener() {
@ -147,13 +155,14 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment {
final EditText dateToEt = (EditText) view.findViewById(R.id.date_to_edit_text);
final DatePickerDialog.OnDateSetListener dateToDialog = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
public void onDateSet(DatePicker v, int year, int monthOfYear, int dayOfMonth) {
Calendar to = Calendar.getInstance();
to.set(Calendar.YEAR, year);
to.set(Calendar.MONTH, monthOfYear);
to.set(Calendar.DAY_OF_MONTH, dayOfMonth);
dateToEt.setText(dateFormat.format(to.getTime()));
settings.MAPILLARY_FILTER_TO_DATE.set(to.getTimeInMillis());
changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
}
};
dateToEt.setOnClickListener(new View.OnClickListener() {
@ -181,6 +190,7 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment {
final Button apply = (Button) view.findViewById(R.id.button_apply);
changeButtonState(apply, .5f, false);
apply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -200,6 +210,9 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment {
if (dateTo.equals("")) {
settings.MAPILLARY_FILTER_TO_DATE.set(0L);
}
changeButtonState(apply, .5f, false);
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
}
});
@ -217,6 +230,9 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment {
settings.MAPILLARY_FILTER_USERNAME.set("");
settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
settings.MAPILLARY_FILTER_TO_DATE.set(0L);
changeButtonState(apply, .5f, false);
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
}
});
@ -228,4 +244,9 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment {
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
mapActivity.getDashboard().refreshContent(true);
}
private void changeButtonState(Button button, float alpha, boolean enabled) {
button.setAlpha(alpha);
button.setEnabled(enabled);
}
}

View file

@ -182,7 +182,7 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont
ty = (tileY + py) * mult;
if (tileBounds.contains(tx, ty, tx, ty)) {
if (settings.USE_MAPILLARY_FILTER.get()) {
if (skipPoint(p)) continue;
if (filtered(p.getUserData())) continue;
}
x = tileBox.getPixXFromTile(tileX + px, tileY + py, TILE_ZOOM);
y = tileBox.getPixYFromTile(tileX + px, tileY + py, TILE_ZOOM);
@ -193,9 +193,12 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont
}
}
private boolean skipPoint(Point p) {
private boolean filtered(Object data) {
if (data == null) {
return true;
}
String userKey = settings.MAPILLARY_FILTER_USER_KEY.get();
HashMap<String, Object> userData = (HashMap<String, Object>) p.getUserData();
HashMap<String, Object> userData = (HashMap<String, Object>) data;
long capturedAt = (long) userData.get("captured_at");
long from = settings.MAPILLARY_FILTER_FROM_DATE.get();
long to = settings.MAPILLARY_FILTER_TO_DATE.get();
@ -221,18 +224,22 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont
if (g instanceof LineString && !g.isEmpty()) {
LineString l = (LineString) g;
if (l.getCoordinateSequence() != null && !l.isEmpty()) {
draw(l.getCoordinateSequence().toCoordinateArray(), canvas, tileBox, tileX, tileY);
if (!filtered(l.getUserData())) {
draw(l.getCoordinateSequence().toCoordinateArray(), canvas, tileBox, tileX, tileY);
}
}
} else if (g instanceof MultiLineString && !g.isEmpty()) {
MultiLineString ml = (MultiLineString) g;
for (int i = 0; i < ml.getNumGeometries(); i++) {
Geometry gm = ml.getGeometryN(i);
if (gm instanceof LineString && !gm.isEmpty()) {
LineString l = (LineString) gm;
if (l.getCoordinateSequence() != null && !l.isEmpty()) {
draw(l.getCoordinateSequence().toCoordinateArray(), canvas, tileBox, tileX, tileY);
}
}
if (!filtered(ml.getUserData())) {
for (int i = 0; i < ml.getNumGeometries(); i++) {
Geometry gm = ml.getGeometryN(i);
if (gm instanceof LineString && !gm.isEmpty()) {
LineString l = (LineString) gm;
if (l.getCoordinateSequence() != null && !l.isEmpty()) {
draw(l.getCoordinateSequence().toCoordinateArray(), canvas, tileBox, tileX, tileY);
}
}
}
}
}
}