mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Fixed bulk live download when user chooses to sync starred tracks
This commit is contained in:
parent
3f6f3ab06a
commit
da7030bee1
7 changed files with 60 additions and 14 deletions
|
|
@ -20,9 +20,9 @@ import com.cappielloantonio.play.model.RecentSearch;
|
||||||
import com.cappielloantonio.play.model.Server;
|
import com.cappielloantonio.play.model.Server;
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
version = 61,
|
version = 62,
|
||||||
entities = {Queue.class, Server.class, RecentSearch.class, Download.class, Chronology.class},
|
entities = {Queue.class, Server.class, RecentSearch.class, Download.class, Chronology.class},
|
||||||
autoMigrations = {@AutoMigration(from = 60, to = 61)}
|
autoMigrations = {@AutoMigration(from = 61, to = 62)}
|
||||||
)
|
)
|
||||||
@TypeConverters({DateConverters.class})
|
@TypeConverters({DateConverters.class})
|
||||||
public abstract class AppDatabase extends RoomDatabase {
|
public abstract class AppDatabase extends RoomDatabase {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public interface DownloadDao {
|
public interface DownloadDao {
|
||||||
@Query("SELECT * FROM download ORDER BY album, track ASC")
|
@Query("SELECT * FROM download WHERE download_state = 1 ORDER BY artist, album, track ASC")
|
||||||
LiveData<List<Download>> getAll();
|
LiveData<List<Download>> getAll();
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
|
@ -21,6 +21,9 @@ public interface DownloadDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
void insertAll(List<Download> downloads);
|
void insertAll(List<Download> downloads);
|
||||||
|
|
||||||
|
@Query("UPDATE download SET download_state = 1 WHERE id = :id")
|
||||||
|
void update(String id);
|
||||||
|
|
||||||
@Query("DELETE FROM download WHERE id = :id")
|
@Query("DELETE FROM download WHERE id = :id")
|
||||||
void delete(String id);
|
void delete(String id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@ class Download(@PrimaryKey override val id: String) : Child(id) {
|
||||||
@ColumnInfo(name = "playlist_name")
|
@ColumnInfo(name = "playlist_name")
|
||||||
var playlistName: String? = null
|
var playlistName: String? = null
|
||||||
|
|
||||||
|
@ColumnInfo(name = "download_state", defaultValue = "1")
|
||||||
|
var downloadState: Int = 0;
|
||||||
|
|
||||||
constructor(child: Child) : this(child.id) {
|
constructor(child: Child) : this(child.id) {
|
||||||
parentId = child.parentId
|
parentId = child.parentId
|
||||||
isDir = child.isDir
|
isDir = child.isDir
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,27 @@ public class DownloadRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update(String id) {
|
||||||
|
UpdateThreadSafe update = new UpdateThreadSafe(downloadDao, id);
|
||||||
|
Thread thread = new Thread(update);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class UpdateThreadSafe implements Runnable {
|
||||||
|
private final DownloadDao downloadDao;
|
||||||
|
private final String id;
|
||||||
|
|
||||||
|
public UpdateThreadSafe(DownloadDao downloadDao, String id) {
|
||||||
|
this.downloadDao = downloadDao;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
downloadDao.update(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void insertAll(List<Download> downloads) {
|
public void insertAll(List<Download> downloads) {
|
||||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(downloadDao, downloads);
|
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(downloadDao, downloads);
|
||||||
Thread thread = new Thread(insertAll);
|
Thread thread = new Thread(insertAll);
|
||||||
|
|
@ -76,24 +97,24 @@ public class DownloadRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Download download) {
|
public void delete(String id) {
|
||||||
DeleteThreadSafe delete = new DeleteThreadSafe(downloadDao, download);
|
DeleteThreadSafe delete = new DeleteThreadSafe(downloadDao, id);
|
||||||
Thread thread = new Thread(delete);
|
Thread thread = new Thread(delete);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DeleteThreadSafe implements Runnable {
|
private static class DeleteThreadSafe implements Runnable {
|
||||||
private final DownloadDao downloadDao;
|
private final DownloadDao downloadDao;
|
||||||
private final Download download;
|
private final String id;
|
||||||
|
|
||||||
public DeleteThreadSafe(DownloadDao downloadDao, Download download) {
|
public DeleteThreadSafe(DownloadDao downloadDao, String id) {
|
||||||
this.downloadDao = downloadDao;
|
this.downloadDao = downloadDao;
|
||||||
this.download = download;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
downloadDao.delete(download.getId());
|
downloadDao.delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public class DownloaderManager {
|
||||||
|
|
||||||
public void download(MediaItem mediaItem, com.cappielloantonio.play.model.Download download) {
|
public void download(MediaItem mediaItem, com.cappielloantonio.play.model.Download download) {
|
||||||
DownloadService.sendAddDownload(context, DownloaderService.class, buildDownloadRequest(mediaItem), false);
|
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) {
|
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) {
|
public void remove(MediaItem mediaItem, com.cappielloantonio.play.model.Download download) {
|
||||||
DownloadService.sendRemoveDownload(context, DownloaderService.class, buildDownloadRequest(mediaItem).id, false);
|
DownloadService.sendRemoveDownload(context, DownloaderService.class, buildDownloadRequest(mediaItem).id, false);
|
||||||
removeDatabase(download);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(List<MediaItem> mediaItems, List<com.cappielloantonio.play.model.Download> downloads) {
|
public void remove(List<MediaItem> mediaItems, List<com.cappielloantonio.play.model.Download> downloads) {
|
||||||
|
|
@ -114,11 +113,15 @@ public class DownloaderManager {
|
||||||
return new DownloadRepository();
|
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);
|
getDownloadRepository().insert(download);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void removeDatabase(com.cappielloantonio.play.model.Download download) {
|
public static void deleteDatabase(String id) {
|
||||||
getDownloadRepository().delete(download);
|
getDownloadRepository().delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateDatabase(String id) {
|
||||||
|
getDownloadRepository().update(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ public class DownloaderService extends androidx.media3.exoplayer.offline.Downloa
|
||||||
|
|
||||||
if (download.state == Download.STATE_COMPLETED) {
|
if (download.state == Download.STATE_COMPLETED) {
|
||||||
notification = notificationHelper.buildDownloadCompletedNotification(context, R.drawable.ic_check_circle, null, Util.fromUtf8Bytes(download.request.data));
|
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) {
|
} else if (download.state == Download.STATE_FAILED) {
|
||||||
notification = notificationHelper.buildDownloadFailedNotification(context, R.drawable.ic_error, null, Util.fromUtf8Bytes(download.request.data));
|
notification = notificationHelper.buildDownloadFailedNotification(context, R.drawable.ic_error, null, Util.fromUtf8Bytes(download.request.data));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -77,5 +78,10 @@ public class DownloaderService extends androidx.media3.exoplayer.offline.Downloa
|
||||||
|
|
||||||
NotificationUtil.setNotification(context, nextNotificationId++, notification);
|
NotificationUtil.setNotification(context, nextNotificationId++, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadRemoved(@NonNull DownloadManager downloadManager, Download download) {
|
||||||
|
DownloaderManager.deleteDatabase(download.request.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,16 @@ public class DownloadHorizontalAdapter extends RecyclerView.Adapter<DownloadHori
|
||||||
return songs.get(id);
|
return songs.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
ItemHorizontalDownloadBinding item;
|
ItemHorizontalDownloadBinding item;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue