Limit number of progress updates

This commit is contained in:
M66B 2019-06-07 12:19:13 +02:00
parent f77cf6c029
commit 72c7e3df08
2 changed files with 16 additions and 4 deletions

View File

@ -1800,6 +1800,7 @@ public class FragmentCompose extends FragmentBase {
}
long size = 0;
int lastProgress = 0;
try {
File file = attachment.getFile(context);
@ -1815,8 +1816,13 @@ public class FragmentCompose extends FragmentBase {
os.write(buffer, 0, len);
// Update progress
if (attachment.size != null && attachment.size > 0)
db.attachment().setProgress(attachment.id, (int) (size * 100 / attachment.size));
if (attachment.size != null && attachment.size > 0) {
int progress = (int) (size * 100 / attachment.size / 20 * 20);
if (progress != lastProgress) {
lastProgress = progress;
db.attachment().setProgress(attachment.id, progress);
}
}
}
if (image) {

View File

@ -908,6 +908,7 @@ public class MessageHelper {
try (InputStream is = apart.part.getInputStream()) {
long size = 0;
long total = apart.part.getSize();
int lastprogress = 0;
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
byte[] buffer = new byte[ATTACHMENT_BUFFER_SIZE];
@ -916,8 +917,13 @@ public class MessageHelper {
os.write(buffer, 0, len);
// Update progress
if (total > 0)
db.attachment().setProgress(id, (int) (size * 100 / total));
if (total > 0) {
int progress = (int) (size * 100 / total / 20 * 20);
if (progress != lastprogress) {
lastprogress = progress;
db.attachment().setProgress(id, progress);
}
}
}
}