From 41378188f97d832873781ebfc9040f5c0596b5c0 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Sun, 20 Feb 2011 18:49:55 +0100 Subject: [PATCH 1/2] Updates to the view need to happen on the UI thread Fixes downloading attachments (would just fail silently) Also added a ProgressDialog since progress() just asks for progress to displayed in the title bar. Since there is no title bar, no progress is shown at all. --- res/values/ids.xml | 1 + res/values/strings.xml | 2 + src/com/fsck/k9/activity/MessageView.java | 65 +++++++++++++++-------- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/res/values/ids.xml b/res/values/ids.xml index a2b91bfee..b144b9153 100644 --- a/res/values/ids.xml +++ b/res/values/ids.xml @@ -2,5 +2,6 @@ + diff --git a/res/values/strings.xml b/res/values/strings.xml index db250401b..4fd6b3938 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1021,6 +1021,8 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Delete Do not delete + Downloading attachment + Debug logging to Android logging system enabled ยป diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index 638aae075..3c2ef4cb3 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -2,6 +2,7 @@ package com.fsck.k9.activity; import android.app.AlertDialog; import android.app.Dialog; +import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -942,9 +943,12 @@ public class MessageView extends K9Activity implements OnClickListener { @Override protected Dialog onCreateDialog(final int id) { switch (id) { - case R.id.dialog_confirm_delete: { - return createConfirmDeleteDialog(id); - } + case R.id.dialog_confirm_delete: return createConfirmDeleteDialog(id); + case R.id.dialog_attachment_progress: + ProgressDialog d = new ProgressDialog(this); + d.setIndeterminate(true); + d.setTitle(R.string.dialog_attachment_progress_title); + return d; } return super.onCreateDialog(id); } @@ -1075,32 +1079,42 @@ public class MessageView extends K9Activity implements OnClickListener { } @Override - public void loadAttachmentStarted(Account account, Message message, Part part, Object tag, boolean requiresDownload) { + public void loadAttachmentStarted(Account account, Message message, Part part, Object tag, final boolean requiresDownload) { if (mMessage != message) { return; } - mMessageView.setAttachmentsEnabled(false); - mHandler.progress(true); - if (requiresDownload) { - mHandler.fetchingAttachment(); - } + mHandler.post(new Runnable() { + @Override + public void run() { + mMessageView.setAttachmentsEnabled(false); + showDialog(R.id.dialog_attachment_progress); + if (requiresDownload) { + mHandler.fetchingAttachment(); + } + } + }); } @Override - public void loadAttachmentFinished(Account account, Message message, Part part, Object tag) { + public void loadAttachmentFinished(Account account, Message message, Part part, final Object tag) { if (mMessage != message) { return; } - mMessageView.setAttachmentsEnabled(true); - mHandler.progress(false); - Object[] params = (Object[]) tag; - boolean download = (Boolean) params[0]; - AttachmentView attachment = (AttachmentView) params[1]; - if (download) { - attachment.writeFile(); - } else { - attachment.showFile(); - } + mHandler.post(new Runnable() { + public void run() { + mMessageView.setAttachmentsEnabled(true); + removeDialog(R.id.dialog_attachment_progress); + Object[] params = (Object[]) tag; + boolean download = (Boolean) params[0]; + AttachmentView attachment = (AttachmentView) params[1]; + if (download) { + attachment.writeFile(); + } else { + attachment.showFile(); + } + + } + }); } @Override @@ -1108,9 +1122,14 @@ public class MessageView extends K9Activity implements OnClickListener { if (mMessage != message) { return; } - mMessageView.setAttachmentsEnabled(true); - mHandler.progress(false); - mHandler.networkError(); + mHandler.post(new Runnable() { + public void run() { + mMessageView.setAttachmentsEnabled(true); + removeDialog(R.id.dialog_attachment_progress); + mHandler.networkError(); + + } + }); } } From d354905f21fe0dc635a15d337e9417515b3d798f Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 20 Feb 2011 19:18:17 +0100 Subject: [PATCH 2/2] Cosmetic changes --- src/com/fsck/k9/activity/MessageView.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index 3c2ef4cb3..ae63d9a17 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -943,7 +943,8 @@ public class MessageView extends K9Activity implements OnClickListener { @Override protected Dialog onCreateDialog(final int id) { switch (id) { - case R.id.dialog_confirm_delete: return createConfirmDeleteDialog(id); + case R.id.dialog_confirm_delete: + return createConfirmDeleteDialog(id); case R.id.dialog_attachment_progress: ProgressDialog d = new ProgressDialog(this); d.setIndeterminate(true); @@ -1084,7 +1085,6 @@ public class MessageView extends K9Activity implements OnClickListener { return; } mHandler.post(new Runnable() { - @Override public void run() { mMessageView.setAttachmentsEnabled(false); showDialog(R.id.dialog_attachment_progress); @@ -1112,7 +1112,6 @@ public class MessageView extends K9Activity implements OnClickListener { } else { attachment.showFile(); } - } }); } @@ -1127,7 +1126,6 @@ public class MessageView extends K9Activity implements OnClickListener { mMessageView.setAttachmentsEnabled(true); removeDialog(R.id.dialog_attachment_progress); mHandler.networkError(); - } }); }