Add date for {{Information}} template according to EXIF data

This commit is contained in:
YuviPanda 2012-11-03 15:24:56 +05:30
parent b3f8bf815e
commit 88cb714b02
2 changed files with 26 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package org.wikimedia.commons; package org.wikimedia.commons;
import java.io.*; import java.io.*;
import java.util.Date;
import org.mediawiki.api.*; import org.mediawiki.api.*;
import org.wikimedia.commons.media.Media; import org.wikimedia.commons.media.Media;
@ -9,8 +10,11 @@ import de.mastacode.http.ProgressListener;
import android.app.*; import android.app.*;
import android.content.*; import android.content.*;
import android.database.Cursor;
import android.os.*; import android.os.*;
import android.provider.MediaStore;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.text.method.DateTimeKeyListener;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
@ -105,10 +109,17 @@ public class UploadService extends IntentService {
String description = intent.getStringExtra(EXTRA_DESCRIPTION); String description = intent.getStringExtra(EXTRA_DESCRIPTION);
String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY); String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY);
String notificationTag = mediaUri.toString(); String notificationTag = mediaUri.toString();
Date dateCreated = null;
try { try {
file = this.getContentResolver().openInputStream(mediaUri); file = this.getContentResolver().openInputStream(mediaUri);
length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength(); length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
Cursor cursor = this.getContentResolver().query(mediaUri,
new String[] { MediaStore.Images.ImageColumns.DATE_TAKEN }, null, null, null);
if(cursor.getCount() != 0) {
cursor.moveToFirst();
dateCreated = new Date(cursor.getInt(0));
}
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -147,13 +158,14 @@ public class UploadService extends IntentService {
return; return;
} }
} }
Media media = new Media(mediaUri, filename, description, editSummary, app.getCurrentAccount().name); Media media = new Media(mediaUri, filename, description, editSummary, app.getCurrentAccount().name, dateCreated);
result = api.upload(filename, file, length, media.getPageContents(), editSummary, notificationUpdater); result = api.upload(filename, file, length, media.getPageContents(), editSummary, notificationUpdater);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Log.d("Commons", app.getStringFromDOM(result.getDocument()));
notificationManager.cancel(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS); notificationManager.cancel(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS);
String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl"); String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl");

View file

@ -1,5 +1,7 @@
package org.wikimedia.commons.media; package org.wikimedia.commons.media;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import android.net.*; import android.net.*;
@ -11,13 +13,16 @@ public class Media {
private String mimeType; private String mimeType;
private String description; private String description;
private String userName; private String userName;
private Date dateCreated;
private Date dateUploaded;
public Media(Uri mediaUri, String fileName, String description, String editSummary, String userName) { public Media(Uri mediaUri, String fileName, String description, String editSummary, String userName, Date dateCreated) {
this.mediaUri = mediaUri; this.mediaUri = mediaUri;
this.fileName = fileName; this.fileName = fileName;
this.description = description; this.description = description;
this.editSummary = editSummary; this.editSummary = editSummary;
this.userName = userName; this.userName = userName;
this.dateCreated = dateCreated;
} }
public Uri getMediaUri() { public Uri getMediaUri() {
@ -34,12 +39,18 @@ public class Media {
public String getPageContents() { public String getPageContents() {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
buffer buffer
.append("== {{int:filedesc}} ==\n") .append("== {{int:filedesc}} ==\n")
.append("{{Information") .append("{{Information")
.append("|Description=").append(description) .append("|Description=").append(description)
.append("|source=").append("{{own}}") .append("|source=").append("{{own}}")
.append("|author=[[User:").append(userName).append("]]") .append("|author=[[User:").append(userName).append("]]");
if(dateCreated != null) {
buffer
.append("|date={{According to EXIF data|").append(isoFormat.format(dateCreated)).append("}}");
}
buffer
.append("}}").append("\n") .append("}}").append("\n")
.append("== {{int:license-header}} ==\n") .append("== {{int:license-header}} ==\n")
.append("{{self|cc-by-sa-3.0}}") .append("{{self|cc-by-sa-3.0}}")