X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/d05d5ffe1a5b7a4f470afa541515a0b9c7eb9f59..d8ac7b2241bc99df58b5f4be4c3c4d83fc9efaf6:/src/com/owncloud/android/files/services/FileDownloader.java diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index db806913..741e30a8 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -96,9 +96,6 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis private NotificationCompat.Builder mNotificationBuilder; private int mLastPercent; - private Account mAccount; - private OCFile mFile; - public static String getDownloadAddedMessage() { return FileDownloader.class.getName().toString() + DOWNLOAD_ADDED_MESSAGE; @@ -150,28 +147,34 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis Log_OC.e(TAG, "Not enough information provided in intent"); return START_NOT_STICKY; } else { - mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT); - mFile = intent.getParcelableExtra(EXTRA_FILE); + final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT); + final OCFile file = intent.getParcelableExtra(EXTRA_FILE); if (ACTION_CANCEL_FILE_DOWNLOAD.equals(intent.getAction())) { new Thread(new Runnable() { public void run() { // Cancel the download - cancel(mAccount,mFile); + cancel(account, file); } }).start(); } else { AbstractList requestedDownloads = new Vector(); // dvelasco: now this always contains just one element, but that can change in a near future (download of multiple selection) - String downloadKey = buildRemoteName(mAccount, mFile); + String downloadKey = buildRemoteName(account, file); try { - DownloadFileOperation newDownload = new DownloadFileOperation(mAccount, mFile); + DownloadFileOperation newDownload = new DownloadFileOperation(account, file); mPendingDownloads.putIfAbsent(downloadKey, newDownload); newDownload.addDatatransferProgressListener(this); newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder); requestedDownloads.add(downloadKey); + + // Store file on db with state 'downloading' + FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver()); + file.setDownloading(true); + storageManager.saveFile(file); + sendBroadcastNewDownload(newDownload); } catch (IllegalArgumentException e) { @@ -256,6 +259,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis * @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) { if (account == null || file == null) return false; String targetKey = buildRemoteName(account, file); @@ -273,6 +277,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } } } + */ /** @@ -418,6 +423,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis file.setStoragePath(mCurrentDownload.getSavePath()); file.setFileLength((new File(mCurrentDownload.getSavePath()).length())); file.setRemoteId(mCurrentDownload.getFile().getRemoteId()); + file.setDownloading(false); mStorageManager.saveFile(file); mStorageManager.triggerMediaScan(file.getStoragePath()); }