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

Swipe delete, UnsupportedOperationException #523

Closed
ni-ku opened this issue Jan 24, 2018 · 1 comment
Closed

Swipe delete, UnsupportedOperationException #523

ni-ku opened this issue Jan 24, 2018 · 1 comment
Milestone

Comments

@ni-ku
Copy link

ni-ku commented Jan 24, 2018

Im running the example App and on the "Headers and Sections" Screen,
if i delete a single item by a swipe to the right, an UnsupportedOperationException is raised.

FATAL EXCEPTION: main
Process: eu.davidea.samples.flexibleadapter, PID: 13125
java.lang.UnsupportedOperationException
at java.util.AbstractList.set(AbstractList.java:132)
at java.util.AbstractList$ListItr.set(AbstractList.java:426)
at java.util.Collections.sort(Collections.java:247)
at eu.davidea.flexibleadapter.FlexibleAdapter.removeItems(FlexibleAdapter.java:3324)
at eu.davidea.flexibleadapter.helpers.UndoHelper.performAction(UndoHelper.java:211)
at eu.davidea.flexibleadapter.helpers.UndoHelper.start(UndoHelper.java:198)
at eu.davidea.samples.flexibleadapter.MainActivity.onItemSwipe(MainActivity.java:791)
at eu.davidea.flexibleadapter.FlexibleAdapter.onItemSwiped(FlexibleAdapter.java:4672)
at eu.davidea.flexibleadapter.helpers.ItemTouchHelperCallback.onSwiped(ItemTouchHelperCallback.java:249)

Checking the size of the items positions list seems to fix the issue.
`

    if (selectedPositions.size() >= 2) {
        // Reverse-sort the list, start from last position for efficiency
        Collections.sort(selectedPositions, new Comparator<Integer>() {
            @Override
            public int compare(Integer lhs, Integer rhs) {
                return rhs - lhs;
            }
        });
        log.v("removeItems after reverse sort selectedPositions=%s", selectedPositions);
    }`
@davideas davideas added this to the 5.0.0 milestone Jan 24, 2018
@davideas
Copy link
Owner

davideas commented Jan 24, 2018

Thanks @ni-ku, it is caused because of the singletonList, created in MainActivity, is an immutable list. However, I will put also that check. The issue remains if the list is immutable with more than 1 item, but then the exception is correct.
This will be a small improvement and not a bug.

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

No branches or pull requests

2 participants