use of com.bumptech.glide.RequestManager in project Shuttle by timusus.
the class AlbumArtistFragment method refreshAdapterItems.
void refreshAdapterItems(boolean force) {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
int artistDisplayType = SettingsManager.getInstance().getArtistDisplayType();
boolean ascending = SortManager.getInstance().getArtistsAscending();
disposable = DataManager.getInstance().getAlbumArtistsRelay().skipWhile(albumArtists -> !force && adapter.items.size() == albumArtists.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(albumArtists -> {
// Sort
SortManager.getInstance().sortAlbumArtists(albumArtists);
// Reverse if required
if (!ascending) {
Collections.reverse(albumArtists);
}
return Observable.fromIterable(albumArtists).map(albumArtist -> {
// Look for an existing AlbumArtistView wrapping the song, we'll reuse it if it exists.
AlbumArtistView albumArtistView = (AlbumArtistView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumArtistView && (((AlbumArtistView) viewModel).albumArtist.equals(albumArtist))).findFirst().orElse(null);
if (albumArtistView == null) {
albumArtistView = new AlbumArtistView(albumArtist, artistDisplayType, requestManager);
albumArtistView.setClickListener(this);
}
return (ViewModel) albumArtistView;
}).toList();
}).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
if (items.isEmpty()) {
adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_artists)));
} else {
adapter.setItems(items);
}
// Move the RV back to the top if we've had a sort order change.
if (sortOrderChanged) {
recyclerView.scrollToPosition(0);
}
sortOrderChanged = false;
});
}
});
}
use of com.bumptech.glide.RequestManager in project Shuttle by timusus.
the class QueueFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_queue, container, false);
unbinder = ButterKnife.bind(this, rootView);
toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());
toolbar.inflateMenu(R.menu.menu_queue);
SubMenu sub = toolbar.getMenu().addSubMenu(0, MusicUtils.Defs.ADD_TO_PLAYLIST, 1, R.string.save_as_playlist);
disposables.add(PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe());
toolbar.setOnMenuItemClickListener(toolbarListener);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setRecyclerListener(new RecyclerListener());
recyclerView.setAdapter(adapter);
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback((fromPosition, toPosition) -> adapter.moveItem(fromPosition, toPosition), MusicUtils::moveQueueItem, () -> {
// Nothing to do
}));
itemTouchHelper.attachToRecyclerView(recyclerView);
disposables.add(Aesthetic.get(getContext()).colorPrimary().subscribe(color -> {
boolean isLight = Util.isColorLight(color);
lineOne.setTextColor(isLight ? Color.BLACK : Color.WHITE);
lineTwo.setTextColor(isLight ? Color.BLACK : Color.WHITE);
}));
// In landscape, we need to adjust the status bar's translation depending on the slide offset of the sheet
if (ShuttleUtils.isLandscape()) {
statusBarView.setTranslationY(ResourceUtils.toPixels(16));
disposables.add(multiSheetSlideEventRelay.getEvents().filter(multiSheetEvent -> multiSheetEvent.sheet == MultiSheetView.Sheet.SECOND).filter(multiSheetEvent -> multiSheetEvent.slideOffset >= 0).subscribe(multiSheetEvent -> {
statusBarView.setTranslationY((1 - multiSheetEvent.slideOffset) * ResourceUtils.toPixels(16));
}));
}
setupContextualToolbar();
queuePresenter = new QueuePresenter(requestManager, cabHelper);
return rootView;
}
use of com.bumptech.glide.RequestManager in project Shuttle by timusus.
the class SuggestedFragment method getMostPlayedViewModels.
Observable<List<ViewModel>> getMostPlayedViewModels() {
return Playlist.mostPlayedPlaylist.getSongsObservable().map(songs -> {
if (!songs.isEmpty()) {
List<ViewModel> viewModels = new ArrayList<>();
SuggestedHeader mostPlayedHeader = new SuggestedHeader(getString(R.string.mostplayed), getString(R.string.suggested_most_played_songs_subtitle), Playlist.mostPlayedPlaylist);
SuggestedHeaderView mostPlayedHeaderView = new SuggestedHeaderView(mostPlayedHeader);
mostPlayedHeaderView.setClickListener(this);
viewModels.add(mostPlayedHeaderView);
viewModels.add(mostPlayedRecyclerView);
Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(b.playCount, a.playCount));
SongClickListener songClickListener = new SongClickListener(songs);
mostPlayedRecyclerView.viewModelAdapter.setItems(Stream.of(songs).map(song -> {
SuggestedSongView suggestedSongView = new SuggestedSongView(song, requestManager);
suggestedSongView.setClickListener(songClickListener);
return (ViewModel) suggestedSongView;
}).limit(20).toList());
return viewModels;
} else {
return Collections.emptyList();
}
});
}
use of com.bumptech.glide.RequestManager in project Shuttle by timusus.
the class SuggestedFragment method getRecentlyPlayedViewModels.
Observable<List<ViewModel>> getRecentlyPlayedViewModels() {
return Playlist.recentlyPlayedPlaylist.getSongsObservable().flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMapSingle(albums -> Observable.fromIterable(albums).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).flatMapSingle(album -> album.getSongsSingle().map(songs -> {
album.numSongs = songs.size();
return album;
}).filter(a -> a.numSongs > 0).toSingle()).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).take(6).toList()).map(albums -> {
if (!albums.isEmpty()) {
List<ViewModel> viewModels = new ArrayList<>();
SuggestedHeader recentlyPlayedHeader = new SuggestedHeader(getString(R.string.suggested_recent_title), getString(R.string.suggested_recent_subtitle), Playlist.recentlyPlayedPlaylist);
SuggestedHeaderView recentlyPlayedHeaderView = new SuggestedHeaderView(recentlyPlayedHeader);
recentlyPlayedHeaderView.setClickListener(this);
viewModels.add(recentlyPlayedHeaderView);
viewModels.addAll(Stream.of(albums).map(album -> {
AlbumView albumView = new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager);
albumView.setClickListener(this);
return albumView;
}).toList());
return viewModels;
} else {
return Collections.emptyList();
}
});
}
use of com.bumptech.glide.RequestManager in project Shuttle by timusus.
the class QueuePresenter method loadData.
private void loadData() {
QueueView queueView = getView();
if (queueView != null) {
List<ViewModel> data = Stream.of(MusicUtils.getQueue()).map(song -> {
SongView songView = new SongView(song, requestManager) {
@Override
public boolean equals(Object o) {
// are considered to be the same. We lose some RV optimisations here, but at least we don't crash.
return false;
}
};
songView.setClickListener(clickListener);
songView.showAlbumArt(true);
songView.setEditable(true);
return songView;
}).collect(Collectors.toList());
queueView.loadData(data, MusicUtils.getQueuePosition());
}
}
Aggregations