[Android] Add a progress bar to the ML scan notification

Nicolas Pomepuy git at videolan.org
Tue Aug 30 06:12:47 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug 30 08:07:23 2022 +0200| [4b1b36f6674fc78bd01cf06f01610ff4585f3580] | committer: Nicolas Pomepuy

Add a progress bar to the ML scan notification

> https://code.videolan.org/videolan/vlc-android/commit/4b1b36f6674fc78bd01cf06f01610ff4585f3580
---

 application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt   | 4 ++--
 .../src/org/videolan/vlc/gui/helpers/NotificationHelper.kt            | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 4065f9248..6d6a6d892 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -199,7 +199,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
 
     @TargetApi(Build.VERSION_CODES.O)
     private fun forceForeground() {
-        val notification = NotificationHelper.createScanNotification(applicationContext, getString(R.string.loading_medialibrary), scanPaused)
+        val notification = NotificationHelper.createScanNotification(applicationContext, getString(R.string.loading_medialibrary), scanPaused, -1, -1)
         startForeground(43, notification)
     }
 
@@ -372,7 +372,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
             if (!isActive) return at withContext ""
             if (lastNotificationTime != -1L) {
                 try {
-                    val notification = NotificationHelper.createScanNotification(applicationContext, progressText, scanPaused)
+                    val notification = NotificationHelper.createScanNotification(applicationContext, progressText, scanPaused, scheduled, done)
                     startForeground(43, notification)
                 } catch (ignored: IllegalArgumentException) {}
                 progressText
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
index 488190f78..81f0bbbba 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt
@@ -146,13 +146,14 @@ object NotificationHelper {
         return PendingIntent.getBroadcast(ctx, actionId.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
     }
 
-    fun createScanNotification(ctx: Context, progressText: String, paused: Boolean): Notification {
+    fun createScanNotification(ctx: Context, progressText: String, paused: Boolean, max:Int, progress: Int): Notification {
         val intent = Intent(Intent.ACTION_VIEW).setClassName(ctx, START_ACTIVITY)
         val scanCompatBuilder = NotificationCompat.Builder(ctx, MEDIALIBRRARY_CHANNEL_ID)
                 .setContentIntent(PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
                 .setSmallIcon(R.drawable.ic_notif_scan)
                 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                 .setContentTitle(ctx.getString(R.string.ml_scanning))
+                .setProgress(max, progress, max < 1 || progress < 1)
                 .setAutoCancel(false)
                 .setCategory(NotificationCompat.CATEGORY_PROGRESS)
                 .setOngoing(true)



More information about the Android mailing list