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:
parent
336da94386
commit
f69ef280ba
4 changed files with 18 additions and 9 deletions
|
@ -162,7 +162,7 @@ public class AttachmentPresenter {
|
|||
if (attachmentViewInfo.inlineAttachment) {
|
||||
continue;
|
||||
}
|
||||
if (!attachmentViewInfo.isContentAvailable) {
|
||||
if (!attachmentViewInfo.isContentAvailable()) {
|
||||
allPartsAvailable = false;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -21,16 +21,24 @@ public class AttachmentViewInfo {
|
|||
public final Uri internalUri;
|
||||
public final boolean inlineAttachment;
|
||||
public final Part part;
|
||||
public final boolean isContentAvailable;
|
||||
private boolean contentAvailable;
|
||||
|
||||
public AttachmentViewInfo(String mimeType, String displayName, long size, Uri internalUri, boolean inlineAttachment,
|
||||
Part part, boolean isContentAvailable) {
|
||||
Part part, boolean contentAvailable) {
|
||||
this.mimeType = mimeType;
|
||||
this.displayName = displayName;
|
||||
this.size = size;
|
||||
this.internalUri = internalUri;
|
||||
this.inlineAttachment = inlineAttachment;
|
||||
this.part = part;
|
||||
this.isContentAvailable = isContentAvailable;
|
||||
this.contentAvailable = contentAvailable;
|
||||
}
|
||||
|
||||
public boolean isContentAvailable() {
|
||||
return contentAvailable;
|
||||
}
|
||||
|
||||
public void setContentAvailable() {
|
||||
this.contentAvailable = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class AttachmentController {
|
|||
}
|
||||
|
||||
public void viewAttachment() {
|
||||
if (!attachment.isContentAvailable) {
|
||||
if (!attachment.isContentAvailable()) {
|
||||
downloadAndViewAttachment((LocalPart) attachment.part);
|
||||
} else {
|
||||
viewLocalAttachment();
|
||||
|
@ -100,6 +100,7 @@ public class AttachmentController {
|
|||
controller.loadAttachment(account, message, attachment.part, new SimpleMessagingListener() {
|
||||
@Override
|
||||
public void loadAttachmentFinished(Account account, Message message, Part part) {
|
||||
attachment.setContentAvailable();
|
||||
messageViewFragment.hideAttachmentLoadingDialogOnMainThread();
|
||||
messageViewFragment.runOnMainThread(attachmentDownloadedCallback);
|
||||
}
|
||||
|
@ -129,7 +130,7 @@ public class AttachmentController {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!attachment.isContentAvailable) {
|
||||
if (!attachment.isContentAvailable()) {
|
||||
downloadAndSaveAttachmentTo((LocalPart) attachment.part, directory);
|
||||
} else {
|
||||
saveLocalAttachmentTo(directory);
|
||||
|
|
|
@ -168,7 +168,7 @@ public class AttachmentInfoExtractorTest {
|
|||
|
||||
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
|
||||
|
||||
assertFalse(attachmentViewInfo.isContentAvailable);
|
||||
assertFalse(attachmentViewInfo.isContentAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -178,7 +178,7 @@ public class AttachmentInfoExtractorTest {
|
|||
|
||||
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
|
||||
|
||||
assertTrue(attachmentViewInfo.isContentAvailable);
|
||||
assertTrue(attachmentViewInfo.isContentAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -206,6 +206,6 @@ public class AttachmentInfoExtractorTest {
|
|||
assertEquals(TEST_SIZE, attachmentViewInfo.size);
|
||||
assertEquals(TEST_MIME_TYPE, attachmentViewInfo.mimeType);
|
||||
assertFalse(attachmentViewInfo.inlineAttachment);
|
||||
assertTrue(attachmentViewInfo.isContentAvailable);
|
||||
assertTrue(attachmentViewInfo.isContentAvailable());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue