Fixed bulk live download when user chooses to sync starred tracks

This commit is contained in:
antonio 2023-03-12 17:59:12 +01:00
parent 3f6f3ab06a
commit da7030bee1
7 changed files with 60 additions and 14 deletions

View file

@ -79,7 +79,7 @@ public class DownloaderManager {
public void download(MediaItem mediaItem, com.cappielloantonio.play.model.Download download) {
DownloadService.sendAddDownload(context, DownloaderService.class, buildDownloadRequest(mediaItem), false);
downloadDatabase(download);
insertDatabase(download);
}
public void download(List<MediaItem> mediaItems, List<com.cappielloantonio.play.model.Download> downloads) {
@ -90,7 +90,6 @@ public class DownloaderManager {
public void remove(MediaItem mediaItem, com.cappielloantonio.play.model.Download download) {
DownloadService.sendRemoveDownload(context, DownloaderService.class, buildDownloadRequest(mediaItem).id, false);
removeDatabase(download);
}
public void remove(List<MediaItem> mediaItems, List<com.cappielloantonio.play.model.Download> downloads) {
@ -114,11 +113,15 @@ public class DownloaderManager {
return new DownloadRepository();
}
private static void downloadDatabase(com.cappielloantonio.play.model.Download download) {
public static void insertDatabase(com.cappielloantonio.play.model.Download download) {
getDownloadRepository().insert(download);
}
private static void removeDatabase(com.cappielloantonio.play.model.Download download) {
getDownloadRepository().delete(download);
public static void deleteDatabase(String id) {
getDownloadRepository().delete(id);
}
public static void updateDatabase(String id) {
getDownloadRepository().update(id);
}
}

View file

@ -69,6 +69,7 @@ public class DownloaderService extends androidx.media3.exoplayer.offline.Downloa
if (download.state == Download.STATE_COMPLETED) {
notification = notificationHelper.buildDownloadCompletedNotification(context, R.drawable.ic_check_circle, null, Util.fromUtf8Bytes(download.request.data));
DownloaderManager.updateDatabase(download.request.id);
} else if (download.state == Download.STATE_FAILED) {
notification = notificationHelper.buildDownloadFailedNotification(context, R.drawable.ic_error, null, Util.fromUtf8Bytes(download.request.data));
} else {
@ -77,5 +78,10 @@ public class DownloaderService extends androidx.media3.exoplayer.offline.Downloa
NotificationUtil.setNotification(context, nextNotificationId++, notification);
}
@Override
public void onDownloadRemoved(@NonNull DownloadManager downloadManager, Download download) {
DownloaderManager.deleteDatabase(download.request.id);
}
}
}