trigger Media Scan on:

- download
- delete local (on list and details)
- delete local & remote (on list and details)
This commit is contained in:
tobiasKaminsky 2014-10-17 09:35:25 +02:00
parent a8d55d09dd
commit e5515c1a2d
3 changed files with 45 additions and 5 deletions

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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<String, Void, Bitmap> {