use of com.simplecity.amp_library.model.Album in project Shuttle by timusus.
the class Operators method songsToAlbums.
public static List<Album> songsToAlbums(List<Song> songs) {
HashMap<Pair<Long, String>, Album> albumMap = new HashMap<>();
for (Song song : songs) {
//Create an album representing the album this song belongs to
Album album = song.getAlbum();
// We need to use the album id AND the albumArtistName as the key, to determine whether
// two albums are the same. This is because it's possible that the user doesn't have
// correct album tags for their songs. In that case, Android falls back to using the folder
// name for the album. So all songs with no album name, which share a folder will end up with
// the same album id. By using the albumArtistName in the key, we ensure that songs with the
// same album id but different albumArtistNames are not considered to be part of the same album.
Pair<Long, String> key = new Pair<>(album.id, album.albumArtistName);
//Now check if there's already an equivalent album in our albumMap
Album oldAlbum = albumMap.get(key);
if (oldAlbum != null) {
//Increment the number of songs.
oldAlbum.numSongs++;
//The number of discs is just the largest disc number for songs
oldAlbum.numDiscs = Math.max(song.discNumber, oldAlbum.numDiscs);
oldAlbum.songPlayCount += song.playCount;
//Add any new artists
Stream.of(album.artists).filter(artist -> !oldAlbum.artists.contains(artist)).forEach(artist -> oldAlbum.artists.add(artist));
//Add new paths
Stream.of(album.paths).filter(path -> !oldAlbum.paths.contains(path)).forEach(path -> oldAlbum.paths.add(path));
} else {
//Couldn't find an existing entry for this album. Add a new one.
albumMap.put(key, album);
}
}
return new ArrayList<>(albumMap.values());
}
use of com.simplecity.amp_library.model.Album in project Shuttle by timusus.
the class Operators method albumsToAlbumArtists.
public static List<AlbumArtist> albumsToAlbumArtists(List<Album> albums) {
HashMap<String, AlbumArtist> albumArtistMap = new HashMap<>();
for (Album album : albums) {
//Create an album-artist representing the album-artist this album belongs to
AlbumArtist albumArtist = album.getAlbumArtist();
//Check if there's already an equivalent album-artist in our albumArtistMap
AlbumArtist oldAlbumArtist = albumArtistMap.get(albumArtist.name);
if (oldAlbumArtist != null) {
//Add this album to the album artist's albums
if (!oldAlbumArtist.albums.contains(album)) {
oldAlbumArtist.albums.add(album);
}
} else {
albumArtistMap.put(albumArtist.name, albumArtist);
}
}
return new ArrayList<>(albumArtistMap.values());
}
use of com.simplecity.amp_library.model.Album in project Shuttle by timusus.
the class SearchActivity method refreshAdapterItems.
private void refreshAdapterItems() {
subscriptions.add(DataManager.getInstance().getSongsRelay().first().map(songs -> {
char[] prefix = filterString.toUpperCase().toCharArray();
List<Album> albums = Operators.songsToAlbums(songs);
Collections.sort(albums, Album::compareTo);
List<AlbumArtist> albumArtists = Operators.albumsToAlbumArtists(albums);
Collections.sort(albumArtists, AlbumArtist::compareTo);
List<AdaptableItem> adaptableItems = Stream.of(albumArtists).filter(album -> album.name != null).map(albumArtist -> new SearchUtils.JaroWinklerObject<>(albumArtist, filterString, albumArtist.name)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).map(albumArtist -> {
AlbumArtistView albumArtistView = new AlbumArtistView(albumArtist, ViewType.ARTIST_LIST, requestManager);
albumArtistView.setPrefix(prefixHighlighter, prefix);
return (AdaptableItem) albumArtistView;
}).collect(Collectors.toList());
if (!adaptableItems.isEmpty()) {
adaptableItems.add(0, artistsHeader);
}
List<AdaptableItem> albumItems = Stream.of(albums).filter(album -> album.name != null).map(album -> new SearchUtils.JaroWinklerObject<>(album, filterString, album.name, album.albumArtistName)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).map(album -> {
AlbumView albumView = new AlbumView(album, ViewType.ALBUM_LIST, requestManager);
albumView.setPrefix(prefixHighlighter, prefix);
return albumView;
}).collect(Collectors.toList());
if (!albumItems.isEmpty()) {
albumItems.add(0, albumsHeader);
}
adaptableItems.addAll(albumItems);
songs = Stream.of(songs).filter(song -> song.name != null).map(song -> new SearchUtils.JaroWinklerObject<>(song, filterString, song.name, song.albumName, song.artistName, song.albumArtistName)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).collect(Collectors.toList());
List<AdaptableItem> songItems = Stream.of(songs).map(song -> {
SongView songView = new SongView(song, dummySelector, requestManager);
songView.setPrefix(prefixHighlighter, prefix);
return songView;
}).collect(Collectors.toList());
if (!songItems.isEmpty()) {
songItems.add(0, songsHeader);
}
adaptableItems.addAll(songItems);
return adaptableItems;
}).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
if (setItemsSubscription != null) {
setItemsSubscription.unsubscribe();
}
setItemsSubscription = adapter.setItems(adaptableItems);
recyclerView.scrollToPosition(0);
}));
}
use of com.simplecity.amp_library.model.Album in project Shuttle by timusus.
the class SearchActivity method onItemClick.
@Override
public void onItemClick(View v, int position, Object item) {
if (item instanceof AlbumArtist || item instanceof Album) {
Intent intent = new Intent();
intent.putExtra(MainActivity.ARG_MODEL, (Serializable) item);
setResult(Activity.RESULT_OK, intent);
finish();
} else if (item instanceof Song) {
List<Song> songs = new ArrayList<>();
int curPos = 0;
for (int i = 0, count = adapter.getItemCount(); i < count; i++) {
Object aModel = adapter.getItem(i);
if (aModel != null && aModel instanceof Song) {
songs.add((Song) aModel);
if (aModel.equals(item)) {
curPos = songs.size() - 1;
}
}
}
MusicUtils.playAll(songs, curPos, false, () -> {
final String message = getString(R.string.emptyplaylist);
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
});
finish();
}
}
use of com.simplecity.amp_library.model.Album in project Shuttle by timusus.
the class TaggerDialog method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Serializable model = getArguments().getSerializable(ARG_MODEL);
if (model instanceof AlbumArtist) {
albumArtist = (AlbumArtist) model;
originalSongPaths = Stream.of(albumArtist.albums).flatMap(value -> Stream.of(value.paths)).collect(Collectors.toList());
showAlbum = false;
showTrack = false;
} else if (model instanceof Album) {
album = (Album) model;
originalSongPaths = album.paths;
showTrack = false;
} else if (model instanceof Song) {
song = (Song) model;
originalSongPaths.add(song.path);
}
if (originalSongPaths == null || originalSongPaths.isEmpty()) {
dismiss();
//Todo: refine & extract
Toast.makeText(getContext(), R.string.tag_retrieve_error, Toast.LENGTH_LONG).show();
}
}
Aggregations