Avoid downloading attachments multiple times

Mark an attachment as downloaded so repeated clicks on "Open" or "Save"
won't download the attachment again.
This commit is contained in:
cketti 2017-04-13 19:56:29 +02:00
parent 336da94386
commit f69ef280ba
4 changed files with 18 additions and 9 deletions

View file

@ -162,7 +162,7 @@ public class AttachmentPresenter {
if (attachmentViewInfo.inlineAttachment) { if (attachmentViewInfo.inlineAttachment) {
continue; continue;
} }
if (!attachmentViewInfo.isContentAvailable) { if (!attachmentViewInfo.isContentAvailable()) {
allPartsAvailable = false; allPartsAvailable = false;
continue; continue;
} }

View file

@ -21,16 +21,24 @@ public class AttachmentViewInfo {
public final Uri internalUri; public final Uri internalUri;
public final boolean inlineAttachment; public final boolean inlineAttachment;
public final Part part; public final Part part;
public final boolean isContentAvailable; private boolean contentAvailable;
public AttachmentViewInfo(String mimeType, String displayName, long size, Uri internalUri, boolean inlineAttachment, public AttachmentViewInfo(String mimeType, String displayName, long size, Uri internalUri, boolean inlineAttachment,
Part part, boolean isContentAvailable) { Part part, boolean contentAvailable) {
this.mimeType = mimeType; this.mimeType = mimeType;
this.displayName = displayName; this.displayName = displayName;
this.size = size; this.size = size;
this.internalUri = internalUri; this.internalUri = internalUri;
this.inlineAttachment = inlineAttachment; this.inlineAttachment = inlineAttachment;
this.part = part; this.part = part;
this.isContentAvailable = isContentAvailable; this.contentAvailable = contentAvailable;
}
public boolean isContentAvailable() {
return contentAvailable;
}
public void setContentAvailable() {
this.contentAvailable = true;
} }
} }

View file

@ -57,7 +57,7 @@ public class AttachmentController {
} }
public void viewAttachment() { public void viewAttachment() {
if (!attachment.isContentAvailable) { if (!attachment.isContentAvailable()) {
downloadAndViewAttachment((LocalPart) attachment.part); downloadAndViewAttachment((LocalPart) attachment.part);
} else { } else {
viewLocalAttachment(); viewLocalAttachment();
@ -100,6 +100,7 @@ public class AttachmentController {
controller.loadAttachment(account, message, attachment.part, new SimpleMessagingListener() { controller.loadAttachment(account, message, attachment.part, new SimpleMessagingListener() {
@Override @Override
public void loadAttachmentFinished(Account account, Message message, Part part) { public void loadAttachmentFinished(Account account, Message message, Part part) {
attachment.setContentAvailable();
messageViewFragment.hideAttachmentLoadingDialogOnMainThread(); messageViewFragment.hideAttachmentLoadingDialogOnMainThread();
messageViewFragment.runOnMainThread(attachmentDownloadedCallback); messageViewFragment.runOnMainThread(attachmentDownloadedCallback);
} }
@ -129,7 +130,7 @@ public class AttachmentController {
return; return;
} }
if (!attachment.isContentAvailable) { if (!attachment.isContentAvailable()) {
downloadAndSaveAttachmentTo((LocalPart) attachment.part, directory); downloadAndSaveAttachmentTo((LocalPart) attachment.part, directory);
} else { } else {
saveLocalAttachmentTo(directory); saveLocalAttachmentTo(directory);

View file

@ -168,7 +168,7 @@ public class AttachmentInfoExtractorTest {
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part); AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
assertFalse(attachmentViewInfo.isContentAvailable); assertFalse(attachmentViewInfo.isContentAvailable());
} }
@Test @Test
@ -178,7 +178,7 @@ public class AttachmentInfoExtractorTest {
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part); AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
assertTrue(attachmentViewInfo.isContentAvailable); assertTrue(attachmentViewInfo.isContentAvailable());
} }
@Test @Test
@ -206,6 +206,6 @@ public class AttachmentInfoExtractorTest {
assertEquals(TEST_SIZE, attachmentViewInfo.size); assertEquals(TEST_SIZE, attachmentViewInfo.size);
assertEquals(TEST_MIME_TYPE, attachmentViewInfo.mimeType); assertEquals(TEST_MIME_TYPE, attachmentViewInfo.mimeType);
assertFalse(attachmentViewInfo.inlineAttachment); assertFalse(attachmentViewInfo.inlineAttachment);
assertTrue(attachmentViewInfo.isContentAvailable); assertTrue(attachmentViewInfo.isContentAvailable());
} }
} }