- private void addDownloadingFile(OCFile file, Account account) {
- OwnCloudFileObserver observer = null;
- for (OwnCloudFileObserver o : mObservers) {
- if (o.getRemotePath().equals(file.getRemotePath()) && o.getAccount().equals(account)) {
- observer = o;
- break;
- }
- }
- if (observer == null) {
- Log.e(TAG, "Couldn't find observer for remote file " + file.getRemotePath());
- return;
- }
- observer.stopWatching();
- DownloadCompletedReceiver dcr = new DownloadCompletedReceiver(observer.getPath(), observer);
- registerReceiver(dcr, new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE));
- }
-
-
- private static void addReceiverToList(DownloadCompletedReceiver r) {
- synchronized(mReceiverListLock) {
- mDownloadReceivers.add(r);
- }
- }
-
- private static void removeReceiverFromList(DownloadCompletedReceiver r) {
- synchronized(mReceiverListLock) {
- mDownloadReceivers.remove(r);
- }
- }
-
- @Override
- public void OnObservedFileStatusUpdate(String localPath, String remotePath, Account account, Status status) {
- switch (status) {
- case CONFLICT:
- {
- // ISSUE 5: if the user is not running the app (this is a service!), this can be very intrusive; a notification should be preferred
- Intent i = new Intent(getApplicationContext(), ConflictsResolveActivity.class);
- i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
- i.putExtra("remotepath", remotePath);
- i.putExtra("localpath", localPath);
- i.putExtra("account", account);
- startActivity(i);
- break;
- }
- case SENDING_TO_UPLOADER:
- case INCORRECT_MASK:
- break;
- default:
- Log.wtf(TAG, "Unhandled status " + status);
- }
- }
-
- private class DownloadCompletedReceiver extends BroadcastReceiver {
- String mPath;
- OwnCloudFileObserver mObserver;
-
- public DownloadCompletedReceiver(String path, OwnCloudFileObserver observer) {
- mPath = path;
- mObserver = observer;
- addReceiverToList(this);
- }