summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/documentsui/dirlist/DirectoryFragment.java9
-rw-r--r--tests/common/com/android/documentsui/bots/DirectoryListBot.java7
-rw-r--r--tests/functional/com/android/documentsui/FileUndoDeletionUiTest.java17
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"));
+ }
}