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

This commit is contained in:
David A. Velasco 2016-07-08 10:27:41 +02:00 committed by Andy Scherzinger
parent db6acc6868
commit 0a4ac6e91c
2 changed files with 7 additions and 13 deletions

View file

@ -476,17 +476,12 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
return mSelection.contains(getItemId(position)); return mSelection.contains(getItemId(position));
} }
public void updateSelection(int position, boolean checked) { public void updateSelection(long itemId, boolean checked) {
if (checked) { if (checked) {
mSelection.add(getItemId(position)); mSelection.add(itemId);
notifyDataSetChanged();
} else { } else {
removeSelection(position); mSelection.remove(itemId);
} }
}
public void removeSelection(int position) {
mSelection.remove(getItemId(position));
notifyDataSetChanged(); notifyDataSetChanged();
} }

View file

@ -349,7 +349,7 @@ public class OCFileListFragment extends ExtendedListFragment {
@Override @Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
mAdapter.updateSelection(position, checked); mAdapter.updateSelection(id, checked);
mode.invalidate(); mode.invalidate();
} }
@ -376,18 +376,17 @@ public class OCFileListFragment extends ExtendedListFragment {
@Override @Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
final int checkedCount = getListView().getCheckedItemCount(); List<OCFile> checkedFiles = mAdapter.getCheckedItems();
final int checkedCount = checkedFiles.size();
String title = getResources().getQuantityString( String title = getResources().getQuantityString(
R.plurals.items_selected_count, R.plurals.items_selected_count,
checkedCount, checkedCount,
checkedCount checkedCount
); );
mode.setTitle(title); mode.setTitle(title);
if (checkedCount > 0) { if (checkedCount > 0) {
List<OCFile> targetFiles = mAdapter.getCheckedItems();
FileMenuFilter mf = new FileMenuFilter( FileMenuFilter mf = new FileMenuFilter(
targetFiles, checkedFiles,
((FileActivity) getActivity()).getAccount(), ((FileActivity) getActivity()).getAccount(),
mContainerActivity, mContainerActivity,
getActivity() getActivity()