|
@@ -1,25 +1,24 @@
|
|
/**
|
|
/**
|
|
- * ownCloud Android client application
|
|
|
|
- *
|
|
|
|
- * @author Bartek Przybylski
|
|
|
|
- * @author Tobias Kaminsky
|
|
|
|
- * @author David A. Velasco
|
|
|
|
- * @author masensio
|
|
|
|
- * Copyright (C) 2011 Bartek Przybylski
|
|
|
|
- * Copyright (C) 2016 ownCloud Inc.
|
|
|
|
- *
|
|
|
|
- * This program is free software: you can redistribute it and/or modify
|
|
|
|
- * it under the terms of the GNU General Public License version 2,
|
|
|
|
- * as published by the Free Software Foundation.
|
|
|
|
- *
|
|
|
|
- * This program is distributed in the hope that it will be useful,
|
|
|
|
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
- * GNU General Public License for more details.
|
|
|
|
- *
|
|
|
|
- * You should have received a copy of the GNU General Public License
|
|
|
|
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
+ * ownCloud Android client application
|
|
*
|
|
*
|
|
|
|
+ * @author Bartek Przybylski
|
|
|
|
+ * @author Tobias Kaminsky
|
|
|
|
+ * @author David A. Velasco
|
|
|
|
+ * @author masensio
|
|
|
|
+ * Copyright (C) 2011 Bartek Przybylski
|
|
|
|
+ * Copyright (C) 2016 ownCloud Inc.
|
|
|
|
+ * <p>
|
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
|
+ * it under the terms of the GNU General Public License version 2,
|
|
|
|
+ * as published by the Free Software Foundation.
|
|
|
|
+ * <p>
|
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ * GNU General Public License for more details.
|
|
|
|
+ * <p>
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
*/
|
|
package com.owncloud.android.ui.adapter;
|
|
package com.owncloud.android.ui.adapter;
|
|
|
|
|
|
@@ -43,6 +42,7 @@ import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
import android.widget.AbsListView;
|
|
import android.widget.AbsListView;
|
|
import android.widget.BaseAdapter;
|
|
import android.widget.BaseAdapter;
|
|
|
|
+import android.widget.GridView;
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.ListAdapter;
|
|
import android.widget.ListAdapter;
|
|
@@ -86,8 +86,11 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
private Account mAccount;
|
|
private Account mAccount;
|
|
private ComponentsGetter mTransferServiceGetter;
|
|
private ComponentsGetter mTransferServiceGetter;
|
|
private boolean mGridMode;
|
|
private boolean mGridMode;
|
|
|
|
+ private boolean isGridViewSelectionRestored = true;
|
|
|
|
|
|
- private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM };
|
|
|
|
|
|
+ private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM}
|
|
|
|
+
|
|
|
|
+ ;
|
|
|
|
|
|
private HashSet<Long> mSelection = new LinkedHashSet<Long>();
|
|
private HashSet<Long> mSelection = new LinkedHashSet<Long>();
|
|
|
|
|
|
@@ -95,7 +98,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
boolean justFolders,
|
|
boolean justFolders,
|
|
Context context,
|
|
Context context,
|
|
ComponentsGetter transferServiceGetter
|
|
ComponentsGetter transferServiceGetter
|
|
- ) {
|
|
|
|
|
|
+ ) {
|
|
|
|
|
|
mJustFolders = justFolders;
|
|
mJustFolders = justFolders;
|
|
mContext = context;
|
|
mContext = context;
|
|
@@ -149,6 +152,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
+ restoreGridViewSelection((AbsListView) parent);
|
|
|
|
|
|
View view = convertView;
|
|
View view = convertView;
|
|
OCFile file = null;
|
|
OCFile file = null;
|
|
@@ -161,9 +165,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
// Find out which layout should be displayed
|
|
// Find out which layout should be displayed
|
|
ViewType viewType;
|
|
ViewType viewType;
|
|
- if (!mGridMode){
|
|
|
|
|
|
+ if (!mGridMode) {
|
|
viewType = ViewType.LIST_ITEM;
|
|
viewType = ViewType.LIST_ITEM;
|
|
- } else if (file.isImage()){
|
|
|
|
|
|
+ } else if (file.isImage()) {
|
|
viewType = ViewType.GRID_IMAGE;
|
|
viewType = ViewType.GRID_IMAGE;
|
|
} else {
|
|
} else {
|
|
viewType = ViewType.GRID_ITEM;
|
|
viewType = ViewType.GRID_ITEM;
|
|
@@ -189,7 +193,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
view.invalidate();
|
|
view.invalidate();
|
|
|
|
|
|
- if (file != null){
|
|
|
|
|
|
+ if (file != null) {
|
|
|
|
|
|
ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
|
|
ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
|
|
|
|
|
|
@@ -200,7 +204,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.ListItemLayout);
|
|
LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.ListItemLayout);
|
|
linearLayout.setContentDescription("LinearLayout-" + name);
|
|
linearLayout.setContentDescription("LinearLayout-" + name);
|
|
|
|
|
|
- switch (viewType){
|
|
|
|
|
|
+ switch (viewType) {
|
|
case LIST_ITEM:
|
|
case LIST_ITEM:
|
|
TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
|
|
TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
|
|
TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);
|
|
TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);
|
|
@@ -211,7 +215,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
|
|
lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
fileSizeSeparatorV.setVisibility(View.VISIBLE);
|
|
fileSizeSeparatorV.setVisibility(View.VISIBLE);
|
|
fileSizeV.setVisibility(View.VISIBLE);
|
|
fileSizeV.setVisibility(View.VISIBLE);
|
|
fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
|
|
fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
|
|
@@ -251,7 +254,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
sharedIconV.setImageResource(R.drawable.shared_via_link);
|
|
sharedIconV.setImageResource(R.drawable.shared_via_link);
|
|
sharedIconV.setVisibility(View.VISIBLE);
|
|
sharedIconV.setVisibility(View.VISIBLE);
|
|
sharedIconV.bringToFront();
|
|
sharedIconV.bringToFront();
|
|
- } else if (file.isSharedWithSharee() || file.isSharedWithMe() ) {
|
|
|
|
|
|
+ } else if (file.isSharedWithSharee() || file.isSharedWithMe()) {
|
|
sharedIconV.setImageResource(R.drawable.shared_via_users);
|
|
sharedIconV.setImageResource(R.drawable.shared_via_users);
|
|
sharedIconV.setVisibility(View.VISIBLE);
|
|
sharedIconV.setVisibility(View.VISIBLE);
|
|
sharedIconV.bringToFront();
|
|
sharedIconV.bringToFront();
|
|
@@ -275,22 +278,22 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
localStateView.setVisibility(View.INVISIBLE); // default first
|
|
localStateView.setVisibility(View.INVISIBLE); // default first
|
|
|
|
|
|
if ( //synchronizing
|
|
if ( //synchronizing
|
|
- opsBinder != null &&
|
|
|
|
- opsBinder.isSynchronizing(mAccount, file)
|
|
|
|
|
|
+ opsBinder != null &&
|
|
|
|
+ opsBinder.isSynchronizing(mAccount, file)
|
|
) {
|
|
) {
|
|
localStateView.setImageResource(R.drawable.ic_synchronizing);
|
|
localStateView.setImageResource(R.drawable.ic_synchronizing);
|
|
localStateView.setVisibility(View.VISIBLE);
|
|
localStateView.setVisibility(View.VISIBLE);
|
|
|
|
|
|
} else if ( // downloading
|
|
} else if ( // downloading
|
|
- downloaderBinder != null &&
|
|
|
|
- downloaderBinder.isDownloading(mAccount, file)
|
|
|
|
|
|
+ downloaderBinder != null &&
|
|
|
|
+ downloaderBinder.isDownloading(mAccount, file)
|
|
) {
|
|
) {
|
|
localStateView.setImageResource(R.drawable.ic_synchronizing);
|
|
localStateView.setImageResource(R.drawable.ic_synchronizing);
|
|
localStateView.setVisibility(View.VISIBLE);
|
|
localStateView.setVisibility(View.VISIBLE);
|
|
|
|
|
|
} else if ( //uploading
|
|
} else if ( //uploading
|
|
- uploaderBinder != null &&
|
|
|
|
- uploaderBinder.isUploading(mAccount, file)
|
|
|
|
|
|
+ uploaderBinder != null &&
|
|
|
|
+ uploaderBinder.isUploading(mAccount, file)
|
|
) {
|
|
) {
|
|
localStateView.setImageResource(R.drawable.ic_synchronizing);
|
|
localStateView.setImageResource(R.drawable.ic_synchronizing);
|
|
localStateView.setVisibility(View.VISIBLE);
|
|
localStateView.setVisibility(View.VISIBLE);
|
|
@@ -311,9 +314,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
checkBoxV.setVisibility(View.GONE);
|
|
checkBoxV.setVisibility(View.GONE);
|
|
view.setBackgroundColor(Color.WHITE);
|
|
view.setBackgroundColor(Color.WHITE);
|
|
|
|
|
|
- AbsListView parentList = (AbsListView)parent;
|
|
|
|
|
|
+ AbsListView parentList = (AbsListView) parent;
|
|
if (parentList.getChoiceMode() != AbsListView.CHOICE_MODE_NONE
|
|
if (parentList.getChoiceMode() != AbsListView.CHOICE_MODE_NONE
|
|
- && parentList.getCheckedItemCount() > 0){
|
|
|
|
|
|
+ && parentList.getCheckedItemCount() > 0) {
|
|
if (isItemSelected(position)) {
|
|
if (isItemSelected(position)) {
|
|
view.setBackgroundColor(mContext.getResources().getColor(
|
|
view.setBackgroundColor(mContext.getResources().getColor(
|
|
R.color.selected_item_background));
|
|
R.color.selected_item_background));
|
|
@@ -326,7 +329,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
}
|
|
}
|
|
checkBoxV.setVisibility(View.VISIBLE);
|
|
checkBoxV.setVisibility(View.VISIBLE);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// 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
|
|
@@ -339,12 +342,12 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
// No Folder
|
|
// No Folder
|
|
if (!file.isFolder()) {
|
|
if (!file.isFolder()) {
|
|
- if (file.isImage() && file.getRemoteId() != null){
|
|
|
|
|
|
+ if (file.isImage() && file.getRemoteId() != null) {
|
|
// Thumbnail in Cache?
|
|
// Thumbnail in Cache?
|
|
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
|
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
|
String.valueOf(file.getRemoteId())
|
|
String.valueOf(file.getRemoteId())
|
|
- );
|
|
|
|
- if (thumbnail != null && !file.needsUpdateThumbnail()){
|
|
|
|
|
|
+ );
|
|
|
|
+ if (thumbnail != null && !file.needsUpdateThumbnail()) {
|
|
fileIcon.setImageBitmap(thumbnail);
|
|
fileIcon.setImageBitmap(thumbnail);
|
|
} else {
|
|
} else {
|
|
// generate new Thumbnail
|
|
// generate new Thumbnail
|
|
@@ -352,7 +355,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
|
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
|
new ThumbnailsCacheManager.ThumbnailGenerationTask(
|
|
new ThumbnailsCacheManager.ThumbnailGenerationTask(
|
|
fileIcon, mStorageManager, mAccount
|
|
fileIcon, mStorageManager, mAccount
|
|
- );
|
|
|
|
|
|
+ );
|
|
if (thumbnail == null) {
|
|
if (thumbnail == null) {
|
|
thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
|
thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
|
}
|
|
}
|
|
@@ -392,6 +395,19 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
return view;
|
|
return view;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void restoreGridViewSelection(AbsListView parent) {
|
|
|
|
+ if (parent instanceof GridView && !isGridViewSelectionRestored) {
|
|
|
|
+ isGridViewSelectionRestored = true;
|
|
|
|
+ parent.clearChoices();
|
|
|
|
+ final Vector<OCFile> files = mFiles;
|
|
|
|
+ for (int i = 0; i < files.size(); ++i) {
|
|
|
|
+ if(mSelection.contains(files.get(i).getFileId())){
|
|
|
|
+ parent.setItemChecked(i, true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public int getViewTypeCount() {
|
|
public int getViewTypeCount() {
|
|
return 1;
|
|
return 1;
|
|
@@ -409,10 +425,11 @@ 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
|
|
|
|
- * "no content to adapt".
|
|
|
|
- * @param updatedStorageManager Optional updated storage manager; used to replace
|
|
|
|
- * mStorageManager if is different (and not NULL)
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param directory New file to adapt. Can be NULL, meaning
|
|
|
|
+ * "no content to adapt".
|
|
|
|
+ * @param updatedStorageManager Optional updated storage manager; used to replace
|
|
|
|
+ * mStorageManager if is different (and not NULL)
|
|
*/
|
|
*/
|
|
public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager
|
|
public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager
|
|
/*, boolean onlyOnDevice*/) {
|
|
/*, boolean onlyOnDevice*/) {
|
|
@@ -440,6 +457,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Filter for getting only the folders
|
|
* Filter for getting only the folders
|
|
|
|
+ *
|
|
* @param files
|
|
* @param files
|
|
* @return Vector<OCFile>
|
|
* @return Vector<OCFile>
|
|
*/
|
|
*/
|
|
@@ -478,12 +496,12 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
mGridMode = gridMode;
|
|
mGridMode = gridMode;
|
|
}
|
|
}
|
|
|
|
|
|
- public boolean isItemSelected(int position){
|
|
|
|
|
|
+ public boolean isItemSelected(int position) {
|
|
return mSelection.contains(getItemId(position));
|
|
return mSelection.contains(getItemId(position));
|
|
}
|
|
}
|
|
|
|
|
|
public void setNewSelection(int position, boolean checked) {
|
|
public void setNewSelection(int position, boolean checked) {
|
|
- if(checked){
|
|
|
|
|
|
+ if (checked) {
|
|
mSelection.add(getItemId(position));
|
|
mSelection.add(getItemId(position));
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
} else {
|
|
} else {
|
|
@@ -496,33 +514,35 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
|
|
- public void clearSelection(){
|
|
|
|
- mSelection.clear();
|
|
|
|
|
|
+ public void clearSelection() {
|
|
|
|
+ mSelection.clear();
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
|
|
public ArrayList<OCFile> getCheckedItems() {
|
|
public ArrayList<OCFile> getCheckedItems() {
|
|
ArrayList<OCFile> files = new ArrayList<OCFile>();
|
|
ArrayList<OCFile> files = new ArrayList<OCFile>();
|
|
- if (mFiles != null && mFiles.size() != 0){
|
|
|
|
- for(OCFile file: mFiles){
|
|
|
|
- if(mSelection.contains(file.getFileId())){
|
|
|
|
|
|
+ if (mFiles != null && mFiles.size() != 0) {
|
|
|
|
+ for (OCFile file : mFiles) {
|
|
|
|
+ if (mSelection.contains(file.getFileId())) {
|
|
files.add(file);
|
|
files.add(file);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return files;
|
|
return files;
|
|
}
|
|
}
|
|
- public void restoreSelectionState(Bundle savedInstanceState){
|
|
|
|
|
|
+
|
|
|
|
+ public void restoreSelectionState(Bundle savedInstanceState) {
|
|
if (savedInstanceState == null) {
|
|
if (savedInstanceState == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
long[] selectionState = savedInstanceState.getLongArray(SELECTION_KEY);
|
|
long[] selectionState = savedInstanceState.getLongArray(SELECTION_KEY);
|
|
mSelection.clear();
|
|
mSelection.clear();
|
|
- if(selectionState != null) {
|
|
|
|
|
|
+ if (selectionState != null) {
|
|
for (long id : selectionState) {
|
|
for (long id : selectionState) {
|
|
mSelection.add(id);
|
|
mSelection.add(id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ isGridViewSelectionRestored = false;
|
|
}
|
|
}
|
|
|
|
|
|
public void saveSelectionState(Bundle outState) {
|
|
public void saveSelectionState(Bundle outState) {
|