From: tobiasKaminsky Date: Sat, 29 Nov 2014 11:18:02 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/develop' into triggerMediaScan X-Git-Tag: oc-android-1.7.0_signed~90^2~9 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/eaa3b1ef566ec3301dc648e6e57b39af7915392f?hp=b2af9efa788b773069df27bd5b82666c135305b0 Merge remote-tracking branch 'upstream/develop' into triggerMediaScan -fr/strings.xml Conflicts: src/com/owncloud/android/datamodel/FileDataStorageManager.java src/com/owncloud/android/datamodel/OCFile.java --- diff --git a/owncloud-android-library b/owncloud-android-library index 7ff0bc0d..5bd0d738 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 7ff0bc0d837edea90b075140f8caba308ce7d378 +Subproject commit 5bd0d7387712ce3f53869294761ac4d8537841cd diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index b10e525c..abaafa5f 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -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); } } diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index 853b01c5..70a51547 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -26,8 +26,11 @@ import com.owncloud.android.lib.common.utils.Log_OC; import java.io.File; -import third_parties.daveKoeller.AlphanumComparator; +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() { @@ -296,6 +299,17 @@ 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/DownloadFileOperation.java b/src/com/owncloud/android/operations/DownloadFileOperation.java index 9f2bed72..d0d249e0 100644 --- a/src/com/owncloud/android/operations/DownloadFileOperation.java +++ b/src/com/owncloud/android/operations/DownloadFileOperation.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import com.owncloud.android.MainApp; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.OwnCloudClient; @@ -34,6 +35,7 @@ import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation; import com.owncloud.android.utils.FileStorageUtils; import android.accounts.Account; +import android.media.MediaScannerConnection; import android.webkit.MimeTypeMap; /** @@ -150,13 +152,16 @@ public class DownloadFileOperation extends RemoteOperation { newFile = new File(getSavePath()); newFile.getParentFile().mkdirs(); moved = tmpFile.renameTo(newFile); + + MediaScannerConnection.scanFile(MainApp.getAppContext(), + new String[]{newFile.getAbsolutePath()}, null, null); + if (!moved) result = new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED); } Log_OC.i(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage()); - return result; } diff --git a/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java b/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java index a78584ae..b8dd78cb 100644 --- a/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java +++ b/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java @@ -24,17 +24,23 @@ package com.owncloud.android.ui.dialog; * * @author David A. Velasco */ +import java.io.File; import java.util.Vector; +import android.app.Dialog; +import android.content.Intent; +import android.media.MediaScannerConnection; +import android.net.Uri; +import android.os.Bundle; + +import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; -import android.app.Dialog; -import android.os.Bundle; - public class RemoveFileDialogFragment extends ConfirmationDialogFragment implements ConfirmationDialogFragmentListener { @@ -95,7 +101,9 @@ implements ConfirmationDialogFragmentListener { ComponentsGetter cg = (ComponentsGetter)getSherlockActivity(); FileDataStorageManager storageManager = cg.getStorageManager(); if (storageManager.getFileById(mTargetFile.getFileId()) != null) { + String path = mTargetFile.getStoragePath(); cg.getFileOperationsHelper().removeFile(mTargetFile, false); + triggerMediaScan(path); } } @@ -104,9 +112,9 @@ implements ConfirmationDialogFragmentListener { */ @Override public void onNeutral(String callerTag) { + String path = mTargetFile.getStoragePath(); ComponentsGetter cg = (ComponentsGetter)getSherlockActivity(); - cg.getFileOperationsHelper() - .removeFile(mTargetFile, true); + cg.getFileOperationsHelper().removeFile(mTargetFile, true); FileDataStorageManager storageManager = cg.getStorageManager(); @@ -134,6 +142,9 @@ implements ConfirmationDialogFragmentListener { folder.setEtag(""); storageManager.saveFile(folder); } + + // Trigger MediaScan + triggerMediaScan(path); } @Override @@ -141,4 +152,18 @@ implements ConfirmationDialogFragmentListener { // nothing to do here } -} + private void triggerMediaScan(String path){ + try { + MediaScannerConnection.scanFile( + getActivity().getApplicationContext(), + new String[]{path}, + null,null); + + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + intent.setData(Uri.fromFile(new File(path))); + MainApp.getAppContext().sendBroadcast(intent); + } catch (Exception e){ + Log_OC.d("Trigger", "exception: " + e); + } + } +} \ No newline at end of file diff --git a/src/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java b/src/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java index 530e920a..d285f1e4 100644 --- a/src/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java +++ b/src/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java @@ -22,12 +22,6 @@ package com.owncloud.android.ui.dialog; * * Triggers the rename operation. */ -import com.actionbarsherlock.app.SherlockDialogFragment; -import com.owncloud.android.R; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.lib.resources.files.FileUtils; -import com.owncloud.android.ui.activity.ComponentsGetter; - import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; @@ -39,6 +33,12 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; +import com.actionbarsherlock.app.SherlockDialogFragment; +import com.owncloud.android.R; +import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.ui.activity.ComponentsGetter; + /** * Dialog to input a new name for a file or folder to rename. @@ -125,12 +125,8 @@ extends SherlockDialogFragment implements DialogInterface.OnClickListener { Toast.LENGTH_LONG).show(); return; } - - ((ComponentsGetter)getSherlockActivity()). - getFileOperationsHelper().renameFile(mTargetFile, newFileName); - - + + ((ComponentsGetter)getSherlockActivity()).getFileOperationsHelper().renameFile(mTargetFile, newFileName); } } - } diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 4dd5c436..a3814c77 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -328,7 +328,7 @@ public class PreviewImageFragment extends FileFragment { finish(); } - + private class BitmapLoader extends AsyncTask { /**