use of com.bumptech.glide.RequestManager in project glide by bumptech.
the class RequestManagerRetriever method supportFragmentGet.
RequestManager supportFragmentGet(Context context, FragmentManager fm, Fragment parentHint) {
SupportRequestManagerFragment current = getSupportRequestManagerFragment(fm, parentHint);
RequestManager requestManager = current.getRequestManager();
if (requestManager == null) {
// TODO(b/27524013): Factor out this Glide.get() call.
Glide glide = Glide.get(context);
requestManager = new RequestManager(glide, current.getLifecycle(), current.getRequestManagerTreeNode());
current.setRequestManager(requestManager);
}
return requestManager;
}
use of com.bumptech.glide.RequestManager in project glide by bumptech.
the class RequestManagerRetriever method fragmentGet.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
RequestManager fragmentGet(Context context, android.app.FragmentManager fm, android.app.Fragment parentHint) {
RequestManagerFragment current = getRequestManagerFragment(fm, parentHint);
RequestManager requestManager = current.getRequestManager();
if (requestManager == null) {
// TODO(b/27524013): Factor out this Glide.get() call.
Glide glide = Glide.get(context);
requestManager = new RequestManager(glide, current.getLifecycle(), current.getRequestManagerTreeNode());
current.setRequestManager(requestManager);
}
return requestManager;
}
use of com.bumptech.glide.RequestManager in project MVPArms by JessYanCoding.
the class GlideImageLoaderStrategy method loadImage.
@Override
public void loadImage(Context ctx, GlideImageConfig config) {
if (ctx == null)
throw new IllegalStateException("Context is required");
if (config == null)
throw new IllegalStateException("GlideImageConfig is required");
if (TextUtils.isEmpty(config.getUrl()))
throw new IllegalStateException("url is required");
if (config.getImageView() == null)
throw new IllegalStateException("imageview is required");
RequestManager manager;
//如果context是activity则自动使用Activity的生命周期
manager = Glide.with(ctx);
DrawableRequestBuilder<String> requestBuilder = manager.load(config.getUrl()).crossFade().centerCrop();
switch(//缓存策略
config.getCacheStrategy()) {
case 0:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL);
break;
case 1:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE);
break;
case 2:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE);
break;
case 3:
requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT);
break;
}
if (config.getTransformation() != null) {
//glide用它来改变图形的形状
requestBuilder.transform(config.getTransformation());
}
if (//设置占位符
config.getPlaceholder() != 0)
requestBuilder.placeholder(config.getPlaceholder());
if (//设置错误的图片
config.getErrorPic() != 0)
requestBuilder.error(config.getErrorPic());
requestBuilder.into(config.getImageView());
}
use of com.bumptech.glide.RequestManager in project Shuttle by timusus.
the class SuggestedFragment method refreshAdapterItems.
void refreshAdapterItems() {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
subscription = new CompositeSubscription();
Observable<Playlist> mostPlayedPlaylistObservable = Observable.fromCallable(Playlist::mostPlayedPlaylist).subscribeOn(Schedulers.io()).cache();
Observable<List<Song>> mostPlayedSongsObservable = mostPlayedPlaylistObservable.filter(playlist -> playlist != null).flatMap(playlist -> playlist.getSongsObservable(getContext())).cache();
Observable<List<AdaptableItem>> mostPlayedItemsObservable = mostPlayedPlaylistObservable.flatMap(playlist -> {
SuggestedHeader mostPlayedHeader = new SuggestedHeader(getString(R.string.mostplayed), getString(R.string.suggested_most_played_songs_subtitle), playlist);
SuggestedHeaderView mostPlayedHeaderView = new SuggestedHeaderView(mostPlayedHeader);
return mostPlayedSongsObservable.map(songs -> {
List<AdaptableItem> items = new ArrayList<>();
if (!songs.isEmpty()) {
items.add(mostPlayedHeaderView);
items.add(mostPlayedRecyclerView);
}
return items;
});
}).switchIfEmpty(Observable.just(Collections.emptyList()));
Observable<List<AdaptableItem>> recentlyPlayedAlbums = Observable.fromCallable(Playlist::recentlyPlayedPlaylist).subscribeOn(Schedulers.io()).filter(playlist -> playlist != null).flatMap(playlist -> {
SuggestedHeader recentlyPlayedHeader = new SuggestedHeader(getString(R.string.suggested_recent_title), getString(R.string.suggested_recent_subtitle), playlist);
SuggestedHeaderView recentlyPlayedHeaderView = new SuggestedHeaderView(recentlyPlayedHeader);
return playlist.getSongsObservable(getContext()).flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMap(Observable::from).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).limit(6).flatMap(album -> album.getSongsObservable().map(songs -> {
album.numSongs = songs.size();
return album;
})).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).filter(album -> album.numSongs > 0).map(album -> (AdaptableItem) new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager)).toList().map(adaptableItems -> {
if (!adaptableItems.isEmpty()) {
adaptableItems.add(0, recentlyPlayedHeaderView);
}
return adaptableItems;
});
}).switchIfEmpty(Observable.just(Collections.emptyList()));
Observable<Playlist> favouritesPlaylistObservable = Observable.fromCallable(Playlist::favoritesPlaylist).subscribeOn(Schedulers.io()).cache();
Observable<List<Song>> favouritesSongsObservable = favouritesPlaylistObservable.filter(playlist -> playlist != null).flatMap(playlist -> playlist.getSongsObservable(getContext())).cache();
Observable<List<AdaptableItem>> favoriteSongsItemsObservable = favouritesPlaylistObservable.flatMap(playlist -> {
SuggestedHeader favoriteHeader = new SuggestedHeader(getString(R.string.fav_title), getString(R.string.suggested_favorite_subtitle), playlist);
SuggestedHeaderView favoriteHeaderView = new SuggestedHeaderView(favoriteHeader);
return favouritesSongsObservable.map(songs -> {
List<AdaptableItem> items = new ArrayList<>();
if (!songs.isEmpty()) {
items.add(favoriteHeaderView);
items.add(favoriteRecyclerView);
}
return items;
});
}).switchIfEmpty(Observable.just(Collections.emptyList()));
Observable<List<AdaptableItem>> recentlyAddedAlbums = Observable.fromCallable(Playlist::recentlyAddedPlaylist).subscribeOn(Schedulers.io()).filter(playlist -> playlist != null).flatMap(playlist -> {
SuggestedHeader recentlyAddedHeader = new SuggestedHeader(getString(R.string.recentlyadded), getString(R.string.suggested_recently_added_subtitle), playlist);
SuggestedHeaderView recentlyAddedHeaderView = new SuggestedHeaderView(recentlyAddedHeader);
return playlist.getSongsObservable(getContext()).flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMap(Observable::from).sorted((a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded)).limit(4).flatMap(album -> album.getSongsObservable().map(songs -> {
album.numSongs = songs.size();
return album;
})).sorted((a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded)).filter(album -> album.numSongs > 0).map(album -> (AdaptableItem) new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager)).toList().map(adaptableItems -> {
if (!adaptableItems.isEmpty()) {
adaptableItems.add(0, recentlyAddedHeaderView);
}
return adaptableItems;
});
}).switchIfEmpty(Observable.just(Collections.emptyList()));
Observable.merge(mostPlayedItemsObservable, recentlyPlayedAlbums, favoriteSongsItemsObservable, recentlyAddedAlbums);
subscription.add(Observable.combineLatest(mostPlayedItemsObservable, recentlyPlayedAlbums, favoriteSongsItemsObservable, recentlyAddedAlbums, (mostPlayedSongs1, recentlyPlayedAlbums1, favoriteSongs1, recentlyAddedAlbums1) -> {
List<AdaptableItem> items = new ArrayList<>();
items.addAll(mostPlayedSongs1);
items.addAll(recentlyPlayedAlbums1);
items.addAll(favoriteSongs1);
items.addAll(recentlyAddedAlbums1);
return items;
}).debounce(250, TimeUnit.MILLISECONDS).switchIfEmpty(Observable.just(new ArrayList<>())).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
if (adaptableItems.isEmpty()) {
suggestedAdapter.setEmpty(new EmptyView(R.string.empty_suggested));
} else {
suggestedAdapter.setItems(adaptableItems);
}
}));
subscription.add(mostPlayedSongsObservable.map(songs -> {
Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(b.playCount, a.playCount));
return Stream.of(songs).map(song -> (AdaptableItem) new SuggestedSongView(song, requestManager)).limit(20).collect(Collectors.toList());
}).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
mostPlayedRecyclerView.itemAdapter.setItems(adaptableItems);
}));
subscription.add(favouritesSongsObservable.map(songs -> Stream.of(songs).map(song -> (AdaptableItem) new SuggestedSongView(song, requestManager)).limit(20).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
favoriteRecyclerView.itemAdapter.setItems(adaptableItems);
}));
}
});
}
use of com.bumptech.glide.RequestManager in project Shuttle by timusus.
the class AlbumFragment method refreshAdapterItems.
void refreshAdapterItems() {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
int albumDisplayType = SettingsManager.getInstance().getAlbumDisplayType();
boolean ascending = SortManager.getInstance().getAlbumsAscending();
subscription = DataManager.getInstance().getAlbumsRelay().flatMap(albums -> {
SortManager.getInstance().sortAlbums(albums);
if (!ascending) {
Collections.reverse(albums);
}
return Observable.from(albums).map(album -> (AdaptableItem) new AlbumView(album, albumDisplayType, requestManager, multiSelector)).toList();
}).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
if (items.isEmpty()) {
albumAdapter.setEmpty(new EmptyView(R.string.empty_albums));
} else {
albumAdapter.setItems(items);
}
if (sortOrderChanged) {
recyclerView.scrollToPosition(0);
}
sortOrderChanged = false;
});
}
});
}
Aggregations