From 53b0b46911bd2be44e264408550e46989dfa6341 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Thu, 9 Jun 2016 15:26:23 +0100 Subject: [PATCH] Fix date being set to start of unix time If a date is going to be set at the start of unix time it will use the current time. Also if there is no date column in the image it will use the current time. --- .../nrw/commons/upload/UploadController.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/commons/app/src/main/java/fr/free/nrw/commons/upload/UploadController.java b/commons/app/src/main/java/fr/free/nrw/commons/upload/UploadController.java index 0826aef5f..fc1334f55 100644 --- a/commons/app/src/main/java/fr/free/nrw/commons/upload/UploadController.java +++ b/commons/app/src/main/java/fr/free/nrw/commons/upload/UploadController.java @@ -1,7 +1,11 @@ package fr.free.nrw.commons.upload; import android.app.Activity; -import android.content.*; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.content.SharedPreferences; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; @@ -10,14 +14,15 @@ import android.preference.PreferenceManager; import android.provider.MediaStore; import android.text.TextUtils; import android.webkit.MimeTypeMap; -import fr.free.nrw.commons.contributions.Contribution; + +import java.io.IOException; +import java.util.Date; + import fr.free.nrw.commons.CommonsApplication; import fr.free.nrw.commons.HandlerService; import fr.free.nrw.commons.Prefs; import fr.free.nrw.commons.Utils; - -import java.io.IOException; -import java.util.Date; +import fr.free.nrw.commons.contributions.Contribution; public class UploadController { private UploadService uploadService; @@ -130,8 +135,15 @@ public class UploadController { new String[]{MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, null); if(cursor != null && cursor.getCount() != 0) { cursor.moveToFirst(); - contribution.setDateCreated(new Date(cursor.getLong(0))); - } // FIXME: Alternate way of setting dateCreated if this data is not found + Date dateCreated = new Date(cursor.getLong(0)); + if(dateCreated.equals(new Date(0))) { + // If date is incorrect (1st second of unix time) then set it to the current date + dateCreated = new Date(); + } + contribution.setDateCreated(dateCreated); + } else { + contribution.setDateCreated(new Date()); + } } return contribution;