projects
/
pub
/
Android
/
ownCloud.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Store file on db with 'downloading' state after adding it to pending downloads
[pub/Android/ownCloud.git]
/
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
12ec465
..
5998277
100644
(file)
--- a/
src/com/owncloud/android/files/services/FileDownloader.java
+++ b/
src/com/owncloud/android/files/services/FileDownloader.java
@@
-95,7
+95,7
@@
public class FileDownloader extends Service implements OnDatatransferProgressLis
private NotificationManager mNotificationManager;
private NotificationCompat.Builder mNotificationBuilder;
private int mLastPercent;
private NotificationManager mNotificationManager;
private NotificationCompat.Builder mNotificationBuilder;
private int mLastPercent;
-
+
public static String getDownloadAddedMessage() {
return FileDownloader.class.getName().toString() + DOWNLOAD_ADDED_MESSAGE;
public static String getDownloadAddedMessage() {
return FileDownloader.class.getName().toString() + DOWNLOAD_ADDED_MESSAGE;
@@
-147,13
+147,17
@@
public class FileDownloader extends Service implements OnDatatransferProgressLis
Log_OC.e(TAG, "Not enough information provided in intent");
return START_NOT_STICKY;
} else {
Log_OC.e(TAG, "Not enough information provided in intent");
return START_NOT_STICKY;
} else {
- Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
- OCFile file = 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())) {
if (ACTION_CANCEL_FILE_DOWNLOAD.equals(intent.getAction())) {
- // Cancel the download
- cancel(account,file);
+ new Thread(new Runnable() {
+ public void run() {
+ // Cancel the download
+ cancel(account, file);
+ }
+ }).start();
} else {
} else {
@@
-165,6
+169,12
@@
public class FileDownloader extends Service implements OnDatatransferProgressLis
newDownload.addDatatransferProgressListener(this);
newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
requestedDownloads.add(downloadKey);
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) {
sendBroadcastNewDownload(newDownload);
} catch (IllegalArgumentException e) {
@@
-411,6
+421,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.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());
}
mStorageManager.saveFile(file);
mStorageManager.triggerMediaScan(file.getStoragePath());
}
@@
-573,12
+584,6
@@
public class FileDownloader extends Service implements OnDatatransferProgressLis
* @param file File OCFile
*/
public void cancel(Account account, OCFile file){
* @param file File OCFile
*/
public void cancel(Account account, OCFile file){
- if(Looper.myLooper() == Looper.getMainLooper()) {
- Log_OC.d(TAG, "Current Thread is Main Thread.");
- } else {
- Log_OC.d(TAG, "Current Thread is NOT Main Thread.");
- }
-
DownloadFileOperation download = null;
String targetKey = buildRemoteName(account, file);
ArrayList<String> keyItems = new ArrayList<String>();
DownloadFileOperation download = null;
String targetKey = buildRemoteName(account, file);
ArrayList<String> keyItems = new ArrayList<String>();
@@
-595,6
+600,7
@@
public class FileDownloader extends Service implements OnDatatransferProgressLis
}
}
} else {
}
}
} else {
+ // this is not really expected...
Log_OC.d(TAG, "Canceling file download");
keyItems.add(buildRemoteName(account, file));
}
Log_OC.d(TAG, "Canceling file download");
keyItems.add(buildRemoteName(account, file));
}