From b99ee88c974aaa23508196e7f0052ba218021b45 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 10 Nov 2020 21:44:31 +0900 Subject: [PATCH] Fix download progress notification not auto dismissed sometimes --- .../java/awais/instagrabber/workers/DownloadWorker.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/awais/instagrabber/workers/DownloadWorker.java b/app/src/main/java/awais/instagrabber/workers/DownloadWorker.java index 542c3408..048cd6de 100644 --- a/app/src/main/java/awais/instagrabber/workers/DownloadWorker.java +++ b/app/src/main/java/awais/instagrabber/workers/DownloadWorker.java @@ -200,6 +200,10 @@ public class DownloadWorker extends Worker { final float percent) { final Notification notification = createProgressNotification(position, total, percent); try { + if (notification == null) { + notificationManager.cancel(notificationId); + return; + } setForegroundAsync(new ForegroundInfo(notificationId, notification)).get(); } catch (ExecutionException | InterruptedException e) { Log.e(TAG, "updateDownloadProgress", e); @@ -216,6 +220,9 @@ public class DownloadWorker extends Worker { } else { totalPercent = (int) ((100f * (position - 1) / total) + (1f / total) * (percent)); } + if (totalPercent == 100) { + return null; + } // Log.d(TAG, "createProgressNotification: position: " + position // + ", total: " + total // + ", percent: " + percent