aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-06-01 21:41:41 +0200
committerChristian Schneppe <christian@pix-art.de>2016-06-01 21:41:41 +0200
commitc69ad3f6d245910d3af38bb2545cc13e9c296069 (patch)
tree7fc068607cbc16304e1a2ad32bada6a5b16f14fc /src/main/java/eu/siacs
parent9fa0aae644627956e1c3c3d8d4800ed685a86419 (diff)
use datetime as filename
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java8
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java17
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java10
3 files changed, 24 insertions, 11 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
index 51bfd5666..c7d68de16 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
@@ -10,6 +10,9 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
import java.util.concurrent.CancellationException;
import javax.net.ssl.HttpsURLConnection;
@@ -40,6 +43,8 @@ public class HttpDownloadConnection implements Transferable {
private boolean mUseTor = false;
private boolean canceled = false;
+ private final SimpleDateFormat fileDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
+
public HttpDownloadConnection(HttpConnectionManager manager) {
this.mHttpConnectionManager = manager;
this.mXmppConnectionService = manager.getXmppConnectionService();
@@ -88,7 +93,8 @@ public class HttpDownloadConnection implements Transferable {
} else {
extension = lastPart;
}
- message.setRelativeFilePath(message.getUuid() + "." + extension);
+ String filename = fileDateFormat.format(new Date(message.getTimeSent()));
+ message.setRelativeFilePath(filename + "." + extension);
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
String reference = mUrl.getRef();
if (reference != null && reference.length() == 96) {
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index e2944ed23..64157b597 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -54,7 +54,7 @@ import eu.siacs.conversations.utils.FileUtils;
import eu.siacs.conversations.xmpp.pep.Avatar;
public class FileBackend {
- private final SimpleDateFormat imageDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
+ private final SimpleDateFormat fileDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
private XmppConnectionService mXmppConnectionService;
@@ -105,7 +105,8 @@ public class FileBackend {
final DownloadableFile file;
String path = message.getRelativeFilePath();
if (path == null) {
- path = message.getUuid();
+ String filename = fileDateFormat.format(new Date(message.getTimeSent()));
+ path = filename;
}
if (path.startsWith("/")) {
file = new DownloadableFile(path);
@@ -262,7 +263,8 @@ public class FileBackend {
Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage");
String mime = mXmppConnectionService.getContentResolver().getType(uri);
String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime);
- message.setRelativeFilePath(message.getUuid() + "." + extension);
+ String filename = fileDateFormat.format(new Date(message.getTimeSent()));
+ message.setRelativeFilePath(filename + "." + extension);
copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri);
}
@@ -327,15 +329,16 @@ public class FileBackend {
}
public void copyImageToPrivateStorage(Message message, Uri image) throws FileCopyException {
+ String filename = fileDateFormat.format(new Date(message.getTimeSent()));
switch(Config.IMAGE_FORMAT) {
case JPEG:
- message.setRelativeFilePath(message.getUuid()+".jpg");
+ message.setRelativeFilePath(filename+".jpg");
break;
case PNG:
- message.setRelativeFilePath(message.getUuid()+".png");
+ message.setRelativeFilePath(filename+".png");
break;
case WEBP:
- message.setRelativeFilePath(message.getUuid()+".webp");
+ message.setRelativeFilePath(filename+".webp");
break;
}
copyImageToPrivateStorage(getFile(message), image);
@@ -389,7 +392,7 @@ public class FileBackend {
pathBuilder.append('/');
pathBuilder.append("Camera");
pathBuilder.append('/');
- pathBuilder.append("IMG_" + this.imageDateFormat.format(new Date()) + ".jpg");
+ pathBuilder.append("IMG_" + this.fileDateFormat.format(new Date()) + ".jpg");
Uri uri = Uri.parse("file://" + pathBuilder.toString());
File file = new File(uri.toString());
file.getParentFile().mkdirs();
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index c9ee6bdc2..11b07e86f 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -6,7 +6,9 @@ import android.util.Pair;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -35,6 +37,7 @@ import eu.siacs.conversations.xmpp.jingle.stanzas.Reason;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JingleConnection implements Transferable {
+ private final SimpleDateFormat fileDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
private JingleConnectionManager mJingleConnectionManager;
private XmppConnectionService mXmppConnectionService;
@@ -316,17 +319,18 @@ public class JingleConnection implements Transferable {
if (fileNameElement != null) {
String[] filename = fileNameElement.getContent()
.toLowerCase(Locale.US).toLowerCase().split("\\.");
+ String filename_new = fileDateFormat.format(new Date(message.getTimeSent()));
String extension = filename[filename.length - 1];
if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
message.setType(Message.TYPE_IMAGE);
- message.setRelativeFilePath(message.getUuid()+"."+extension);
+ message.setRelativeFilePath(filename_new+"."+extension);
} else if (VALID_CRYPTO_EXTENSIONS.contains(
filename[filename.length - 1])) {
if (filename.length == 3) {
extension = filename[filename.length - 2];
if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
message.setType(Message.TYPE_IMAGE);
- message.setRelativeFilePath(message.getUuid()+"."+extension);
+ message.setRelativeFilePath(filename_new+"."+extension);
} else {
message.setType(Message.TYPE_FILE);
}
@@ -350,7 +354,7 @@ public class JingleConnection implements Transferable {
suffix = suffix.substring(0,suffix.length() - 4);
}
}
- message.setRelativeFilePath(message.getUuid()+"_"+suffix);
+ message.setRelativeFilePath(filename_new+"_"+suffix);
}
long size = Long.parseLong(fileSize.getContent());
message.setBody(Long.toString(size));