From: David A. Velasco Date: Tue, 2 Dec 2014 08:08:48 +0000 (+0100) Subject: Refactoring: get MediaScan trigger out of OCFile for renaming X-Git-Tag: oc-android-1.7.0_signed~90^2~8 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/c95eb327f81525e4f597e2555cb90e2f92f69a7c?ds=sidebyside;hp=--cc Refactoring: get MediaScan trigger out of OCFile for renaming --- c95eb327f81525e4f597e2555cb90e2f92f69a7c diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index abaafa5f..1e3e4651 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1579,4 +1579,10 @@ public class FileDataStorageManager { //} } + public void triggerMediaScan(String path) { + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + intent.setData(Uri.fromFile(new File(path))); + MainApp.getAppContext().sendBroadcast(intent); + } + } diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index 70a51547..cf25d278 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -26,11 +26,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; import java.io.File; -import com.owncloud.android.MainApp; - import third_parties.daveKoeller.AlphanumComparator; -import android.content.Intent; -import android.net.Uri; public class OCFile implements Parcelable, Comparable { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @@ -299,17 +295,6 @@ public class OCFile implements Parcelable, Comparable { mRemotePath += PATH_SEPARATOR; } Log_OC.d(TAG, "OCFile name changed to " + mRemotePath); - - // Notify MediaScanner about removed file - Intent intent1 = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - intent1.setData(Uri.fromFile(new File(this.getStoragePath()))); - MainApp.getAppContext().sendBroadcast(intent1); - - // Notify MediaScanner about new file - Intent intent2 = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - String folder = new File(this.getStoragePath()).getParent(); - intent2.setData(Uri.fromFile(new File(folder+ PATH_SEPARATOR+name))); - MainApp.getAppContext().sendBroadcast(intent2); } } diff --git a/src/com/owncloud/android/operations/RenameFileOperation.java b/src/com/owncloud/android/operations/RenameFileOperation.java index 95a5a9ba..178c4d39 100644 --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/src/com/owncloud/android/operations/RenameFileOperation.java @@ -134,12 +134,19 @@ public class RenameFileOperation extends SyncOperation { // try to rename the local copy of the file if (mFile.isDown()) { - File f = new File(mFile.getStoragePath()); + String oldPath = mFile.getStoragePath(); + File f = new File(oldPath); String parentStoragePath = f.getParent(); if (!parentStoragePath.endsWith(File.separator)) parentStoragePath += File.separator; if (f.renameTo(new File(parentStoragePath + mNewName))) { - mFile.setStoragePath(parentStoragePath + mNewName); + String newPath = parentStoragePath + mNewName; + mFile.setStoragePath(newPath); + + // notify MediaScanner about removed file - TODO really works? + getStorageManager().triggerMediaScan(oldPath); + // notify to scan about new file + getStorageManager().triggerMediaScan(newPath); } // else - NOTHING: the link to the local file is kept although the local name can't be updated // TODO - study conditions when this could be a problem