use of com.simplecity.amp_library.ui.modelviews.AlbumArtistView 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.ui.modelviews.AlbumArtistView 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