From 8f474dc02f01d7805716422625ef7b50fa0e4aef Mon Sep 17 00:00:00 2001 From: Mark Wei Date: Wed, 19 Jun 2013 16:11:32 -0700 Subject: [PATCH] Fix IMAP attachments REDOWNLOADING. Previously, if you clicked Download again, you will never be able to view that attachment again. Change-Id: Ie944becaf8c89a1a27b8625af4795550e9213f5e --- .../android/email/provider/EmailProvider.java | 57 ++++++++++--------- .../service/AttachmentDownloadService.java | 2 + 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java index 4af60d1e7..2a014b951 100644 --- a/src/com/android/email/provider/EmailProvider.java +++ b/src/com/android/email/provider/EmailProvider.java @@ -3781,6 +3781,7 @@ public class EmailProvider extends ContentProvider { } private int uiUpdateAttachment(Uri uri, ContentValues uiValues) { + int result = 0; Integer stateValue = uiValues.getAsInteger(UIProvider.AttachmentColumns.STATE); if (stateValue != null) { // This is a command from UIProvider @@ -3790,37 +3791,41 @@ public class EmailProvider extends ContentProvider { Attachment.restoreAttachmentWithId(context, attachmentId); if (attachment == null) { // Went away; ah, well... - return 0; + return result; } + int state = stateValue.intValue(); ContentValues values = new ContentValues(); - switch (stateValue.intValue()) { - case UIProvider.AttachmentState.NOT_SAVED: - // Set state, try to cancel request - values.put(AttachmentColumns.UI_STATE, stateValue); - values.put(AttachmentColumns.FLAGS, - attachment.mFlags &= ~Attachment.FLAG_DOWNLOAD_USER_REQUEST); - attachment.update(context, values); - return 1; - case UIProvider.AttachmentState.DOWNLOADING: - // Set state and destination; request download - values.put(AttachmentColumns.UI_STATE, stateValue); - Integer destinationValue = + if (state == UIProvider.AttachmentState.NOT_SAVED + || state == UIProvider.AttachmentState.REDOWNLOADING) { + // Set state, try to cancel request + values.put(AttachmentColumns.UI_STATE, UIProvider.AttachmentState.NOT_SAVED); + values.put(AttachmentColumns.FLAGS, + attachment.mFlags &= ~Attachment.FLAG_DOWNLOAD_USER_REQUEST); + attachment.update(context, values); + result = 1; + } + if (state == UIProvider.AttachmentState.DOWNLOADING + || state == UIProvider.AttachmentState.REDOWNLOADING) { + // Set state and destination; request download + values.put(AttachmentColumns.UI_STATE, UIProvider.AttachmentState.DOWNLOADING); + Integer destinationValue = uiValues.getAsInteger(UIProvider.AttachmentColumns.DESTINATION); - values.put(AttachmentColumns.UI_DESTINATION, - destinationValue == null ? 0 : destinationValue); - values.put(AttachmentColumns.FLAGS, - attachment.mFlags | Attachment.FLAG_DOWNLOAD_USER_REQUEST); - attachment.update(context, values); - return 1; - case UIProvider.AttachmentState.SAVED: - // If this is an inline attachment, notify message has changed - if (!TextUtils.isEmpty(attachment.mContentId)) { - notifyUI(UIPROVIDER_MESSAGE_NOTIFIER, attachment.mMessageKey); - } - return 1; + values.put(AttachmentColumns.UI_DESTINATION, + destinationValue == null ? 0 : destinationValue); + values.put(AttachmentColumns.FLAGS, + attachment.mFlags | Attachment.FLAG_DOWNLOAD_USER_REQUEST); + attachment.update(context, values); + result = 1; + } + if (state == UIProvider.AttachmentState.SAVED) { + // If this is an inline attachment, notify message has changed + if (!TextUtils.isEmpty(attachment.mContentId)) { + notifyUI(UIPROVIDER_MESSAGE_NOTIFIER, attachment.mMessageKey); + } + result = 1; } } - return 0; + return result; } private int uiUpdateFolder(final Context context, Uri uri, ContentValues uiValues) { diff --git a/src/com/android/email/service/AttachmentDownloadService.java b/src/com/android/email/service/AttachmentDownloadService.java index 8f1b02453..96387a59a 100644 --- a/src/com/android/email/service/AttachmentDownloadService.java +++ b/src/com/android/email/service/AttachmentDownloadService.java @@ -45,6 +45,7 @@ import com.android.emailcommon.service.EmailServiceStatus; import com.android.emailcommon.service.IEmailServiceCallback; import com.android.emailcommon.utility.AttachmentUtilities; import com.android.emailcommon.utility.Utility; +import com.android.mail.providers.UIProvider.AttachmentState; import com.android.mail.utils.LogUtils; import java.io.File; @@ -621,6 +622,7 @@ public class AttachmentDownloadService extends Service implements Runnable { int flags = Attachment.FLAG_DOWNLOAD_FORWARD | Attachment.FLAG_DOWNLOAD_USER_REQUEST; cv.put(Attachment.FLAGS, attachment.mFlags &= ~flags); + cv.put(Attachment.UI_STATE, AttachmentState.SAVED); attachment.update(mContext, cv); } }