1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Simplify MediaScannerNotifier

This commit is contained in:
cketti 2014-11-10 06:43:26 +01:00
parent c3f1420ef6
commit e64ca84f1b
2 changed files with 7 additions and 20 deletions

View File

@ -1,28 +1,15 @@
package com.fsck.k9.helper; package com.fsck.k9.helper;
import android.content.Context;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import java.io.File; import java.io.File;
import android.content.Context;
import android.media.MediaScannerConnection;
public class MediaScannerNotifier implements MediaScannerConnectionClient {
private MediaScannerConnection mConnection;
private File mFile;
public MediaScannerNotifier(Context context, File file) { public class MediaScannerNotifier {
mFile = file; public static void notify(Context context, File file) {
mConnection = new MediaScannerConnection(context, this); String[] paths = { file.getAbsolutePath() };
mConnection.connect(); MediaScannerConnection.scanFile(context, paths, null, null);
}
public void onMediaScannerConnected() {
mConnection.scanFile(mFile.getAbsolutePath(), null);
}
public void onScanCompleted(String path, Uri uri) {
mConnection.disconnect();
} }
} }

View File

@ -227,7 +227,7 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
displayAttachmentSavedMessage(file.toString()); displayAttachmentSavedMessage(file.toString());
new MediaScannerNotifier(context, file); MediaScannerNotifier.notify(context, file);
} catch (IOException ioe) { } catch (IOException ioe) {
if (K9.DEBUG) { if (K9.DEBUG) {
Log.e(K9.LOG_TAG, "Error saving attachment", ioe); Log.e(K9.LOG_TAG, "Error saving attachment", ioe);