소스 검색

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

David A. Velasco 9 년 전
부모
커밋
0a4ac6e91c
2개의 변경된 파일7개의 추가작업 그리고 13개의 파일을 삭제
  1. 3 8
      src/com/owncloud/android/ui/adapter/FileListListAdapter.java
  2. 4 5
      src/com/owncloud/android/ui/fragment/OCFileListFragment.java

+ 3 - 8
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();
     }
 

+ 4 - 5
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<OCFile> 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<OCFile> targetFiles = mAdapter.getCheckedItems();
                     FileMenuFilter mf = new FileMenuFilter(
-                        targetFiles,
+                        checkedFiles,
                         ((FileActivity) getActivity()).getAccount(),
                         mContainerActivity,
                         getActivity()