Skip to content

Commit

Permalink
Merge branch 'regression_details_tab_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Jan 17, 2024
2 parents ccde841 + 133876f commit cf209c9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,62 @@ public void multiSelectClearValue() {
assertFalse(n2.hasTagKey(Tags.KEY_ACCESS));
}

/**
* Clear value in details editor
*/
@Test
public void clearValue() {
final CountDownLatch signal = new CountDownLatch(1);
mockServer.enqueue("capabilities1");
mockServer.enqueue("download1");
Logic logic = App.getLogic();
logic.downloadBox(main, new BoundingBox(8.3879800D, 47.3892400D, 8.3844600D, 47.3911300D), false, new SignalHandler(signal));
try {
signal.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail(e.getMessage());
}
main.getMap().getDataLayer().setVisible(true);
TestUtils.unlock(device);
TestUtils.zoomToLevel(device, main, 21);

Node n1 = (Node) App.getDelegator().getOsmElement(Node.NAME, 3465444349L);
assertNotNull(n1);

final CountDownLatch signal2 = new CountDownLatch(1);
main.runOnUiThread(() -> {
logic.addSelectedNode(n1);
main.getEasyEditManager().editElements();
(new SignalHandler(signal2)).onSuccess();
});
try {
signal2.await(20, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail(e.getMessage());
}
assertTrue(TestUtils.findText(device, false, context.getString(R.string.actionmode_nodeselect)));

assertTrue(TestUtils.clickMenuButton(device, main.getString(R.string.menu_tags), false, true));
PropertyEditorActivity propertyEditor = waitForPropertyEditor();

switchToDetailsTab();

UiObject2 access = null;
try {
access = getField(device, Tags.KEY_ACCESS, 2);
} catch (UiObjectNotFoundException e) {
fail();
}
assertNotNull(access);
access.setText("");

TestUtils.clickHome(device, true);
assertTrue(TestUtils.findText(device, false, context.getString(R.string.actionmode_nodeselect)));
device.waitForIdle();

assertFalse(n1.hasTagKey(Tags.KEY_ACCESS));
}

/**
* Get the value field for a specific key
*
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/de/blau/android/propertyeditor/TagEditorFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ public void afterTextChanged(Editable s) {
textWatcher.afterTextChanged(s);
Log.d(DEBUG_TAG, "afterTextChanged >" + s + "<");
row.valueEdit.removeTextChangedListener(this);
setMultiselectValue(rowLayout, row, s.toString());
setValue(rowLayout, row, s.toString());
row.valueEdit.addTextChangedListener(this);
}
};
Expand Down Expand Up @@ -1310,26 +1310,26 @@ public void afterTextChanged(Editable s) {
}

/**
* If the there are multiple values set them all to the same and recreate the autocomplete adapter
* Set the valueand recreate the autocomplete adapter
*
* If the there are multiple values set them all to the same
*
* @param rowLayout the layout holding the rows
* @param row the row
* @param newValue the new value
*/
private void setMultiselectValue(@NonNull final LinearLayout rowLayout, @NonNull final TagEditRow row, @NonNull String newValue) {
private void setValue(@NonNull final LinearLayout rowLayout, @NonNull final TagEditRow row, @NonNull String newValue) {
final int length = osmIds.length;
if (length > 1) { // multi-select, all values should be set to the same
List<String> newValues = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
newValues.add(newValue);
}
final String key = row.getKey();
row.setValues(key, newValues, true);
row.post(() -> {
row.valueEdit.dismissDropDown();
row.valueEdit.setAdapter(getValueAutocompleteAdapter(getPreset(key), rowLayout, row));
});
}
List<String> newValues = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
newValues.add(newValue);
}
final String key = row.getKey();
row.setValues(key, newValues, true);
row.post(() -> {
row.valueEdit.dismissDropDown();
row.valueEdit.setAdapter(getValueAutocompleteAdapter(getPreset(key), rowLayout, row));
});
}

/**
Expand Down

0 comments on commit cf209c9

Please sign in to comment.