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);
|
in = contentResolver.openInputStream(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we still need an extension?
|
filename = getFileNameWithExtension(filename, mimeType);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
String sanitized = FileHelper.sanitizeFilename(filename);
|
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
|
@Override
|
||||||
protected void onPostExecute(String filename) {
|
protected void onPostExecute(String filename) {
|
||||||
String text;
|
String text;
|
||||||
|
Loading…
Reference in New Issue
Block a user