Time based attachment progress

pull/168/head
M66B 5 years ago
parent 48b22d51dd
commit 02ad6be8af

@ -89,6 +89,7 @@ public class MessageHelper {
static final int SMALL_MESSAGE_SIZE = 32 * 1024; // bytes static final int SMALL_MESSAGE_SIZE = 32 * 1024; // bytes
static final int DEFAULT_ATTACHMENT_DOWNLOAD_SIZE = 256 * 1024; // bytes static final int DEFAULT_ATTACHMENT_DOWNLOAD_SIZE = 256 * 1024; // bytes
static final long ATTACHMENT_PROGRESS_UPDATE = 1500L; // milliseconds
static void setSystemProperties(Context context) { static void setSystemProperties(Context context) {
System.setProperty("mail.mime.decodetext.strict", "false"); System.setProperty("mail.mime.decodetext.strict", "false");
@ -1297,7 +1298,7 @@ public class MessageHelper {
try (InputStream is = apart.part.getInputStream()) { try (InputStream is = apart.part.getInputStream()) {
long size = 0; long size = 0;
long total = apart.part.getSize(); long total = apart.part.getSize();
int lastprogress = 0; long lastprogress = System.currentTimeMillis();
try (OutputStream os = new FileOutputStream(file)) { try (OutputStream os = new FileOutputStream(file)) {
byte[] buffer = new byte[Helper.BUFFER_SIZE]; byte[] buffer = new byte[Helper.BUFFER_SIZE];
@ -1307,10 +1308,10 @@ public class MessageHelper {
// Update progress // Update progress
if (total > 0) { if (total > 0) {
int progress = (int) (size * 100 / total / 20 * 20); long now = System.currentTimeMillis();
if (progress != lastprogress) { if (now - lastprogress > ATTACHMENT_PROGRESS_UPDATE) {
lastprogress = progress; lastprogress = now;
db.attachment().setProgress(local.id, progress); db.attachment().setProgress(local.id, (int) (size * 100 / total));
} }
} }
} }

Loading…
Cancel
Save