From f85cf5dcff9fcc1f28b8dddfeecd13f743fc8792 Mon Sep 17 00:00:00 2001 From: Timo Witte Date: Sun, 19 Jun 2016 23:25:52 +0200 Subject: [PATCH] =?UTF-8?q?use=20long=20for=20timestamp=20and=20don=C2=B4t?= =?UTF-8?q?=20fail=20if=20timestamp=20is=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../files/InstantUploadBroadcastReceiver.java | 5 ++--- src/com/owncloud/android/utils/FileStorageUtils.java | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java index a1b56a6d0d..54040af3eb 100644 --- a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java +++ b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java @@ -83,7 +83,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { String file_path = null; String file_name = null; String mime_type = null; - String date_taken = null; + long date_taken = 0; Log_OC.i(TAG, "New photo received"); @@ -117,8 +117,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { file_path = c.getString(c.getColumnIndex(Images.Media.DATA)); file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME)); mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE)); - // date_taken = c.getString(c.getColumnIndex(Images.Media.DATE_TAKEN)); does not seem to work for all cameras - date_taken = Long.toString(System.currentTimeMillis()); + date_taken = System.currentTimeMillis(); c.close(); if (file_path.equals(lastUploadedPhotoPath)) { diff --git a/src/com/owncloud/android/utils/FileStorageUtils.java b/src/com/owncloud/android/utils/FileStorageUtils.java index 1cc44e4452..7e988bf42e 100644 --- a/src/com/owncloud/android/utils/FileStorageUtils.java +++ b/src/com/owncloud/android/utils/FileStorageUtils.java @@ -128,22 +128,22 @@ public class FileStorageUtils { * @param dateTaken: Time in milliseconds since 1970 when the picture was taken. * @return */ - public static String getInstantUploadFilePath(Context context, String fileName, String dateTaken) { + public static String getInstantUploadFilePath(Context context, String fileName, long dateTaken) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); String uploadPathdef = context.getString(R.string.instant_upload_path); String uploadPath = pref.getString("instant_upload_path", uploadPathdef); - String subFolders = ""; - if(dateTaken != null && com.owncloud.android.db.PreferenceManager.instantPictureUploadPathUseSubfolders(context)) { + String subFolders = null; + if(dateTaken != 0 && com.owncloud.android.db.PreferenceManager.instantPictureUploadPathUseSubfolders(context)) { try { SimpleDateFormat formatter = new SimpleDateFormat("yyyy" + OCFile.PATH_SEPARATOR + "MM" + OCFile.PATH_SEPARATOR, Locale.ENGLISH); - subFolders = formatter.format(new Date(Long.parseLong(dateTaken))); - Date d = new Date(Long.parseLong((dateTaken))); + subFolders = formatter.format(new Date(dateTaken)); + Date d = new Date(dateTaken); } catch(RuntimeException ex) { // don´t use a subfolder if we can´t parse the date } } - String value = uploadPath + OCFile.PATH_SEPARATOR + subFolders + (fileName == null ? "" : fileName); + String value = uploadPath + OCFile.PATH_SEPARATOR + (subFolders != null ? subFolders : "") + (fileName == null ? "" : fileName); return value; }