Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0cd62cab authored by shawnlin's avatar shawnlin
Browse files

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
parent ccd17cc2
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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) {
+7 −0
Original line number Diff line number Diff line
@@ -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);

+17 −0
Original line number Diff line number Diff line
@@ -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"));
    }
}