mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Merge pull request #232 from whym/fixextension
Fix extension replacement, add related tests
This commit is contained in:
commit
eb275e25df
5 changed files with 51 additions and 17 deletions
|
|
@ -240,4 +240,18 @@ public class Utils {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String fixExtension(String title, String extension) {
|
||||
// People are used to ".jpg" more than ".jpeg" which the system gives us.
|
||||
if (extension != null && extension.toLowerCase().equals("jpeg")) {
|
||||
extension = "jpg";
|
||||
}
|
||||
if (title.toLowerCase().endsWith(".jpeg")) {
|
||||
title = title.replaceFirst("\\.jpeg$", ".jpg");
|
||||
}
|
||||
if (extension != null && !title.toLowerCase().endsWith("." + extension.toLowerCase())) {
|
||||
title += "." + extension;
|
||||
}
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
|
@ -15,8 +14,6 @@ import android.preference.PreferenceManager;
|
|||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
|
@ -24,7 +21,6 @@ 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.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
|
||||
|
|
@ -69,20 +65,9 @@ public class UploadController {
|
|||
}
|
||||
}
|
||||
|
||||
public void startUpload(String rawTitle, Uri mediaUri, String description, String mimeType, String source, ContributionUploadProgress onComplete) {
|
||||
public void startUpload(String title, Uri mediaUri, String description, String mimeType, String source, ContributionUploadProgress onComplete) {
|
||||
Contribution contribution;
|
||||
|
||||
String title = rawTitle;
|
||||
String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);
|
||||
// People are used to ".jpg" more than ".jpeg" which the system gives us.
|
||||
if (extension != null && extension.toLowerCase().equals("jpeg")) {
|
||||
extension = "jpg";
|
||||
}
|
||||
if(extension != null && !title.toLowerCase().endsWith(extension.toLowerCase())) {
|
||||
title += "." + extension;
|
||||
}
|
||||
|
||||
|
||||
contribution = new Contribution(mediaUri, null, title, description, -1, null, null, app.getCurrentAccount().name, CommonsApplication.DEFAULT_EDIT_SUMMARY);
|
||||
|
||||
contribution.setTag("mimeType", mimeType);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import android.app.*;
|
|||
import android.content.*;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.*;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.*;
|
||||
|
||||
import fr.free.nrw.commons.contributions.*;
|
||||
|
|
@ -197,7 +198,11 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
this.startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification.build());
|
||||
|
||||
try {
|
||||
String filename = findUniqueFilename(contribution.getFilename());
|
||||
|
||||
String filename = Utils.fixExtension(
|
||||
contribution.getFilename(),
|
||||
MimeTypeMap.getSingleton().getExtensionFromMimeType((String)contribution.getTag("mimeType")));
|
||||
filename = findUniqueFilename(filename);
|
||||
if(!api.validateLogin()) {
|
||||
// Need to revalidate!
|
||||
if(app.revalidateAuthToken()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue