\r
\r
/**\r
- * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download\r
+ * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download.\r
+ * \r
+ * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting to download. \r
* \r
* @param account Owncloud account where the remote file is stored.\r
* @param file A file that could be in the queue of downloads.\r
*/\r
public boolean isDownloading(Account account, OCFile file) {\r
+ String targetKey = buildRemoteName(account, file);\r
synchronized (mPendingDownloads) {\r
- return (mPendingDownloads.containsKey(buildRemoteName(account, file)));\r
+ if (file.isDirectory()) {\r
+ // this can be slow if there are many downloads :(\r
+ Iterator<String> it = mPendingDownloads.keySet().iterator();\r
+ boolean found = false;\r
+ while (it.hasNext() && !found) {\r
+ found = it.next().startsWith(targetKey);\r
+ }\r
+ return found;\r
+ } else {\r
+ return (mPendingDownloads.containsKey(targetKey));\r
+ }\r
}\r
}\r
}\r
public class FileUploader extends Service implements OnDatatransferProgressListener {
public static final String UPLOAD_FINISH_MESSAGE = "UPLOAD_FINISH";
- public static final String EXTRA_PARENT_DIR_ID = "PARENT_DIR_ID";
public static final String EXTRA_UPLOAD_RESULT = "RESULT";
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_FILE_PATH = "FILE_PATH";
/**
* Returns True when the file described by 'file' is being uploaded to the ownCloud account 'account' or waiting for it
*
+ * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting to download.
+ *
* @param account Owncloud account where the remote file will be stored.
* @param file A file that could be in the queue of pending uploads
*/
public boolean isUploading(Account account, OCFile file) {
+ String targetKey = buildRemoteName(account, file);
synchronized (mPendingUploads) {
- return (mPendingUploads.containsKey(buildRemoteName(account, file)));
+ if (file.isDirectory()) {
+ // this can be slow if there are many downloads :(
+ Iterator<String> it = mPendingUploads.keySet().iterator();
+ boolean found = false;
+ while (it.hasNext() && !found) {
+ found = it.next().startsWith(targetKey);
+ }
+ return found;
+ } else {
+ return (mPendingUploads.containsKey(targetKey));
+ }
}
}
}
end.putExtra(EXTRA_FILE_PATH, upload.getStoragePath());
end.putExtra(ACCOUNT_NAME, upload.getAccount().name);
end.putExtra(EXTRA_UPLOAD_RESULT, uploadResult.isSuccess());
- end.putExtra(EXTRA_PARENT_DIR_ID, upload.getFile().getParentId());
sendBroadcast(end);
}
*/\r
@Override\r
public void onReceive(Context context, Intent intent) {\r
- long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1);\r
- OCFile parentDir = mStorageManager.getFileById(parentDirId);\r
+ String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);\r
-\r
- if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&\r
- parentDir != null && \r
- ( (mCurrentDir == null && parentDir.getFileName().equals("/")) ||\r
- parentDir.equals(mCurrentDir)\r
- )\r
- ) {\r
+ boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);\r
+ boolean isDescendant = (mCurrentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(mCurrentDir.getRemotePath()));\r
+ if (sameAccount && isDescendant) {\r
OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
if (fileListFragment != null) { \r
fileListFragment.listDirectory();\r
public void onReceive(Context context, Intent intent) {\r
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);\r
- OCFile downloadedFile = mStorageManager.getFileByPath(downloadedRemotePath); // if null, the file is not in the current account, OR WAS DELETED before the download finished \r
- \r
- if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&\r
- mCurrentDir != null && downloadedFile != null &&\r
- mCurrentDir.getFileId() == downloadedFile.getParentId()) {\r
+ boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);\r
+ boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath()));\r
+ if (sameAccount && isDescendant) {\r
OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
if (fileListFragment != null) { \r
fileListFragment.listDirectory();\r
fileIcon.setImageResource(R.drawable.ic_menu_archive);\r
}\r
ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);\r
- //if (FileDownloader.isDownloading(mAccount, file.getRemotePath())) {\r
FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();\r
FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();\r
if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {\r
package com.owncloud.android.ui.fragment;
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
import com.owncloud.android.AccountUtils;
import com.owncloud.android.R;
inflater.inflate(R.menu.file_context_menu, menu);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
OCFile targetFile = (OCFile) mAdapter.getItem(info.position);
- MenuItem item = null;
- int[] ids = null;
+ List<Integer> toHide = new ArrayList<Integer>();
+ List<Integer> toDisable = new ArrayList<Integer>();
+
if (targetFile.isDirectory()) {
- int[] theIds = {R.id.open_file_item, R.id.download_file_item, R.id.cancel_download_item, R.id.cancel_upload_item};
- ids = theIds;
-
- } else if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
- int[] theIds = {R.id.open_file_item, R.id.download_file_item, R.id.cancel_upload_item};
- ids = theIds;
-
- } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
- int[] theIds = {R.id.open_file_item, R.id.download_file_item, R.id.cancel_download_item};
- ids = theIds;
-
- } else if ( targetFile.isDown()) {
- int[] theIds = {R.id.cancel_download_item, R.id.cancel_upload_item};
- ids = theIds;
+ // contextual menu for folders
+ toHide.add(R.id.open_file_item);
+ toHide.add(R.id.download_file_item);
+ toHide.add(R.id.cancel_download_item);
+ toHide.add(R.id.cancel_upload_item);
+ if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) ||
+ mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) ) {
+ toDisable.add(R.id.rename_file_item);
+ toDisable.add(R.id.remove_file_item);
+
+ }
} else {
- int[] theIds = {R.id.open_file_item, R.id.cancel_download_item, R.id.cancel_upload_item};
- ids = theIds;
+ // contextual menu for regular files
+ if (targetFile.isDown()) {
+ toHide.add(R.id.cancel_download_item);
+ toHide.add(R.id.cancel_upload_item);
+ } else {
+ toHide.add(R.id.open_file_item);
+ }
+ if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
+ toHide.add(R.id.download_file_item);
+ toHide.add(R.id.cancel_upload_item);
+ toDisable.add(R.id.open_file_item);
+ toDisable.add(R.id.rename_file_item);
+ toDisable.add(R.id.remove_file_item);
+
+ } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
+ toHide.add(R.id.download_file_item);
+ toHide.add(R.id.cancel_download_item);
+ toDisable.add(R.id.open_file_item);
+ toDisable.add(R.id.rename_file_item);
+ toDisable.add(R.id.remove_file_item);
+
+ } else {
+ toHide.add(R.id.cancel_download_item);
+ toHide.add(R.id.cancel_upload_item);
+ }
}
-
- for (int i=0; i < ids.length; i++) {
- item = menu.findItem(ids[i]);
+
+ MenuItem item = null;
+ for (int i : toHide) {
+ item = menu.findItem(i);
if (item != null) {
item.setVisible(false);
item.setEnabled(false);
}
}
+
+ for (int i : toDisable) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setEnabled(false);
+ }
+ }
}