|
@@ -36,6 +36,7 @@ import android.accounts.Account;
|
|
|
import android.content.Context;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.Color;
|
|
|
+import android.os.Bundle;
|
|
|
import android.text.format.DateUtils;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
@@ -61,6 +62,10 @@ import com.owncloud.android.utils.DisplayUtils;
|
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
|
import com.owncloud.android.utils.MimetypeIconUtil;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.Vector;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -69,6 +74,8 @@ import com.owncloud.android.utils.MimetypeIconUtil;
|
|
|
*/
|
|
|
public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
+ private static final String SELECTION_KEY = "multiFileSelectionsKey";
|
|
|
+
|
|
|
private Context mContext;
|
|
|
private OCFile mFile = null;
|
|
|
private Vector<OCFile> mFiles = null;
|
|
@@ -83,7 +90,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM };
|
|
|
|
|
|
private HashSet<Long> mSelection = new LinkedHashSet<Long>();
|
|
|
-
|
|
|
+
|
|
|
public FileListListAdapter(
|
|
|
boolean justFolders,
|
|
|
Context context,
|
|
@@ -307,7 +314,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
AbsListView parentList = (AbsListView)parent;
|
|
|
if (parentList.getChoiceMode() != AbsListView.CHOICE_MODE_NONE
|
|
|
&& parentList.getCheckedItemCount() > 0){
|
|
|
- if (parentList.isItemChecked(position)) {
|
|
|
+ if (isItemSelected(position)) {
|
|
|
view.setBackgroundColor(mContext.getResources().getColor(
|
|
|
R.color.selected_item_background));
|
|
|
checkBoxV.setImageResource(
|
|
@@ -471,6 +478,62 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
mGridMode = gridMode;
|
|
|
}
|
|
|
|
|
|
+ public boolean isItemSelected(int position){
|
|
|
+ return mSelection.contains(getItemId(position));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setNewSelection(int position, boolean checked) {
|
|
|
+ if(checked){
|
|
|
+ mSelection.add(getItemId(position));
|
|
|
+ notifyDataSetChanged();
|
|
|
+ } else {
|
|
|
+ removeSelection(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void removeSelection(int position) {
|
|
|
+ mSelection.remove(getItemId(position));
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void clearSelection(){
|
|
|
+ mSelection.clear();
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<OCFile> getCheckedItems() {
|
|
|
+ ArrayList<OCFile> files = new ArrayList<OCFile>();
|
|
|
+ if (mFiles != null && mFiles.size() != 0){
|
|
|
+ for(OCFile file: mFiles){
|
|
|
+ if(mSelection.contains(file.getFileId())){
|
|
|
+ files.add(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return files;
|
|
|
+ }
|
|
|
+ public void restoreSelectionState(Bundle savedInstanceState){
|
|
|
+ if (savedInstanceState == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ long[] selectionState = savedInstanceState.getLongArray(SELECTION_KEY);
|
|
|
+ mSelection.clear();
|
|
|
+ if(selectionState != null) {
|
|
|
+ for (long id : selectionState) {
|
|
|
+ mSelection.add(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveSelectionState(Bundle outState) {
|
|
|
+ long[] selectionStatePrimitive = new long[mSelection.size()];
|
|
|
+ int i = 0;
|
|
|
+ for (Long id : mSelection) {
|
|
|
+ selectionStatePrimitive[i++] = id;
|
|
|
+ }
|
|
|
+ outState.putLongArray(SELECTION_KEY, selectionStatePrimitive);
|
|
|
+ }
|
|
|
+
|
|
|
public boolean isGridMode() {
|
|
|
return mGridMode;
|
|
|
}
|