mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Extract method
This commit is contained in:
parent
937ca7e17a
commit
36abde2c0b
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user