mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-03 15:45:10 +00:00
Make onProgressChanged updates time-based.
If used to update a notification, calling it too often would lag the UI
This commit is contained in:
@@ -203,16 +203,16 @@ public class LanLink extends BaseLink {
|
|||||||
int bytesRead;
|
int bytesRead;
|
||||||
long size = np.getPayloadSize();
|
long size = np.getPayloadSize();
|
||||||
long progress = 0;
|
long progress = 0;
|
||||||
long prevPercent = -1;
|
long timeSinceLastUpdate = -1;
|
||||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||||
//Log.e("ok",""+bytesRead);
|
//Log.e("ok",""+bytesRead);
|
||||||
progress += bytesRead;
|
progress += bytesRead;
|
||||||
outputStream.write(buffer, 0, bytesRead);
|
outputStream.write(buffer, 0, bytesRead);
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
long percent = ((100*progress) / size);
|
if (timeSinceLastUpdate + 500 < System.currentTimeMillis()) { //Report progress every half a second
|
||||||
if (percent != prevPercent) {
|
long percent = ((100 * progress) / size);
|
||||||
prevPercent = percent;
|
callback.onProgressChanged((int) percent);
|
||||||
callback.onProgressChanged((int)percent);
|
timeSinceLastUpdate = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user