aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/persistance
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/persistance')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java
index 07537fe3..45510661 100644
--- a/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java
+++ b/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java
@@ -1,5 +1,6 @@
package de.thedevstack.conversationsplus.persistance;
+import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
@@ -25,10 +26,40 @@ import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.DownloadableFile;
import de.thedevstack.conversationsplus.entities.Message;
+import de.thedevstack.conversationsplus.services.XmppConnectionService;
public class FileBackend {
private static final SimpleDateFormat imageDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
+ public static void createNoMedia() {
+ final File nomedia = new File(getConversationsFileDirectory()+".nomedia");
+ if (!nomedia.exists()) {
+ try {
+ nomedia.createNewFile();
+ } catch (Exception e) {
+ Log.d(Config.LOGTAG, "could not create nomedia file");
+ }
+ }
+ }
+
+ public static void updateMediaScanner(File file, XmppConnectionService xmppConnectionService) {
+ if (file.getAbsolutePath().startsWith(getConversationsImageDirectory())) {
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ intent.setData(Uri.fromFile(file));
+ xmppConnectionService.sendBroadcast(intent);
+ }
+ }
+
+ public static boolean deleteFile(Message message, XmppConnectionService xmppConnectionService) {
+ File file = getFile(message);
+ if (file.delete()) {
+ updateMediaScanner(file, xmppConnectionService);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
public static DownloadableFile getFile(Message message) {
return getFile(message, true);
}