From e5515c1a2d4ec96b52224df11d19259ffafa2b66 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 17 Oct 2014 09:35:25 +0200 Subject: [PATCH] trigger Media Scan on: - download - delete local (on list and details) - delete local & remote (on list and details) --- .../ui/fragment/OCFileListFragment.java | 18 +++++++++++++++--- .../ui/preview/PreviewImageActivity.java | 16 +++++++++++++++- .../ui/preview/PreviewImageFragment.java | 16 +++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index a3c6d3be22..d484776a84 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -43,9 +43,9 @@ import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationD import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; - import android.accounts.Account; import android.app.Activity; +import android.media.MediaScannerConnection; import android.os.Bundle; import android.os.Handler; import android.view.ContextMenu; @@ -472,19 +472,26 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName public void onConfirmation(String callerTag) { if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) { if (mContainerActivity.getStorageManager().getFileById(mTargetFile.getFileId()) != null) { + String path = new File(mTargetFile.getStoragePath()).getParent(); RemoteOperation operation = new RemoveFileOperation( mTargetFile, true, mContainerActivity.getStorageManager()); operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity()); ((FileDisplayActivity) getActivity()).showLoadingDialog(); + + triggerMediaScan(path); } } } @Override public void onNeutral(String callerTag) { + String path = new File(mTargetFile.getStoragePath()).getParent(); mContainerActivity.getStorageManager().removeFile(mTargetFile, false, true); // TODO perform in background task / new thread + + triggerMediaScan(path); + listDirectory(); mContainerActivity.onTransferStateChanged(mTargetFile, false, false); } @@ -493,6 +500,11 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName public void onCancel(String callerTag) { Log_OC.d(TAG, "REMOVAL CANCELED"); } - - + + private void triggerMediaScan(String path){ + MediaScannerConnection.scanFile( + getActivity().getApplicationContext(), + new String[]{path}, + null,null); + } } diff --git a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java index ef48d1237e..5199c01faa 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java @@ -22,6 +22,9 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; +import android.media.MediaScannerConnection; +import android.media.MediaScannerConnection.OnScanCompletedListener; +import android.net.Uri; import android.os.Bundle; import android.os.IBinder; import android.support.v4.app.Fragment; @@ -372,14 +375,25 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C public void onReceive(Context context, Intent intent) { String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); + + + if (getAccount().name.equals(accountName) && downloadedRemotePath != null) { - OCFile file = mStorageManager.getFileByPath(downloadedRemotePath); + final OCFile file = mStorageManager.getFileByPath(downloadedRemotePath); int position = mPreviewImagePagerAdapter.getFilePosition(file); boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false); //boolean isOffscreen = Math.abs((mViewPager.getCurrentItem() - position)) <= mViewPager.getOffscreenPageLimit(); + if (downloadWasFine){ + // Trigger Mediascan + MediaScannerConnection.scanFile( + context, + new String[]{file.getStoragePath()}, + null,null); + } + if (position >= 0 && intent.getAction().equals(FileDownloader.getDownloadFinishMessage())) { if (downloadWasFine) { mPreviewImagePagerAdapter.updateFile(position, file); diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 9ef4db4bc5..d51734899d 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -21,7 +21,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; - import android.accounts.Account; import android.annotation.SuppressLint; import android.app.Activity; @@ -31,6 +30,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; import android.graphics.Point; +import android.media.MediaScannerConnection; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -374,12 +374,15 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper @Override public void onConfirmation(String callerTag) { if (mStorageManager.getFileById(getFile().getFileId()) != null) { // check that the file is still there; + String path = new File(getFile().getStoragePath()).getParent(); mLastRemoteOperation = new RemoveFileOperation( getFile(), // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters true, mStorageManager); mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity()); ((PreviewImageActivity) getActivity()).showLoadingDialog(); + + triggerMediaScan(path); } } @@ -393,7 +396,11 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper OCFile file = getFile(); if (file.isDown()) { // checks it is still there File f = new File(file.getStoragePath()); + String path = f.getParent(); f.delete(); + + triggerMediaScan(path); + file.setStoragePath(null); mStorageManager.saveFile(file); finish(); @@ -408,6 +415,13 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper // nothing to do here } + private void triggerMediaScan(String path){ + MediaScannerConnection.scanFile( + getActivity().getApplicationContext(), + new String[]{path}, + null,null); + } + private class BitmapLoader extends AsyncTask {