mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Save canonical filename of uploaded files
Also display filenames in a 'pretty'ier way
This commit is contained in:
parent
b4c1c2a06c
commit
b8dd312869
4 changed files with 26 additions and 2 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package org.wikimedia.commons;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.*;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mediawiki.api.*;
|
||||
|
|
@ -265,6 +264,10 @@ public class UploadService extends IntentService {
|
|||
} else {
|
||||
Date dateUploaded = null;
|
||||
dateUploaded = Utils.parseMWDate(result.getString("/api/upload/imageinfo/@timestamp"));
|
||||
String canonicalFilename = "File:" + result.getString("/api/upload/@filename").replace("_", " "); // Title vs Filename
|
||||
String imageUrl = result.getString("/api/upload/imageinfo/@url");
|
||||
contribution.setFilename(canonicalFilename);
|
||||
contribution.setImageUrl(imageUrl);
|
||||
contribution.setState(Contribution.STATE_COMPLETED);
|
||||
contribution.setDateUploaded(dateUploaded);
|
||||
contribution.save();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import java.text.ParseException;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Utils {
|
||||
public static Date parseMWDate(String mwDate) {
|
||||
|
|
@ -73,4 +75,15 @@ public class Utils {
|
|||
task.execute(params);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pattern displayTitlePattern = Pattern.compile("\\w+:(.*)(\\.\\w+)", Pattern.CASE_INSENSITIVE);
|
||||
public static String displayTitleFromTitle(String title) {
|
||||
// FIXME: This does not work for pages without an extension!
|
||||
Matcher matcher = displayTitlePattern.matcher(title);
|
||||
if(matcher.matches()) {
|
||||
return matcher.group(1);
|
||||
} else {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,6 +132,14 @@ public class Contribution extends Media {
|
|||
return cv;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
|
||||
public static class Table {
|
||||
public static final String TABLE_NAME = "contributions";
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
|
|||
imageView.setTag(actualUrl);
|
||||
}
|
||||
|
||||
titleView.setText(title);
|
||||
titleView.setText(Utils.displayTitleFromTitle(title));
|
||||
switch(state) {
|
||||
case Contribution.STATE_COMPLETED:
|
||||
Date uploaded = new Date(cursor.getLong(COLUMN_UPLOADED));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue