Update unsuccessful downloaded file
[pub/Android/ownCloud.git] / src / com / owncloud / android / files / services / FileDownloader.java
index 5998277..61483af 100644 (file)
@@ -259,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);
@@ -276,6 +277,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
                 }
             }
         }
+        */
 
         
         /**
@@ -381,6 +383,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
                 downloadResult = mCurrentDownload.execute(mDownloadClient);
                 if (downloadResult.isSuccess()) {
                     saveDownloadedFile();
+                } else {
+                    updateUnsuccessfulDownloadedFile();
                 }
             
             } catch (AccountsException e) {
@@ -426,6 +430,15 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         mStorageManager.triggerMediaScan(file.getStoragePath());
     }
 
+    /**
+     * Update the OC File after a unsuccessful download
+     */
+    private void updateUnsuccessfulDownloadedFile() {
+        OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
+        file.setDownloading(false);
+        mStorageManager.saveFile(file);
+    }
+
 
     /**
      * Creates a status notification to show the download progress