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 ExecutorService executor;
|
||||||
private DownloadNotification notification;
|
private DownloadNotification notification;
|
||||||
|
|
||||||
|
private static final Object lock = new Object();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
@ -88,13 +90,18 @@ public class DownloadService extends Service {
|
||||||
root = DocumentFile.fromFile(new File(location));
|
root = DocumentFile.fromFile(new File(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentFile artist = root.findFile(MusicUtil.ascii(song.artistName));
|
DocumentFile artist;
|
||||||
if (artist == null) {
|
DocumentFile album;
|
||||||
artist = root.createDirectory(MusicUtil.ascii(song.artistName));
|
|
||||||
}
|
synchronized (lock) {
|
||||||
DocumentFile album = artist.findFile(MusicUtil.ascii(song.albumName));
|
artist = root.findFile(MusicUtil.ascii(song.artistName));
|
||||||
if (album == null) {
|
if (artist == null) {
|
||||||
album = artist.createDirectory(MusicUtil.ascii(song.albumName));
|
artist = root.createDirectory(MusicUtil.ascii(song.artistName));
|
||||||
|
}
|
||||||
|
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;
|
String fileName = song.discNumber + "." + song.trackNumber + " - " + MusicUtil.ascii(song.title) + "." + song.container;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue