aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/persistance/FileBackend.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-05-19 21:43:46 +0200
committerChristian Schneppe <christian@pix-art.de>2019-05-19 21:43:46 +0200
commit6e040b7ac2a1fb5152df40e0a7ca961e827a32e6 (patch)
tree32f3e7c017a2cc94cc6f3f1f4f7067863ded2381 /src/main/java/de/pixart/messenger/persistance/FileBackend.java
parentdfe1a58e0adbf1241650178198b6d263a71e76c0 (diff)
separate received and sent files
fixes #140
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 33a524894..066cd21be 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -85,6 +85,10 @@ public class FileBackend {
private void createNoMedia() {
final File nomedia_files = new File(getConversationsDirectory("Files") + ".nomedia");
final File nomedia_audios = new File(getConversationsDirectory("Audios") + ".nomedia");
+ final File nomedia_videos_sent = new File(getConversationsDirectory("Videos/Sent") + ".nomedia");
+ final File nomedia_files_sent = new File(getConversationsDirectory("Files/Sent") + ".nomedia");
+ final File nomedia_audios_sent = new File(getConversationsDirectory("Audios/Sent") + ".nomedia");
+ final File nomedia_images_sent = new File(getConversationsDirectory("Images/Sent") + ".nomedia");
if (!nomedia_files.exists()) {
try {
nomedia_files.createNewFile();
@@ -99,6 +103,34 @@ public class FileBackend {
Log.d(Config.LOGTAG, "could not create nomedia file for audio directory");
}
}
+ if (!nomedia_videos_sent.exists()) {
+ try {
+ nomedia_videos_sent.createNewFile();
+ } catch (Exception e) {
+ Log.d(Config.LOGTAG, "could not create nomedia file for videos sent directory");
+ }
+ }
+ if (!nomedia_files_sent.exists()) {
+ try {
+ nomedia_files_sent.createNewFile();
+ } catch (Exception e) {
+ Log.d(Config.LOGTAG, "could not create nomedia file for files sent directory");
+ }
+ }
+ if (!nomedia_audios_sent.exists()) {
+ try {
+ nomedia_audios_sent.createNewFile();
+ } catch (Exception e) {
+ Log.d(Config.LOGTAG, "could not create nomedia file for audios sent directory");
+ }
+ }
+ if (!nomedia_images_sent.exists()) {
+ try {
+ nomedia_images_sent.createNewFile();
+ } catch (Exception e) {
+ Log.d(Config.LOGTAG, "could not create nomedia file for images sent directory");
+ }
+ }
}
public static Uri getMediaUri(Context context, File file) {
@@ -269,7 +301,7 @@ public class FileBackend {
for (DatabaseBackend.FilePath relativeFilePath : relativeFilePaths) {
final String mime = MimeUtils.guessMimeTypeFromExtension(MimeUtils.extractRelevantExtension(relativeFilePath.path));
final File file = getFileForPath(relativeFilePath.path, mime);
- if (mime != null && (mime.startsWith("image/") || mime.startsWith("video/"))) {
+ if (file.exists() && mime != null && (mime.startsWith("image/") || mime.startsWith("video/"))) {
attachments.add(Attachment.of(relativeFilePath.uuid, file, mime));
}
}
@@ -437,7 +469,7 @@ public class FileBackend {
if ("ogg".equals(extension) && type != null && type.startsWith("audio/")) {
extension = "oga";
}
- String filename = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4);
+ String filename = "Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4);
message.setRelativeFilePath(filename + "." + extension);
copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri);
}
@@ -544,7 +576,7 @@ public class FileBackend {
}
public void copyImageToPrivateStorage(Message message, Uri image) throws FileCopyException {
- String filename = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4);
+ String filename = "Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4);
switch (Config.IMAGE_FORMAT) {
case JPEG:
message.setRelativeFilePath(filename + ".jpg");
@@ -594,12 +626,13 @@ public class FileBackend {
// If only the UUID were used, the first loaded thumbnail would be cached and the next loading
// would get that thumbnail which would have the size of the first cached thumbnail
// possibly leading to undesirable appearance of the displayed thumbnail.
- final String key = message.getUuid() + String.valueOf(size);final String uuid = message.getUuid();
+ final String key = message.getUuid() + String.valueOf(size);
+ final String uuid = message.getUuid();
final LruCache<String, Bitmap> cache = mXmppConnectionService.getBitmapCache();
- Bitmap thumbnail = cache.get(key );
+ Bitmap thumbnail = cache.get(key);
if ((thumbnail == null) && (!cacheOnly)) {
synchronized (THUMBNAIL_LOCK) {
- thumbnail = cache.get(key );
+ thumbnail = cache.get(key);
if (thumbnail != null) {
return thumbnail;
}
@@ -621,7 +654,7 @@ public class FileBackend {
thumbnail = withGifOverlay;
}
}
- cache.put(key , thumbnail);
+ cache.put(key, thumbnail);
}
}
return thumbnail;