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

Commit e8d97268 authored by Jon Mann's avatar Jon Mann Committed by Android (Google) Code Review
Browse files

Merge "Fix state of file context menu when state changes while already...

Merge "Fix state of file context menu when state changes while already selected" into nyc-andromeda-dev
parents 5d54baaa fcbbdb32
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -1229,7 +1229,11 @@ public class DirectoryFragment extends Fragment
                Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SEARCH);
            }

            mAdapter.notifyDataSetChanged();
            // The below mModel.update triggers recalculation of the selection metadata
            if (mSelectionMgr.hasSelection()) {
                mSelectionMetadata.reset();
            }

            mModel.update(result);

            updateLayout(mState.derivedMode);
+15 −0
Original line number Diff line number Diff line
@@ -101,6 +101,8 @@ public final class SelectionManager {
                // Update the selection to remove any disappeared IDs.
                mSelection.cancelProvisionalSelection();
                mSelection.intersect(mModelIds);

                notifyDataChanged();
            }

            @Override
@@ -423,6 +425,19 @@ public final class SelectionManager {
        return mCanSetState.test(id, nextState);
    }

    private void notifyDataChanged() {
        int lastListener = mItemCallbacks.size() - 1;
        for (String id : mSelection) {
            if (!canSetState(id, true)) {
                attemptDeselect(id);
            } else {
                for (int i = lastListener; i >= 0; i--) {
                    mItemCallbacks.get(i).onItemStateChanged(id, true);
                }
            }
        }
    }

    /**
     * Notifies registered listeners when the selection status of a single item
     * (identified by {@code position}) changes.
+9 −0
Original line number Diff line number Diff line
@@ -51,6 +51,15 @@ public class SelectionMetadata
        mDocFinder = docFinder;
    }

    public void reset(){
        mFileCount = 0;
        mDirectoryCount = 0;
        mPartialCount = 0;
        mWritableDirectoryCount = 0;
        mNoDeleteCount = 0;
        mNoRenameCount = 0;
    }

    @Override
    public void onItemStateChanged(String modelId, boolean selected) {
        final Cursor cursor = mDocFinder.apply(modelId);