diff options
author | 2018-08-29 21:11:07 +0800 | |
---|---|---|
committer | 2018-08-30 14:35:36 +0800 | |
commit | 0cd62cab6cc65c68e9e265c2c5f596976dc13cff (patch) | |
tree | 4c92f4f0decc7981c43f0b232763ac7876834f62 | |
parent | ccd17cc2683375395d7cfe8b4bdd784593be105f (diff) |
Fixed items still in the selection after deleting
Remove any disappear items from selection.
Change-Id: I99a30bbefece139d557ba31e92b3d436638b2ac0
Fixes: 113268142
Test: Manual 1) delete one file, 2) click undo button and observe the selection state
3 files changed, 33 insertions, 0 deletions
diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java index e3b429b09..eacdb8f97 100644 --- a/src/com/android/documentsui/dirlist/DirectoryFragment.java +++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java @@ -103,6 +103,7 @@ import com.android.documentsui.sorting.SortModel; import java.io.IOException; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Iterator; import java.util.List; /** @@ -1044,6 +1045,14 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On updateLayout(mState.derivedMode); + // Update the selection to remove any disappeared IDs. + Iterator<String> selectionIter = mSelectionMgr.getSelection().iterator(); + while (selectionIter.hasNext()) { + if (!mAdapter.getStableIds().contains(selectionIter.next())) { + selectionIter.remove(); + } + } + mAdapter.notifyDataSetChanged(); if (mRestoredState != null) { diff --git a/tests/common/com/android/documentsui/bots/DirectoryListBot.java b/tests/common/com/android/documentsui/bots/DirectoryListBot.java index dd8688360..4b1123235 100644 --- a/tests/common/com/android/documentsui/bots/DirectoryListBot.java +++ b/tests/common/com/android/documentsui/bots/DirectoryListBot.java @@ -191,6 +191,13 @@ public class DirectoryListBot extends Bots.BaseBot { assertSelection(number); } + public boolean isDocumentSelected(String label) throws UiObjectNotFoundException { + waitForDocument(label); + UiObject2 selectionHotspot = findSelectionHotspot(label); + return selectionHotspot.getResourceName() + .equals("com.android.documentsui:id/icon_check"); + } + public UiObject2 findSelectionHotspot(String label) { final BySelector list = By.res(DIR_LIST_ID); diff --git a/tests/functional/com/android/documentsui/FileUndoDeletionUiTest.java b/tests/functional/com/android/documentsui/FileUndoDeletionUiTest.java index 0da36ea55..49b8110dc 100644 --- a/tests/functional/com/android/documentsui/FileUndoDeletionUiTest.java +++ b/tests/functional/com/android/documentsui/FileUndoDeletionUiTest.java @@ -96,4 +96,21 @@ public class FileUndoDeletionUiTest extends ActivityTest<FilesActivity> { assertTrue("deleted files are not restored", bots.directory.hasDocuments(filenames)); } + + public void testSelectionStateAfterDeleteUndo() throws Exception { + bots.roots.openRoot(ROOT_0_ID); + bots.directory.selectDocument("file1.log"); + device.waitForIdle(); + + bots.main.clickToolbarItem(R.id.action_menu_delete); + device.waitForIdle(); + + bots.directory.waitForDeleteSnackbar(); + + bots.directory.clickSnackbarAction(); + device.waitForIdle(); + + assertFalse("the file after deleting/undo is still selected", + bots.directory.isDocumentSelected("file1.log")); + } } |