From 7a3cadbf1c838f097332e5d04a05aeaabb6afa28 Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 24 Jan 2012 14:34:32 +0100 Subject: [PATCH] Refactored AttachmentProvider.openFile() --- .../fsck/k9/provider/AttachmentProvider.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/com/fsck/k9/provider/AttachmentProvider.java b/src/com/fsck/k9/provider/AttachmentProvider.java index 542beab00..1a493a446 100644 --- a/src/com/fsck/k9/provider/AttachmentProvider.java +++ b/src/com/fsck/k9/provider/AttachmentProvider.java @@ -157,24 +157,24 @@ public class AttachmentProvider extends ContentProvider { @Override public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { + File file; + List segments = uri.getPathSegments(); - String dbName = segments.get(0); // "/sdcard/..." is URL-encoded and makes up only 1 segment - String id = segments.get(1); + String accountUuid = segments.get(0); + String attachmentId = segments.get(1); String format = segments.get(2); + if (FORMAT_THUMBNAIL.equals(format)) { int width = Integer.parseInt(segments.get(3)); int height = Integer.parseInt(segments.get(4)); - String filename = "thmb_" + dbName + "_" + id + ".tmp"; - int index = dbName.lastIndexOf('/'); - if (index >= 0) { - filename = /*dbName.substring(0, index + 1) + */"thmb_" + dbName.substring(index + 1) + "_" + id + ".tmp"; - } + + String filename = "thmb_" + accountUuid + "_" + attachmentId + ".tmp"; File dir = getContext().getCacheDir(); - File file = new File(dir, filename); + file = new File(dir, filename); if (!file.exists()) { - String type = getType(dbName, id, FORMAT_VIEW); + String type = getType(accountUuid, attachmentId, FORMAT_VIEW); try { - FileInputStream in = new FileInputStream(getFile(dbName, id)); + FileInputStream in = new FileInputStream(getFile(accountUuid, attachmentId)); try { Bitmap thumbnail = createThumbnail(type, in); if (thumbnail != null) { @@ -187,18 +187,17 @@ public class AttachmentProvider extends ContentProvider { } } } finally { - try { in.close(); } catch (Throwable ignore) {} + try { in.close(); } catch (Throwable ignore) { /* ignore */ } } } catch (IOException ioe) { return null; } } - return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); } else { - return ParcelFileDescriptor.open( - getFile(dbName, id), - ParcelFileDescriptor.MODE_READ_ONLY); + file = getFile(accountUuid, attachmentId); } + + return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); } @Override