|
@@ -27,6 +27,8 @@ package com.owncloud.android.ui.adapter;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.LinkedHashSet;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Vector;
|
|
import java.util.Vector;
|
|
|
|
|
|
@@ -35,7 +37,7 @@ import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Color;
|
|
import android.graphics.Color;
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
-import android.os.Bundle;
|
|
|
|
|
|
+import android.text.format.DateUtils;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
@@ -61,9 +63,6 @@ import com.owncloud.android.utils.DisplayUtils;
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
import com.owncloud.android.utils.MimetypeIconUtil;
|
|
import com.owncloud.android.utils.MimetypeIconUtil;
|
|
|
|
|
|
-import java.util.Vector;
|
|
|
|
-import java.util.HashSet;
|
|
|
|
-import java.util.LinkedHashSet;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -72,8 +71,6 @@ import java.util.LinkedHashSet;
|
|
*/
|
|
*/
|
|
public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
- private static final String SELECTION_KEY = "multiFileSelectionsKey";
|
|
|
|
-
|
|
|
|
private Context mContext;
|
|
private Context mContext;
|
|
private OCFile mFile = null;
|
|
private OCFile mFile = null;
|
|
private Vector<OCFile> mFiles = null;
|
|
private Vector<OCFile> mFiles = null;
|
|
@@ -90,17 +87,17 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
private HashSet<Long> mSelection = new LinkedHashSet<Long>();
|
|
private HashSet<Long> mSelection = new LinkedHashSet<Long>();
|
|
|
|
|
|
public FileListListAdapter(
|
|
public FileListListAdapter(
|
|
- boolean justFolders,
|
|
|
|
|
|
+ boolean justFolders,
|
|
Context context,
|
|
Context context,
|
|
ComponentsGetter transferServiceGetter
|
|
ComponentsGetter transferServiceGetter
|
|
) {
|
|
) {
|
|
-
|
|
|
|
|
|
+
|
|
mJustFolders = justFolders;
|
|
mJustFolders = justFolders;
|
|
mContext = context;
|
|
mContext = context;
|
|
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
|
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
|
|
|
|
|
mTransferServiceGetter = transferServiceGetter;
|
|
mTransferServiceGetter = transferServiceGetter;
|
|
-
|
|
|
|
|
|
+
|
|
// Read sorting order, default to sort by name ascending
|
|
// Read sorting order, default to sort by name ascending
|
|
FileStorageUtils.mSortOrder = PreferenceManager.getSortOrder(mContext);
|
|
FileStorageUtils.mSortOrder = PreferenceManager.getSortOrder(mContext);
|
|
FileStorageUtils.mSortAscending = PreferenceManager.getSortAscending(mContext);
|
|
FileStorageUtils.mSortAscending = PreferenceManager.getSortAscending(mContext);
|
|
@@ -110,7 +107,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
mGridMode = false;
|
|
mGridMode = false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean areAllItemsEnabled() {
|
|
public boolean areAllItemsEnabled() {
|
|
return true;
|
|
return true;
|
|
@@ -310,13 +307,17 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
AbsListView parentList = (AbsListView)parent;
|
|
AbsListView parentList = (AbsListView)parent;
|
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
+ view.setBackgroundColor(Color.WHITE);
|
|
if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) {
|
|
if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) {
|
|
checkBoxV.setVisibility(View.GONE);
|
|
checkBoxV.setVisibility(View.GONE);
|
|
} else if (parentList.getCheckedItemCount() > 0){
|
|
} else if (parentList.getCheckedItemCount() > 0){
|
|
if (parentList.isItemChecked(position)) {
|
|
if (parentList.isItemChecked(position)) {
|
|
|
|
+ view.setBackgroundColor(mContext.getResources().getColor(
|
|
|
|
+ R.color.selected_item_background));
|
|
checkBoxV.setImageResource(
|
|
checkBoxV.setImageResource(
|
|
R.drawable.ic_checkbox_marked);
|
|
R.drawable.ic_checkbox_marked);
|
|
} else {
|
|
} else {
|
|
|
|
+ view.setBackgroundColor(Color.WHITE);
|
|
checkBoxV.setImageResource(
|
|
checkBoxV.setImageResource(
|
|
R.drawable.ic_checkbox_blank_outline);
|
|
R.drawable.ic_checkbox_blank_outline);
|
|
}
|
|
}
|
|
@@ -325,7 +326,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
}
|
|
}
|
|
|
|
|
|
// For all Views
|
|
// For all Views
|
|
-
|
|
|
|
|
|
+
|
|
// this if-else is needed even though favorite icon is visible by default
|
|
// this if-else is needed even though favorite icon is visible by default
|
|
// because android reuses views in listview
|
|
// because android reuses views in listview
|
|
if (!file.isFavorite()) {
|
|
if (!file.isFavorite()) {
|
|
@@ -333,7 +334,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
} else {
|
|
} else {
|
|
view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE);
|
|
view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// No Folder
|
|
// No Folder
|
|
if (!file.isFolder()) {
|
|
if (!file.isFolder()) {
|
|
if (file.isImage() && file.getRemoteId() != null){
|
|
if (file.isImage() && file.getRemoteId() != null){
|
|
@@ -355,9 +356,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
}
|
|
}
|
|
final ThumbnailsCacheManager.AsyncDrawable asyncDrawable =
|
|
final ThumbnailsCacheManager.AsyncDrawable asyncDrawable =
|
|
new ThumbnailsCacheManager.AsyncDrawable(
|
|
new ThumbnailsCacheManager.AsyncDrawable(
|
|
- mContext.getResources(),
|
|
|
|
- thumbnail,
|
|
|
|
- task
|
|
|
|
|
|
+ mContext.getResources(),
|
|
|
|
+ thumbnail,
|
|
|
|
+ task
|
|
);
|
|
);
|
|
fileIcon.setImageDrawable(asyncDrawable);
|
|
fileIcon.setImageDrawable(asyncDrawable);
|
|
task.execute(file);
|
|
task.execute(file);
|
|
@@ -386,13 +387,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (mSelection.contains(getItemId(position))) {
|
|
|
|
- view.setBackgroundColor(mContext.getResources().getColor(R.color.selected_item_background));
|
|
|
|
- } else {
|
|
|
|
- view.setBackgroundColor(Color.WHITE);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
return view;
|
|
return view;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -413,9 +407,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Change the adapted directory for a new one
|
|
* Change the adapted directory for a new one
|
|
- * @param directory New file to adapt. Can be NULL, meaning
|
|
|
|
|
|
+ * @param directory New file to adapt. Can be NULL, meaning
|
|
* "no content to adapt".
|
|
* "no content to adapt".
|
|
- * @param updatedStorageManager Optional updated storage manager; used to replace
|
|
|
|
|
|
+ * @param updatedStorageManager Optional updated storage manager; used to replace
|
|
* mStorageManager if is different (and not NULL)
|
|
* mStorageManager if is different (and not NULL)
|
|
*/
|
|
*/
|
|
public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager
|
|
public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager
|
|
@@ -430,7 +424,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
mFiles = mStorageManager.getFolderContent(mFile/*, onlyOnDevice*/);
|
|
mFiles = mStorageManager.getFolderContent(mFile/*, onlyOnDevice*/);
|
|
mFilesOrig.clear();
|
|
mFilesOrig.clear();
|
|
mFilesOrig.addAll(mFiles);
|
|
mFilesOrig.addAll(mFiles);
|
|
-
|
|
|
|
|
|
+
|
|
if (mJustFolders) {
|
|
if (mJustFolders) {
|
|
mFiles = getFolders(mFiles);
|
|
mFiles = getFolders(mFiles);
|
|
}
|
|
}
|
|
@@ -441,7 +435,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
mFiles = FileStorageUtils.sortFolder(mFiles);
|
|
mFiles = FileStorageUtils.sortFolder(mFiles);
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Filter for getting only the folders
|
|
* Filter for getting only the folders
|
|
@@ -449,9 +442,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
* @return Vector<OCFile>
|
|
* @return Vector<OCFile>
|
|
*/
|
|
*/
|
|
public Vector<OCFile> getFolders(Vector<OCFile> files) {
|
|
public Vector<OCFile> getFolders(Vector<OCFile> files) {
|
|
- Vector<OCFile> ret = new Vector<OCFile>();
|
|
|
|
- OCFile current = null;
|
|
|
|
- for (int i=0; i<files.size(); i++) {
|
|
|
|
|
|
+ Vector<OCFile> ret = new Vector<OCFile>();
|
|
|
|
+ OCFile current = null;
|
|
|
|
+ for (int i = 0; i < files.size(); i++) {
|
|
current = files.get(i);
|
|
current = files.get(i);
|
|
if (current.isFolder()) {
|
|
if (current.isFolder()) {
|
|
ret.add(current);
|
|
ret.add(current);
|
|
@@ -459,9 +452,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
}
|
|
}
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
public void setSortOrder(Integer order, boolean ascending) {
|
|
public void setSortOrder(Integer order, boolean ascending) {
|
|
|
|
+
|
|
PreferenceManager.setSortOrder(order, mContext);
|
|
PreferenceManager.setSortOrder(order, mContext);
|
|
PreferenceManager.setSortAscending(ascending, mContext);
|
|
PreferenceManager.setSortAscending(ascending, mContext);
|
|
|
|
|
|
@@ -472,61 +466,14 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
|
|
- public void setGridMode(boolean gridMode) {
|
|
|
|
- mGridMode = gridMode;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // TODO Tobi: all methods needed?
|
|
|
|
- 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 removeSelection(){
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ private CharSequence showRelativeTimestamp(OCFile file) {
|
|
|
|
+ return DisplayUtils.getRelativeDateTimeString(mContext, file.getModificationTimestamp(),
|
|
|
|
+ DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);
|
|
}
|
|
}
|
|
|
|
|
|
- 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 void setGridMode(boolean gridMode) {
|
|
|
|
+ mGridMode = gridMode;
|
|
}
|
|
}
|
|
|
|
|
|
public boolean isGridMode() {
|
|
public boolean isGridMode() {
|