From 0a4ac6e91c31cf3c73aefa9c574a043969528159 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Fri, 8 Jul 2016 10:27:41 +0200 Subject: [PATCH] Update selection in FileListListAdapter using ID received from list instead of position, so that changes removals or additions in the list result in correct update of the drawn selection --- .../android/ui/adapter/FileListListAdapter.java | 11 +++-------- .../android/ui/fragment/OCFileListFragment.java | 9 ++++----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 8e884a3bc5..3a84eb5a80 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -476,17 +476,12 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { return mSelection.contains(getItemId(position)); } - public void updateSelection(int position, boolean checked) { + public void updateSelection(long itemId, boolean checked) { if (checked) { - mSelection.add(getItemId(position)); - notifyDataSetChanged(); + mSelection.add(itemId); } else { - removeSelection(position); + mSelection.remove(itemId); } - } - - public void removeSelection(int position) { - mSelection.remove(getItemId(position)); notifyDataSetChanged(); } diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 5efebfbf16..36e7024ed6 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -349,7 +349,7 @@ public class OCFileListFragment extends ExtendedListFragment { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { - mAdapter.updateSelection(position, checked); + mAdapter.updateSelection(id, checked); mode.invalidate(); } @@ -376,18 +376,17 @@ public class OCFileListFragment extends ExtendedListFragment { @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - final int checkedCount = getListView().getCheckedItemCount(); + List checkedFiles = mAdapter.getCheckedItems(); + final int checkedCount = checkedFiles.size(); String title = getResources().getQuantityString( R.plurals.items_selected_count, checkedCount, checkedCount ); mode.setTitle(title); - if (checkedCount > 0) { - List targetFiles = mAdapter.getCheckedItems(); FileMenuFilter mf = new FileMenuFilter( - targetFiles, + checkedFiles, ((FileActivity) getActivity()).getAccount(), mContainerActivity, getActivity()