use of com.bumptech.glide.RequestManager in project glide by bumptech.
the class HorizontalGalleryFragment method onLoadFinished.
@Override
public void onLoadFinished(Loader<List<MediaStoreData>> loader, List<MediaStoreData> mediaStoreData) {
RequestManager requestManager = Glide.with(this);
RecyclerAdapter adapter = new RecyclerAdapter(getActivity(), mediaStoreData, requestManager);
RecyclerViewPreloader<MediaStoreData> preloader = new RecyclerViewPreloader<>(requestManager, adapter, adapter, 3);
recyclerView.addOnScrollListener(preloader);
recyclerView.setAdapter(adapter);
}
use of com.bumptech.glide.RequestManager in project Shuttle by timusus.
the class DetailFragment method refreshAdapterItems.
void refreshAdapterItems() {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
boolean albumsAscending = getAlbumsAscending();
boolean songsAscending = getSongsAscending();
@SortManager.SongSort int songSort = getSongsSortOrder();
@SortManager.AlbumSort int albumSort = getAlbumsSortOrder();
Observable<List<Song>> observable = null;
if (albumArtist != null) {
observable = DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(song -> Stream.of(albumArtist.albums).anyMatch(album1 -> album1.id == song.albumId)).collect(Collectors.toList()));
} else if (album != null) {
observable = DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(song -> song.albumId == album.id).collect(Collectors.toList()));
} else if (genre != null) {
observable = genre.getSongsObservable(getContext());
} else if (playlist != null) {
observable = playlist.getSongsObservable(getContext());
}
subscriptions.add(observable.map(songs -> {
songs = Stream.of(songs).filter(song -> {
if (albumArtist != null) {
return Stream.of(albumArtist.albums).anyMatch(album -> album.id == song.albumId);
} else if (album != null) {
return song.albumId == album.id;
}
return true;
}).collect(Collectors.toList());
List<Album> albums = Stream.of(Operators.songsToAlbums(songs)).collect(Collectors.toList());
if (playlist != null && albumSort == SortManager.AlbumSort.DEFAULT) {
switch(playlist.type) {
case Playlist.Type.MOST_PLAYED:
Collections.sort(albums, (a, b) -> ComparisonUtils.compareInt(b.songPlayCount, a.songPlayCount));
break;
case Playlist.Type.RECENTLY_PLAYED:
Collections.sort(albums, (a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed));
break;
case Playlist.Type.RECENTLY_ADDED:
Collections.sort(albums, (a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded));
break;
case Playlist.Type.USER_CREATED:
case Playlist.Type.FAVORITES:
case Playlist.Type.PODCAST:
Collections.sort(albums, (a, b) -> ComparisonUtils.compare(a.name, b.name));
break;
}
} else {
SortManager.getInstance().sortAlbums(albums, albumSort);
if (!albumsAscending) {
Collections.reverse(albums);
}
}
if (playlist == null || songSort != SortManager.SongSort.DETAIL_DEFAULT) {
SortManager.getInstance().sortSongs(songs, songSort);
if (!songsAscending) {
Collections.reverse(songs);
}
}
if (album == null) {
List<AdaptableItem> items = Stream.of(albums).map(album -> new HorizontalAlbumView(album, requestManager)).collect(Collectors.toList());
horizontalRecyclerView.setItems(items);
}
List<AdaptableItem> songViews = Stream.of(songs).map(song -> {
SongView songView = new SongView(song, multiSelector, requestManager);
songView.setShowAlbumArt(false);
songView.setEditable(canEdit());
songView.setShowTrackNumber(album != null && (songSort == SortManager.SongSort.DETAIL_DEFAULT || songSort == SortManager.SongSort.TRACK_NUMBER));
return songView;
}).collect(Collectors.toList());
if (album != null && album.numDiscs > 1 && (songSort == SortManager.SongSort.DETAIL_DEFAULT || songSort == SortManager.SongSort.TRACK_NUMBER)) {
int discNumber = 0;
int length = songViews.size();
for (int i = 0; i < length; i++) {
SongView songView = (SongView) songViews.get(i);
if (discNumber != songView.song.discNumber) {
discNumber = songView.song.discNumber;
songViews.add(i, new DiscNumberView(discNumber));
}
}
}
List<AdaptableItem> adaptableItems = new ArrayList<>();
adaptableItems.add(headerItem);
if (album == null) {
adaptableItems.add(horizontalRecyclerView);
}
adaptableItems.addAll(songViews);
return adaptableItems;
}).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
if (adaptableItems.isEmpty()) {
adapter.setEmpty(new EmptyView(R.string.empty_songlist));
} else {
if (sortChanged) {
adapter.items.clear();
adapter.items = adaptableItems;
adapter.notifyDataSetChanged();
recyclerView.smoothScrollToPosition(0);
sortChanged = false;
} else {
adapter.setItems(adaptableItems);
}
}
int numSongs = (int) Stream.of(adaptableItems).filter(value -> value instanceof SongView).count();
int numAlbums = horizontalRecyclerView.getCount();
if (lineTwo != null) {
if (albumArtist != null) {
lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, albumArtist.getNumSongs()));
} else if (album != null) {
lineTwo.setText(String.format("%s%s", album.getAlbumArtist().name, numSongs > 0 ? " | " + album.getNumSongsLabel() : ""));
} else if (genre != null) {
lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, numSongs));
} else if (playlist != null) {
lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, numSongs));
}
}
List<Album> albums = Stream.of(adaptableItems).filter(adaptableItem -> adaptableItem instanceof SongView).map(songView -> (Song) songView.getItem()).map(Song::getAlbum).distinct().collect(Collectors.toList());
if (playlist != null || genre != null && !albums.isEmpty()) {
if (slideShowObservable != null && !slideShowObservable.isUnsubscribed()) {
slideShowObservable.unsubscribe();
}
slideShowObservable = Observable.interval(8, TimeUnit.SECONDS).onBackpressureDrop().startWith(0L).map(aLong -> {
if (albums.isEmpty() || aLong == 0L && currentSlideShowAlbum != null) {
return null;
}
return albums.get(new Random().nextInt(albums.size()));
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(nextSlideShowAlbum -> {
if (nextSlideShowAlbum != null && nextSlideShowAlbum != currentSlideShowAlbum) {
requestManager.load(nextSlideShowAlbum).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.HIGH).error(GlideUtils.getPlaceHolderDrawable(nextSlideShowAlbum.name, true)).centerCrop().thumbnail(Glide.with(this).load(currentSlideShowAlbum).centerCrop()).animate(new AlwaysCrossFade(false)).into(headerImageView);
currentSlideShowAlbum = nextSlideShowAlbum;
}
});
subscriptions.add(slideShowObservable);
}
}));
}
});
}
use of com.bumptech.glide.RequestManager in project glide by bumptech.
the class RequestManagerFragmentTest method testNonSupportFragmentCallsOnTrimMemory.
@Test
public void testNonSupportFragmentCallsOnTrimMemory() {
RequestManagerHarness requestManagerHarness = new RequestManagerHarness();
int level = 100;
RequestManager requestManager = mock(RequestManager.class);
requestManagerHarness.setRequestManager(requestManager);
requestManagerHarness.onTrimMemory(level);
verify(requestManager).onTrimMemory(eq(level));
}
use of com.bumptech.glide.RequestManager 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.bumptech.glide.RequestManager in project Shuttle by timusus.
the class AlbumFragment method refreshAdapterItems.
void refreshAdapterItems(boolean force) {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
int albumDisplayType = SettingsManager.getInstance().getAlbumDisplayType();
boolean ascending = SortManager.getInstance().getAlbumsAscending();
subscription = DataManager.getInstance().getAlbumsRelay().skipWhile(albums -> !force && Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumView).count() == albums.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(albums -> {
// Sort
SortManager.getInstance().sortAlbums(albums);
// Reverse if required
if (!ascending) {
Collections.reverse(albums);
}
return Observable.fromIterable(albums).map(album -> {
// Look for an existing AlbumView wrapping the album, we'll reuse it if it exists.
AlbumView albumView = (AlbumView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumView && (((AlbumView) viewModel).album.equals(album))).findFirst().orElse(null);
if (albumView == null) {
albumView = new AlbumView(album, albumDisplayType, requestManager);
albumView.setClickListener(this);
}
return (ViewModel) albumView;
}).toList();
}).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
if (items.isEmpty()) {
adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_albums)));
} else {
items.add(0, shuffleView);
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;
}, error -> LogUtils.logException(TAG, "Error refreshing adapter items", error));
}
});
}
Aggregations