From d1dd50e31c909943cf9bf8d94f5ab608dcda82f4 Mon Sep 17 00:00:00 2001 From: rymdhund Date: Fri, 11 Jul 2014 12:58:21 +0200 Subject: [PATCH] Add date to saved media filenames Fixes #1689 Closes #1693 --- .../thoughtcrime/securesms/ConversationFragment.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index 87a145976a..bd79136f44 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -411,7 +411,7 @@ public class ConversationFragment extends SherlockListFragment return FAILURE; } - File mediaFile = constructOutputFile(slide); + File mediaFile = constructOutputFile(slide, messageRecord[0].getDateReceived()); InputStream inputStream = slide.getPartDataInputStream(); OutputStream outputStream = new FileOutputStream(mediaFile); @@ -470,7 +470,7 @@ public class ConversationFragment extends SherlockListFragment return null; } - private File constructOutputFile(Slide slide) throws IOException { + private File constructOutputFile(Slide slide, long timestamp) throws IOException { File sdCard = Environment.getExternalStorageDirectory(); File outputDirectory; @@ -484,13 +484,14 @@ public class ConversationFragment extends SherlockListFragment outputDirectory.mkdirs(); - MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); - String extension = mimeTypeMap.getExtensionFromMimeType(slide.getContentType()); + MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); + String extension = mimeTypeMap.getExtensionFromMimeType(slide.getContentType()); + SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); if (extension == null) extension = "attach"; - return File.createTempFile("textsecure", "." + extension, outputDirectory); + return File.createTempFile("textsecure-" + dateFormatter.format(timestamp), "." + extension, outputDirectory); } } }