mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 02:17:43 +03:00
Merge pull request #810 from owncloud/download_folder__better_downloading_icon_for_folders
Show the download-in-progress icon in the folder as soon as the Synchron...
This commit is contained in:
commit
a4277dcd37
3 changed files with 52 additions and 8 deletions
|
@ -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<Target, RemoteOperation> 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<Account, String> itemSyncKey = (Pair<Account, String>) msg.obj;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue