diff --git a/app/src/main/java/com/dkanada/gramophone/service/DownloadService.java b/app/src/main/java/com/dkanada/gramophone/service/DownloadService.java index 06817676..e34185f7 100644 --- a/app/src/main/java/com/dkanada/gramophone/service/DownloadService.java +++ b/app/src/main/java/com/dkanada/gramophone/service/DownloadService.java @@ -48,6 +48,7 @@ public class DownloadService extends Service { List songs = intent.getParcelableArrayListExtra(EXTRA_SONGS); for (Song song : songs) { download(song); + notification.start(song); } return super.onStartCommand(intent, flags, startId); @@ -58,6 +59,7 @@ public class DownloadService extends Service { return null; } + @SuppressWarnings("ConstantConditions") public void download(Song song) { executor.execute(() -> { try { @@ -81,10 +83,10 @@ public class DownloadService extends Service { byte[] data = new byte[1048576]; int count; - notification.start(song, connection.getContentLength()); + notification.update(0, connection.getContentLength()); while ((count = input.read(data)) != -1) { output.write(data, 0, count); - notification.update(count); + notification.update(count, 0); } input.close(); diff --git a/app/src/main/java/com/dkanada/gramophone/service/notifications/DownloadNotification.java b/app/src/main/java/com/dkanada/gramophone/service/notifications/DownloadNotification.java index 145cfbfb..62e762ac 100644 --- a/app/src/main/java/com/dkanada/gramophone/service/notifications/DownloadNotification.java +++ b/app/src/main/java/com/dkanada/gramophone/service/notifications/DownloadNotification.java @@ -39,18 +39,17 @@ public class DownloadNotification { this.songs = new ArrayList<>(); } - public synchronized void start(Song song, int maximum) { + public synchronized void start(Song song) { this.songs.add(song); - this.maximum += maximum; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createNotificationChannel(); } } - public synchronized void update(int current) { + public synchronized void update(int current, int maximum) { this.current += current; + this.maximum += maximum; Intent action = new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent clickIntent = PendingIntent.getActivity(context, 0, action, 0); @@ -64,7 +63,7 @@ public class DownloadNotification { .setSmallIcon(R.drawable.ic_notification) .setContentIntent(clickIntent) .setContentTitle(String.format(context.getString(R.string.downloading_x_songs), songs.size())) - .setProgress(maximum, this.current, false) + .setProgress(this.maximum, this.current, false) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setStyle(style) .setShowWhen(false);