aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
parentdfe1a58e0adbf1241650178198b6d263a71e76c0 (diff)
separate received and sent files
fixes #140
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java6
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java47
-rw-r--r--src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/RecordingActivity.java2
4 files changed, 47 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
index c53919784..e5f5d878a 100644
--- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
@@ -95,7 +95,11 @@ public class HttpDownloadConnection implements Transferable {
} else {
extension = lastPart;
}
- message.setRelativeFilePath(fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension != null ? ("." + extension) : ""));
+ if (message.getStatus() == Message.STATUS_RECEIVED){
+ message.setRelativeFilePath(fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension != null ? ("." + extension) : ""));
+ } else {
+ message.setRelativeFilePath("Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension != null ? ("." + extension) : ""));
+ }
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
final String reference = mUrl.getRef();
if (reference != null && AesGcmURLStreamHandler.IV_KEY.matcher(reference).matches()) {
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;
diff --git a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java
index 993de3bc6..fbf77577b 100644
--- a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java
+++ b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java
@@ -94,7 +94,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
Log.d(Config.LOGTAG, "processing file as video");
mXmppConnectionService.startForcingForegroundNotification();
SimpleDateFormat fileDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US);
- message.setRelativeFilePath(fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + "_komp.mp4");
+ message.setRelativeFilePath("Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + "_komp.mp4");
final DownloadableFile file = mXmppConnectionService.getFileBackend().getFile(message);
file.getParentFile().mkdirs();
final ParcelFileDescriptor parcelFileDescriptor = mXmppConnectionService.getContentResolver().openFileDescriptor(uri, "r");
diff --git a/src/main/java/de/pixart/messenger/ui/RecordingActivity.java b/src/main/java/de/pixart/messenger/ui/RecordingActivity.java
index 31dc1681a..c37b27863 100644
--- a/src/main/java/de/pixart/messenger/ui/RecordingActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/RecordingActivity.java
@@ -127,7 +127,7 @@ public class RecordingActivity extends Activity implements View.OnClickListener
private static File generateOutputFilename(Context context) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
- return new File(FileBackend.getConversationsDirectory("Audios")
+ return new File(FileBackend.getConversationsDirectory("Audios/Sent")
+ dateFormat.format(new Date())
+ ".m4a");
}