From dcb8587dec0bdd4869139bd952db23a01afab817 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 27 Aug 2017 23:44:32 +0200 Subject: [PATCH] Show progress based on time (after 500ms), not file size (#2706) --- .../fsck/k9/ui/crypto/MessageCryptoHelper.java | 6 +----- .../k9/ui/messageview/MessageViewFragment.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java index ee51ac5ad..dcc8c328e 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java @@ -58,7 +58,6 @@ public class MessageCryptoHelper { private static final int INVALID_OPENPGP_RESULT_CODE = -1; private static final MimeBodyPart NO_REPLACEMENT_PART = null; private static final int REQUEST_CODE_USER_INTERACTION = 124; - private static final int PROGRESS_SIZE_THRESHOLD = 4096; private final Context context; @@ -406,10 +405,7 @@ public class MessageCryptoHelper { throw new IllegalStateException("part to stream must be encrypted or inline!"); } if (body instanceof SizeAware) { - long bodySize = ((SizeAware) body).getSize(); - if (bodySize > PROGRESS_SIZE_THRESHOLD) { - return bodySize; - } + return ((SizeAware) body).getSize(); } return null; } diff --git a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java index cf69e17fb..900129431 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java @@ -17,6 +17,7 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Parcelable; +import android.os.SystemClock; import android.text.TextUtils; import android.view.ContextThemeWrapper; import android.view.KeyEvent; @@ -65,6 +66,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF public static final int REQUEST_MASK_LOADER_HELPER = (1 << 8); public static final int REQUEST_MASK_CRYPTO_PRESENTER = (1 << 9); + public static final int PROGRESS_THRESHOLD_MILLIS = 500 * 1000; + public static MessageViewFragment newInstance(MessageReference reference) { MessageViewFragment fragment = new MessageViewFragment(); @@ -85,6 +88,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF private Handler handler = new Handler(); private MessageLoaderHelper messageLoaderHelper; private MessageCryptoPresenter messageCryptoPresenter; + private Long showProgressThreshold; /** * Used to temporarily store the destination folder for refile operations if a confirmation @@ -741,26 +745,35 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF displayHeaderForLoadingMessage(message); mMessageView.setToLoadingState(); + showProgressThreshold = null; } @Override public void onMessageDataLoadFailed() { Toast.makeText(getActivity(), R.string.status_loading_error, Toast.LENGTH_LONG).show(); + showProgressThreshold = null; } @Override public void onMessageViewInfoLoadFinished(MessageViewInfo messageViewInfo) { showMessage(messageViewInfo); + showProgressThreshold = null; } @Override public void onMessageViewInfoLoadFailed(MessageViewInfo messageViewInfo) { showMessage(messageViewInfo); + showProgressThreshold = null; } @Override public void setLoadingProgress(int current, int max) { - mMessageView.setLoadingProgress(current, max); + if (showProgressThreshold == null) { + showProgressThreshold = SystemClock.elapsedRealtime() + PROGRESS_THRESHOLD_MILLIS; + } else if (showProgressThreshold == 0L || SystemClock.elapsedRealtime() > showProgressThreshold) { + showProgressThreshold = 0L; + mMessageView.setLoadingProgress(current, max); + } } @Override @@ -788,6 +801,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF @Override public void startIntentSenderForMessageLoaderHelper(IntentSender si, int requestCode, Intent fillIntent, int flagsMask, int flagValues, int extraFlags) { + showProgressThreshold = null; try { requestCode |= REQUEST_MASK_LOADER_HELPER; getActivity().startIntentSenderForResult(