From ee65e892300d6aa7391239215871dbc27adf0b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Matuszewski?= Date: Wed, 30 Oct 2019 23:17:09 +0100 Subject: [PATCH] limit amount of notification thumbnail updates limits amount of calls to updateNotificationThumbnail in background player --- .../org/schabi/newpipe/player/BackgroundPlayer.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index ab07ded22..90af3c29f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -95,6 +95,9 @@ public final class BackgroundPlayer extends Service { private boolean shouldUpdateOnProgress; + private static final int NOTIFICATION_UPDATES_BEFORE_RESET = 60; + private int timesNotificationUpdated; + /*////////////////////////////////////////////////////////////////////////// // Service's LifeCycle //////////////////////////////////////////////////////////////////////////*/ @@ -180,6 +183,7 @@ public final class BackgroundPlayer extends Service { private void resetNotification() { notBuilder = createNotification(); + timesNotificationUpdated = 0; } private NotificationCompat.Builder createNotification() { @@ -252,6 +256,7 @@ public final class BackgroundPlayer extends Service { if (bigNotRemoteView != null) bigNotRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId); } notificationManager.notify(NOTIFICATION_ID, notBuilder.build()); + timesNotificationUpdated++; } /*////////////////////////////////////////////////////////////////////////// @@ -351,8 +356,10 @@ public final class BackgroundPlayer extends Service { updateProgress(currentProgress, duration, bufferPercent); if (!shouldUpdateOnProgress) return; - resetNotification(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O /*Oreo*/) updateNotificationThumbnail(); + if (timesNotificationUpdated > NOTIFICATION_UPDATES_BEFORE_RESET) { + resetNotification(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O /*Oreo*/) updateNotificationThumbnail(); + } if (bigNotRemoteView != null) { if(cachedDuration != duration) { cachedDuration = duration;