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

Do not remain in actionmode #94

Closed
readbeard opened this issue Mar 24, 2016 · 4 comments
Closed

Do not remain in actionmode #94

readbeard opened this issue Mar 24, 2016 · 4 comments
Assignees
Labels

Comments

@readbeard
Copy link

Hi,
thanks for this great library!
I was wondering why the multichoice mode is not implemented as the one in gmail app. It think it would be better if the actionmode is closed as soon as an action is selected (for example, as soon as an item is deleted). Is it possible to do that?
Thanks in advance.

@mikepenz
Copy link
Owner

@readbeard you can have any behavior you want. If you select an action, just finish the ActionMode you do not have to depend on the default implementation here. It is just a simple class to simplify things for most cases ;)

@mikepenz mikepenz self-assigned this Mar 24, 2016
mikepenz added a commit that referenced this issue Mar 24, 2016
… those are updated later if the actionMode is finished

 * improve behavior mentioned in #94
@mikepenz
Copy link
Owner

will be improved in the next version

@readbeard
Copy link
Author

Here is my solution to the improvement. Let me know if you like it and if it is a correct behaviour for you.
You just need to edit the UndoHelper.java file, in particoular this 2 methods (lines with //<--- comment are the interesting ones):

public Snackbar remove(View view, String text, String actionText, @Snackbar.Duration int duration, Set<Integer> positions,  ActionMode actionMode) { //<---
. . . 
private void doChange(ActionMode actionMode) {
        if (mHistory != null) {
            if (mHistory.action == ACTION_REMOVE) {
                Integer[] positions = new Integer[mHistory.positions.size()];
                mHistory.positions.toArray(positions);
                for (int i = positions.length - 1; i >= 0; i--) {
                    FastAdapter.RelativeInfo<Item> relativeInfo = mHistory.items.get(i);
                    if (relativeInfo.adapter instanceof IItemAdapter) {
                        ((IItemAdapter) relativeInfo.adapter).remove(positions[i]);
                    }
                }
            }
        }
        actionMode.finish(); // <---
    }

    private void undoChange() {
        if (mHistory != null) {
            if (mHistory.action == ACTION_REMOVE) {
                int count = 0;
                for (Integer position : mHistory.positions) {
                    FastAdapter.RelativeInfo<Item> relativeInfo = mHistory.items.get(count);
                    if (relativeInfo.adapter instanceof IItemAdapter) {
                        IItemAdapter<Item> adapter = (IItemAdapter<Item>) relativeInfo.adapter;
                        adapter.add(position, relativeInfo.item);
                        if (relativeInfo.item.isSelected()) {
                            mAdapter.deselect(position); //<---
                        }
                    }
                    count++;
                }
            }
        }
        mHistory = null;
    }

@mikepenz
Copy link
Owner

@readbeard that was the case before. That's why I had to do the following change:
d999c65#diff-31afcdcd4f3dcf443fc7b3c2cfaded2cR50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants