diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-06-01 21:41:41 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-06-01 21:41:41 +0200 |
commit | c69ad3f6d245910d3af38bb2545cc13e9c296069 (patch) | |
tree | 7fc068607cbc16304e1a2ad32bada6a5b16f14fc /src/main/java/eu/siacs/conversations/persistance | |
parent | 9fa0aae644627956e1c3c3d8d4800ed685a86419 (diff) |
use datetime as filename
Diffstat (limited to 'src/main/java/eu/siacs/conversations/persistance')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 17 |
1 files changed, 10 insertions, 7 deletions
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(); |