mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Add date for {{Information}} template according to EXIF data
This commit is contained in:
parent
b3f8bf815e
commit
88cb714b02
2 changed files with 26 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package org.wikimedia.commons;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mediawiki.api.*;
|
||||
import org.wikimedia.commons.media.Media;
|
||||
|
|
@ -9,8 +10,11 @@ import de.mastacode.http.ProgressListener;
|
|||
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.database.Cursor;
|
||||
import android.os.*;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.text.method.DateTimeKeyListener;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
|
@ -105,10 +109,17 @@ public class UploadService extends IntentService {
|
|||
String description = intent.getStringExtra(EXTRA_DESCRIPTION);
|
||||
String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY);
|
||||
String notificationTag = mediaUri.toString();
|
||||
Date dateCreated = null;
|
||||
|
||||
try {
|
||||
file = this.getContentResolver().openInputStream(mediaUri);
|
||||
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) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -147,13 +158,14 @@ public class UploadService extends IntentService {
|
|||
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);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Log.d("Commons", app.getStringFromDOM(result.getDocument()));
|
||||
notificationManager.cancel(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS);
|
||||
|
||||
String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.wikimedia.commons.media;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import android.net.*;
|
||||
|
|
@ -11,13 +13,16 @@ public class Media {
|
|||
private String mimeType;
|
||||
private String description;
|
||||
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.fileName = fileName;
|
||||
this.description = description;
|
||||
this.editSummary = editSummary;
|
||||
this.userName = userName;
|
||||
this.dateCreated = dateCreated;
|
||||
}
|
||||
|
||||
public Uri getMediaUri() {
|
||||
|
|
@ -34,12 +39,18 @@ public class Media {
|
|||
|
||||
public String getPageContents() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
buffer
|
||||
.append("== {{int:filedesc}} ==\n")
|
||||
.append("{{Information")
|
||||
.append("|Description=").append(description)
|
||||
.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("== {{int:license-header}} ==\n")
|
||||
.append("{{self|cc-by-sa-3.0}}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue