Synchronize writing of downloads to avoid numbered folders like 'AJR (1)'.
This commit is contained in:
parent
3b54d1c917
commit
728c6068cd
1 changed files with 14 additions and 7 deletions
|
|
@ -36,6 +36,8 @@ public class DownloadService extends Service {
|
|||
private ExecutorService executor;
|
||||
private DownloadNotification notification;
|
||||
|
||||
private static final Object lock = new Object();
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
|
@ -88,14 +90,19 @@ public class DownloadService extends Service {
|
|||
root = DocumentFile.fromFile(new File(location));
|
||||
}
|
||||
|
||||
DocumentFile artist = root.findFile(MusicUtil.ascii(song.artistName));
|
||||
DocumentFile artist;
|
||||
DocumentFile album;
|
||||
|
||||
synchronized (lock) {
|
||||
artist = root.findFile(MusicUtil.ascii(song.artistName));
|
||||
if (artist == null) {
|
||||
artist = root.createDirectory(MusicUtil.ascii(song.artistName));
|
||||
}
|
||||
DocumentFile album = artist.findFile(MusicUtil.ascii(song.albumName));
|
||||
album = artist.findFile(MusicUtil.ascii(song.albumName));
|
||||
if (album == null) {
|
||||
album = artist.createDirectory(MusicUtil.ascii(song.albumName));
|
||||
}
|
||||
}
|
||||
|
||||
String fileName = song.discNumber + "." + song.trackNumber + " - " + MusicUtil.ascii(song.title) + "." + song.container;
|
||||
DocumentFile audio = album.createFile("audio/" + song.container, fileName);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue