Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag relation members #2596

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions documentation/docs/help/en/Property editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ This tab will only be displayed if you are editing a relation, it displays entri

Members with a dark object field and only a numeric id displayed have not been downloaded, member highlighted in blue can be clicked on and a new property editor will be opened for the element. Note: during such a drill down operation the property editors are stacked, if you close a stacked property editor you will be returned to the previous one and so on.

Individual member entries can be moved by _drag and drop_ (long press followed by dragging).

The following operation can be performed on selected relation members.

* _Delete_ - remove the object from this (the edited) relation.
Expand Down
27 changes: 26 additions & 1 deletion src/androidTest/java/de/blau/android/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,31 @@ public static void scrollToStartsWith(@NonNull String text, boolean fail) {
}
}

/**
* Scroll to a specific text
*
* @param text the text
* @param fail fail if scrollable not found
*/
public static void scrollToStartsWith(@NonNull UiDevice device, @NonNull String text, int maxSwipes, boolean fail) {
BySelector bySelector = By.textStartsWith(text);
UiScrollable appView = new UiScrollable(new UiSelector().scrollable(true));
appView.setSwipeDeadZonePercentage(0.4);
try {
for (int swipes = 0; swipes < maxSwipes; maxSwipes++) {
appView.scrollForward(10);
if (device.wait(Until.findObject(bySelector), 500) != null) {
return;
}
}
} catch (UiObjectNotFoundException e) {
Assert.fail("UiScrollable not found");
}
if (fail) {
Assert.fail(text + " not found");
}
}

/**
* Scroll to end
*
Expand Down Expand Up @@ -1561,7 +1586,7 @@ public static void clickSimpleButton(@NonNull UiDevice device, long wait) {
waitForSimpleButton(device, wait);
TestUtils.clickButton(device, device.getCurrentPackageName() + ":id/simpleButton", true);
}

/**
* Wait for the "simple" button
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import android.os.RemoteException;
import android.view.KeyEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
Expand Down Expand Up @@ -1093,13 +1096,19 @@ public void relationMemberMove() {
int oldPos = members.get(0).getPosition();

main.performTagEdit(r, null, false, false);
waitForPropertyEditor();
PropertyEditorActivity propertyEditor = waitForPropertyEditor();
PropertyEditorFragment fragment = getPropertyEditorFragment(propertyEditor);

assertNotNull(fragment);
assertTrue(fragment.isPagingEnabled());

TestUtils.clickText(device, true, main.getString(R.string.tag_details), false, false);
TestUtils.clickText(device, true, main.getString(R.string.members), false, false);

selectMember("Vorbühl");

assertFalse(fragment.isPagingEnabled());

clickButtonOrOverflowMenu(main.getString(R.string.tag_menu_move_up));
clickButtonOrOverflowMenu(main.getString(R.string.tag_menu_move_up));
clickButtonOrOverflowMenu(main.getString(R.string.tag_menu_move_down));
Expand All @@ -1114,6 +1123,23 @@ public void relationMemberMove() {
assertEquals(oldPos - 1, members.get(0).getPosition());
}

/**
* Get the PropertyEditorFragment
*
* @param propertyEditor
* @return a propertyeditorfragment or null
*/
@Nullable
private PropertyEditorFragment getPropertyEditorFragment(@NonNull PropertyEditorActivity propertyEditor) {
FragmentManager fm = propertyEditor.getSupportFragmentManager();
for (Fragment f : fm.getFragments()) {
if (f instanceof PropertyEditorFragment) {
return (PropertyEditorFragment) f;
}
}
return null;
}

/**
* Select a relation move member to bottom then down one
*/
Expand Down Expand Up @@ -1275,7 +1301,8 @@ public void relationMembersSort() {
TestUtils.clickText(device, true, main.getString(R.string.tag_details), false, false);
TestUtils.clickText(device, true, main.getString(R.string.members), false, false);
String name1 = m1.getElement().getTagWithKey(Tags.KEY_NAME);
TestUtils.scrollToStartsWith(name1, true);
TestUtils.scrollToStartsWith(device, name1, r.getMemberCount(), true);

selectMember(name1);
clickButtonOrOverflowMenu(main.getString(R.string.tag_menu_move_up));
// exit property editor
Expand All @@ -1298,7 +1325,7 @@ public void relationMembersSort() {
TestUtils.clickText(device, true, main.getString(R.string.members), false, false);

String name2 = m2.getElement().getTagWithKey(Tags.KEY_NAME);
TestUtils.scrollToStartsWith(name2, true);
TestUtils.scrollToStartsWith(device, name2, r.getMemberCount(), true);
selectMember(name1);
selectMember("#119104097");
selectMember(name2);
Expand Down
1 change: 1 addition & 0 deletions src/main/assets/help/en/Property editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ <h3><img src="../images/menu_help.png" alt="Help" /> Help</h3>
<h2>Members Tab</h2>
<p>This tab will only be displayed if you are editing a relation, it displays entries for all the members of the relation.</p>
<p>Members with a dark object field and only a numeric id displayed have not been downloaded, member highlighted in blue can be clicked on and a new property editor will be opened for the element. Note: during such a drill down operation the property editors are stacked, if you close a stacked property editor you will be returned to the previous one and so on.</p>
<p>Individual member entries can be moved by <em>drag and drop</em> (long press followed by dragging).</p>
<p>The following operation can be performed on selected relation members.</p>
<ul>
<li><em>Delete</em> - remove the object from this (the edited) relation.</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,30 +1173,27 @@ public void onPresetSelected(PresetItem item, boolean applyOptional, boolean isA
}
}

/**
* Allow ViewPager to work
*/
@Override
public void enablePaging() {
mViewPager.setPagingEnabled(true);
}

/**
* Disallow ViewPAger to work
*/
@Override
public void disablePaging() {
mViewPager.setPagingEnabled(false);
}

/**
* Allow presets to be applied
*/
@Override
public boolean isPagingEnabled() {
return mViewPager.isPagingEnabled();
}

@Override
public void enablePresets() {
enablePresets(true);
}

/**
* Disallow presets to be applied
*/
@Override
public void disablePresets() {
enablePresets(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public interface PropertyEditorListener {
*/
@Nullable
public List<Map<String, String>> getUpdatedTags();

/**
* Get original tags
*
Expand Down Expand Up @@ -105,6 +105,13 @@ public interface PropertyEditorListener {
*/
public void disablePaging();

/**
* Check if paging is enabled
*
* @return true if paging is enabled
*/
public boolean isPagingEnabled();

/**
* Allow presets to be applied
*/
Expand All @@ -114,7 +121,7 @@ public interface PropertyEditorListener {
* Disallow presets to be applied
*/
public void disablePresets();

/**
* Get the current API-Servers Capabilities object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void afterTextChanged(Editable s) {
holder.row.elementView.setOnClickListener(null);
}
}

@Override
public int getItemViewType(int position) {
return entries.get(position).downloaded() ? R.layout.relation_member_downloaded_row : R.layout.relation_member_row;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class RelationMemberSelectedActionModeCallback extends SelectedRowsAction
private static final int TAG_LEN = Math.min(LOG_TAG_LEN, RelationMemberSelectedActionModeCallback.class.getSimpleName().length());
private static final String DEBUG_TAG = RelationMemberSelectedActionModeCallback.class.getSimpleName().substring(0, TAG_LEN);

// pm: protected static final int MENU_ITEM_DELETE = 1;
// pm: private static final int MENU_ITEM_COPY = 2;
// pm: private static final int MENU_ITEM_CUT = 3;
// pm: protected static final int MENU_ITEM_HELP = 15;
// pm: protected static final int MENU_ITEM_DELETE = 1; NOSONAR
// pm: private static final int MENU_ITEM_COPY = 2; NOSONAR
// pm: private static final int MENU_ITEM_CUT = 3; NOSONAR
// pm: protected static final int MENU_ITEM_HELP = 15; NOSONAR
private static final int MENU_ITEM_MOVE_UP = 4;
private static final int MENU_ITEM_MOVE_DOWN = 5;
private static final int MENU_ITEM_SORT = 6;
Expand Down Expand Up @@ -296,7 +296,7 @@ private void update() {
for (int i = 0; i < members.size(); i++) {
members.get(i).setPosition(i);
}
((RelationMembersFragment) caller).setIcons();
((RelationMembersFragment) caller).setConnections();
adapter.notifyDataSetChanged();
}

Expand Down
Loading
Loading