use of com.annimon.stream.function.Predicate in project Shuttle by timusus.
the class MusicService method openFile.
/**
* Opens a file and prepares it for playback
*
* @param path The path of the file to open
*/
public void openFile(String path, @Nullable Action0 completion) {
synchronized (this) {
if (path == null) {
return;
}
Uri uri = Uri.parse(path);
long id = -1;
try {
id = Long.valueOf(uri.getLastPathSegment());
} catch (NumberFormatException ignored) {
}
Predicate<Song> predicate;
long finalId = id;
if (finalId != -1 && (path.startsWith(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.toString()) || path.startsWith(MediaStore.Files.getContentUri("external").toString()))) {
predicate = song -> song.id == finalId;
} else {
if (uri != null && path.startsWith("content://")) {
path = uri.getPath();
}
String finalPath = path;
predicate = song -> song.path.contains(finalPath);
}
DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(predicate).collect(Collectors.toList())).subscribe(songs -> {
if (!songs.isEmpty()) {
currentSong = songs.get(0);
open(currentSong);
if (completion != null) {
completion.call();
}
}
});
}
}
Aggregations