use of com.simplecity.amp_library.model.AlbumArtist 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.AlbumArtist 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.AlbumArtist 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.AlbumArtist 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();
}
}
use of com.simplecity.amp_library.model.AlbumArtist in project Shuttle by timusus.
the class AlbumArtistAdapter method getSectionName.
@NonNull
@Override
public String getSectionName(int position) {
if (!(items.get(position) instanceof AlbumArtistView)) {
return "";
}
int sortOrder = SortManager.getInstance().getArtistsSortOrder();
AlbumArtist albumArtist = ((AlbumArtistView) items.get(position)).albumArtist;
String string = null;
switch(sortOrder) {
case SortManager.ArtistSort.DEFAULT:
string = StringUtils.keyFor(albumArtist.name);
break;
case SortManager.AlbumSort.ARTIST_NAME:
string = albumArtist.name;
break;
}
if (!TextUtils.isEmpty(string)) {
string = string.substring(0, 1).toUpperCase();
} else {
string = " ";
}
return string;
}
Aggregations