1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 09:52:16 -05:00

Extract method

This commit is contained in:
cketti 2015-02-04 21:14:04 +01:00
parent 937ca7e17a
commit 36abde2c0b

View File

@ -97,19 +97,7 @@ class DownloadImageTask extends AsyncTask<String, Void, String> {
in = contentResolver.openInputStream(uri);
}
// Do we still need an extension?
if (filename.indexOf('.') == -1) {
// Use JPEG as fallback
String extension = "jpeg";
if (mimeType != null) {
// Try to find an extension for the given MIME type
String ext = MimeUtility.getExtensionByMimeType(mimeType);
if (ext != null) {
extension = ext;
}
}
filename += "." + extension;
}
filename = getFileNameWithExtension(filename, mimeType);
String sanitized = FileHelper.sanitizeFilename(filename);
@ -136,6 +124,23 @@ class DownloadImageTask extends AsyncTask<String, Void, String> {
}
}
private String getFileNameWithExtension(String filename, String mimeType) {
if (filename.indexOf('.') != -1) {
return filename;
}
// Use JPEG as fallback
String extension = "jpeg";
if (mimeType != null) {
String extensionFromMimeType = MimeUtility.getExtensionByMimeType(mimeType);
if (extensionFromMimeType != null) {
extension = extensionFromMimeType;
}
}
return filename + "." + extension;
}
@Override
protected void onPostExecute(String filename) {
String text;