From: David A. Velasco Date: Thu, 22 Nov 2012 12:06:54 +0000 (+0100) Subject: Disable rename and remove actions on folders when some file is uploading or downloadi... X-Git-Tag: oc-android-1.4.3~88^2~3 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/658267ad79996516624236f2328289c6760ccd42 Disable rename and remove actions on folders when some file is uploading or downloading inside --- diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 1ac3a0a4..0f2d6742 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -202,14 +202,27 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis /** - * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download + * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download. + * + * 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 is stored. * @param file A file that could be in the queue of downloads. */ public boolean isDownloading(Account account, OCFile file) { + String targetKey = buildRemoteName(account, file); synchronized (mPendingDownloads) { - return (mPendingDownloads.containsKey(buildRemoteName(account, file))); + if (file.isDirectory()) { + // this can be slow if there are many downloads :( + Iterator it = mPendingDownloads.keySet().iterator(); + boolean found = false; + while (it.hasNext() && !found) { + found = it.next().startsWith(targetKey); + } + return found; + } else { + return (mPendingDownloads.containsKey(targetKey)); + } } } } diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index aef15db2..7956a99b 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -64,7 +64,6 @@ import eu.alefzero.webdav.WebdavClient; 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"; @@ -281,12 +280,25 @@ public class FileUploader extends Service implements OnDatatransferProgressListe /** * 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 it = mPendingUploads.keySet().iterator(); + boolean found = false; + while (it.hasNext() && !found) { + found = it.next().startsWith(targetKey); + } + return found; + } else { + return (mPendingUploads.containsKey(targetKey)); + } } } } @@ -572,7 +584,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe 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); } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 49370e5d..e6771e0e 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -874,16 +874,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements */ @Override public void onReceive(Context context, Intent intent) { - long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1); - OCFile parentDir = mStorageManager.getFileById(parentDirId); + String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); - - if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && - parentDir != null && - ( (mCurrentDir == null && parentDir.getFileName().equals("/")) || - parentDir.equals(mCurrentDir) - ) - ) { + boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name); + boolean isDescendant = (mCurrentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(mCurrentDir.getRemotePath())); + if (sameAccount && isDescendant) { OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); if (fileListFragment != null) { fileListFragment.listDirectory(); @@ -902,11 +897,9 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public void onReceive(Context context, Intent intent) { String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); - OCFile downloadedFile = mStorageManager.getFileByPath(downloadedRemotePath); // if null, the file is not in the current account, OR WAS DELETED before the download finished - - if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && - mCurrentDir != null && downloadedFile != null && - mCurrentDir.getFileId() == downloadedFile.getParentId()) { + boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name); + boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath())); + if (sameAccount && isDescendant) { OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); if (fileListFragment != null) { fileListFragment.listDirectory(); diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 87172898..503dfffe 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -121,7 +121,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { fileIcon.setImageResource(R.drawable.ic_menu_archive); } ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2); - //if (FileDownloader.isDownloading(mAccount, file.getRemotePath())) { FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder(); if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) { diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 72d530c7..a96f4001 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -18,6 +18,8 @@ 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; @@ -161,36 +163,65 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial 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 toHide = new ArrayList(); + List toDisable = new ArrayList(); + 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); + } + } }