From 48758cdec5b7b42e02afc25bea13fe00c3c5e66b Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 11 May 2016 16:10:53 +0200 Subject: update progress handling in PgpDecryptVerifyOperation - less progress messages overall - report progress again based on input stream position, if filesize is known - limit progress messages to one every 200ms while decrypting - also fixed a bug in DecryptListFragment, the recycler view now reuses old views as intended instead of crossfading all the time. --- .../keychain/pgp/PgpDecryptVerifyOperation.java | 64 +++++++++------------- .../keychain/ui/DecryptListFragment.java | 7 ++- .../keychain/util/InputData.java | 2 + OpenKeychain/src/main/res/values/strings.xml | 3 +- 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java index a27e4a8d5..e0d71bd1e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java @@ -84,6 +84,8 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; public class PgpDecryptVerifyOperation extends BaseOperation { + public static final int PROGRESS_STRIDE_MILLISECONDS = 200; + public PgpDecryptVerifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { super(context, providerHelper, progressable); } @@ -153,10 +155,10 @@ public class PgpDecryptVerifyOperation extends BaseOperation 0; int length; byte[] buffer = new byte[8192]; byte[] firstBytes = new byte[48]; CharsetVerifier charsetVerifier = new CharsetVerifier(buffer, mimeType, charset); + updateProgress(R.string.progress_decrypting, 1, 100); + + long nextProgressTime = 0L; + int lastReportedProgress = 1; while ((length = dataIn.read(buffer)) > 0) { // Log.d(Constants.TAG, "read bytes: " + length); if (out != null) { @@ -467,14 +465,17 @@ public class PgpDecryptVerifyOperation extends BaseOperation 0) { - long progress = 100 * alreadyWritten / wholeSize; + if (sizeIsKnown && nextProgressTime < System.currentTimeMillis()) { + long progress = 100 * inputData.getStreamPosition() / wholeSize; // stop at 100% for wrong file sizes... if (progress > 100) { progress = 100; } - progressScaler.setProgress((int) progress, 100); + if (progress > lastReportedProgress) { + updateProgress((int) progress, 100); + lastReportedProgress = (int) progress; + nextProgressTime = System.currentTimeMillis() + PROGRESS_STRIDE_MILLISECONDS; + } } } @@ -490,7 +491,8 @@ public class PgpDecryptVerifyOperation extends BaseOperation"extracting key…" "preparing streams…" "encrypting data…" - "decrypting data…" + "Starting decryption…" + "Decrypting data…" "preparing signature…" processing signature… "generating signature…" -- cgit v1.2.3