From: David A. Velasco Date: Tue, 16 Dec 2014 09:42:55 +0000 (+0100) Subject: Show the download-in-progress icon in the folder as soon as the SynchronizeFolderOper... X-Git-Tag: oc-android-1.7.0_signed~23^2~25^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/727a941b3cd0d8401b0c87aa14b9d8ef9551426e?ds=inline;hp=--cc Show the download-in-progress icon in the folder as soon as the SynchronizeFolderOperation is created --- 727a941b3cd0d8401b0c87aa14b9d8ef9551426e diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index eef9362d..6e70a8c9 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentMap; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; -import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; @@ -51,6 +51,7 @@ import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.UnshareLinkOperation; +import com.owncloud.android.utils.FileStorageUtils; import android.accounts.Account; import android.accounts.AccountsException; @@ -179,6 +180,7 @@ public class OperationsService extends Service { Pair itemToQueue = newOperation(intent); if (itemToQueue != null) { mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation)itemToQueue.second); + sendBroadcastNewSyncFolder(account, remotePath); Message msg = mSyncFolderHandler.obtainMessage(); msg.arg1 = startId; msg.obj = itemSyncKey; @@ -203,6 +205,19 @@ public class OperationsService extends Service { return START_NOT_STICKY; } + /** + * TODO remove this method when "folder synchronization" replaces "folder download"; this is a fast and ugly + * patch. + */ + private void sendBroadcastNewSyncFolder(Account account, String remotePath) { + Intent added = new Intent(FileDownloader.getDownloadAddedMessage()); + added.putExtra(FileDownloader.ACCOUNT_NAME, account.name); + added.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath); + added.putExtra(FileDownloader.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) + remotePath); + sendStickyBroadcast(added); + } + + @Override public void onDestroy() { //Log_OC.wtf(TAG, "onDestroy init" ); @@ -359,6 +374,19 @@ public class OperationsService extends Service { //Log_OC.wtf(TAG, "Not finished yet"); } } + + + /** + * 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 affected + */ + public boolean isSynchronizing(Account account, String remotePath) { + return mSyncFolderHandler.isSynchronizing(account, remotePath); + } } @@ -389,6 +417,16 @@ public class OperationsService extends Service { mService = service; } + + public boolean isSynchronizing(Account account, String remotePath) { + if (account == null || remotePath == null) return false; + String targetKey = buildRemoteName(account, remotePath); + synchronized (mPendingOperations) { + return (mPendingOperations.containsKey(targetKey)); + } + } + + @Override public void handleMessage(Message msg) { Pair itemSyncKey = (Pair) msg.obj; diff --git a/src/com/owncloud/android/ui/activity/ComponentsGetter.java b/src/com/owncloud/android/ui/activity/ComponentsGetter.java index 076a6cba..2916ac3d 100644 --- a/src/com/owncloud/android/ui/activity/ComponentsGetter.java +++ b/src/com/owncloud/android/ui/activity/ComponentsGetter.java @@ -22,28 +22,31 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.files.FileOperationsHelper; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; +import com.owncloud.android.services.OperationsService.OperationsServiceBinder; public interface ComponentsGetter { /** - * Callback method invoked when the parent activity is fully created to get a reference to the FileDownloader service API. - * - * @return Directory to list firstly. Can be NULL. + * To be invoked when the parent activity is fully created to get a reference to the FileDownloader service API. */ public FileDownloaderBinder getFileDownloaderBinder(); /** - * Callback method invoked when the parent activity is fully created to get a reference to the FileUploader service API. - * - * @return Directory to list firstly. Can be NULL. + * To be invoked when the parent activity is fully created to get a reference to the FileUploader service API. */ public FileUploaderBinder getFileUploaderBinder(); + /** + * To be invoked when the parent activity is fully created to get a reference to the OperationsSerivce service API. + */ + public OperationsServiceBinder getOperationsServiceBinder(); + public FileDataStorageManager getStorageManager(); public FileOperationsHelper getFileOperationsHelper(); + } diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 1df1211c..c89ef3bf 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -47,6 +47,7 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; +import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; @@ -163,7 +164,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder(); - if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) { + OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder(); + if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || + (opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath()))) { localStateView.setImageResource(R.drawable.downloading_file_indicator); localStateView.setVisibility(View.VISIBLE); } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {