Merge remote-tracking branch 'upstream/develop' into triggerMediaScan
[pub/Android/ownCloud.git] / src / com / owncloud / android / datamodel / FileDataStorageManager.java
index b10e525..abaafa5 100644 (file)
@@ -33,7 +33,6 @@ import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.lib.resources.files.FileUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 
-
 import android.accounts.Account;
 import android.content.ContentProviderClient;
 import android.content.ContentProviderOperation;
@@ -41,6 +40,7 @@ import android.content.ContentProviderResult;
 import android.content.ContentResolver;
 import android.content.ContentUris;
 import android.content.ContentValues;
+import android.content.Intent;
 import android.content.OperationApplicationException;
 import android.database.Cursor;
 import android.net.Uri;
@@ -346,7 +346,13 @@ public class FileDataStorageManager {
                     ).withSelection(where, whereArgs).build());
                     
                     if (file.isDown()) {
+                        String path = file.getStoragePath();
                         new File(file.getStoragePath()).delete();
+                        
+                        // Notify MediaScanner about removed file
+                        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+                        intent.setData(Uri.fromFile(new File(path)));
+                        MainApp.getAppContext().sendBroadcast(intent);
                     }
                 }
             }
@@ -542,11 +548,17 @@ public class FileDataStorageManager {
                         success &= removeLocalFolder(file);
                     } else {
                         if (file.isDown()) {
+                            String path = file.getStoragePath();
                             File localFile = new File(file.getStoragePath());
                             success &= localFile.delete();
                             if (success) {
                                 file.setStoragePath(null);
                                 saveFile(file);
+                                
+                             // Notify MediaScanner about removed file
+                                Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+                                intent.setData(Uri.fromFile(new File(path)));
+                                MainApp.getAppContext().sendBroadcast(intent);
                             }
                         }
                     }
@@ -568,7 +580,13 @@ public class FileDataStorageManager {
                 if (localFile.isDirectory()) {
                     success &= removeLocalFolder(localFile);
                 } else {
+                    String path = localFile.getAbsolutePath();
                     success &= localFile.delete();
+                    
+                    // Notify MediaScanner about removed file
+                    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+                    intent.setData(Uri.fromFile(new File(path)));
+                    MainApp.getAppContext().sendBroadcast(intent);
                 }
             }
         }
@@ -787,6 +805,18 @@ public class FileDataStorageManager {
             }
             Log_OC.d(TAG, "Local file RENAMED : " + renamed);
             
+            // Notify MediaScanner about removed file
+            Intent intent1 = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+            intent1.setData(Uri.fromFile(new File(file.getStoragePath())));
+            MainApp.getAppContext().sendBroadcast(intent1);
+            
+            // Notify MediaScanner about new file/folder
+            Intent intent2 = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+            intent2.setData(Uri.fromFile(new File(defaultSavePath + targetPath)));
+            MainApp.getAppContext().sendBroadcast(intent2);
+            
+            Log_OC.d(TAG, "uri old: " + file.getStoragePath());
+            Log_OC.d(TAG, "uri new: " + defaultSavePath + targetPath);
         }
         
     }