deleteSongsFuture), new AsyncFunction<List<Object>, List<Song>>() {
@Override
public ListenableFuture<List<Song>> apply(List<Object> input) throws Exception {
postProgressEvent(4);
SyncPlan syncPlan = (SyncPlan) input.get(0);
List<SyncPlan.Item> downloadPlanItems = Lists.newArrayList();
for (SyncPlan.Item item : syncPlan.getItems()) {
if (item.getAction() == Action.DOWNLOAD) {
downloadPlanItems.add(item);
}
}
if (downloadPlanItems.size() == 0 || config.dryRun) {
return Futures.immediateFuture((List<Song>) new ArrayList<Song>());
} else {
return exec.submit(new DownloadSongsTask(bus,
client,
exec,
tempPath,
concurrentJobsSemaphore,
downloadPlanItems));
}
}
}
);
// Schedule write playlists task
final ListenableFuture<Void> generatePlaylistsFuture = Futures.transform(Futures.allAsList(
buildSyncPlanFuture,
downloadSongsFuture), new AsyncFunction<List<Object>, Void>() {
@Override
public ListenableFuture<Void> apply(List<Object> input) throws Exception {
postProgressEvent(5);
if (config.dryRun) {
return Futures.immediateFuture(null);
} else {
SyncPlan syncPlan = (SyncPlan) input.get(0);
List<Song> downloadedSongs = Lists.newArrayList((List<Song>) input.get(
1));
return exec.submit(new GeneratePlaylistsTask(bus,
config.syncDir,
syncPlan,
downloadedSongs));
}
}
}
);
// Schedule write cache file task
final ListenableFuture<Integer> writeCacheFileFuture = Futures.transform(Futures.allAsList(
buildSyncPlanFuture,
downloadSongsFuture), new AsyncFunction<List<Object>, Integer>() {
@Override
public ListenableFuture<Integer> apply(List<Object> input) throws Exception {
if (config.dryRun) {
return Futures.immediateFuture(null);
} else {
SyncPlan syncPlan = (SyncPlan) input.get(0);
List<Song> downloadedSongs = Lists.newArrayList((List<Song>) input.get(
1));
return exec.submit(new WriteCacheFileTask(config.syncDir,
syncPlan,