use of com.bumptech.glide.GenericRequestBuilder in project Shuttle by timusus.
the class QueuePagerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_queue_pager, container, false);
unbinder = ButterKnife.bind(this, rootView);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
if (ShuttleUtils.isLandscape()) {
textProtectionScrim.setVisibility(View.GONE);
}
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(viewModelAdapter);
SnapHelper snapHelper = new PagerSnapHelper() {
@Override
public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
int snapPosition = super.findTargetSnapPosition(layoutManager, velocityX, velocityY);
if (snapPosition < viewModelAdapter.items.size()) {
Observable.defer(() -> {
if (MusicUtils.getQueuePosition() != snapPosition) {
MusicUtils.setQueuePosition(snapPosition);
}
return Observable.empty();
}).delaySubscription(150, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io()).subscribe();
}
return snapPosition;
}
};
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.addOnScrollListener(new RecyclerViewPreloader<>(new ListPreloader.PreloadModelProvider<QueuePagerItemView>() {
@Override
public List<QueuePagerItemView> getPreloadItems(int position) {
QueuePagerItemView queuePagerItemView = (QueuePagerItemView) viewModelAdapter.items.get(position);
return Collections.singletonList(queuePagerItemView);
}
@Override
public GenericRequestBuilder getPreloadRequestBuilder(QueuePagerItemView item) {
return requestManager.load(item.song).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(PlaceholderProvider.getInstance().getPlaceHolderDrawable(item.song.name, true));
}
}, (item, adapterPosition, perItemPosition) -> imageSize, 3));
recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
// This null check doesn't make sense to me, but there was an NPE here..
if (recyclerView != null) {
imageSize = new int[] { recyclerView.getWidth(), recyclerView.getHeight() };
recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
}
return false;
}
});
return rootView;
}
use of com.bumptech.glide.GenericRequestBuilder in project RichText by zzhoujay.
the class GlideImageGetter method getDrawable.
@Override
public Drawable getDrawable(ImageHolder holder, final RichTextConfig config, TextView textView) {
final ImageTarget target;
final GenericRequestBuilder load;
DrawableTypeRequest dtr;
DrawableWrapper drawableWrapper = new DrawableWrapper();
byte[] src = Base64.decode(holder.getSource());
if (src != null) {
dtr = Glide.with(textView.getContext()).load(src);
} else {
dtr = Glide.with(textView.getContext()).load(holder.getSource());
}
Rect rect = null;
if (config.cacheType >= CacheType.LAYOUT) {
rect = loadCache(holder.getSource());
if (rect != null) {
drawableWrapper.setBounds(rect);
}
} else {
drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight());
}
if (holder.isGif()) {
target = new ImageTargetGif(textView, drawableWrapper, holder, config, this, rect);
load = dtr.asGif();
} else {
target = new ImageTargetBitmap(textView, drawableWrapper, holder, config, this, rect);
load = dtr.asBitmap().atMost();
}
checkTag(textView);
targets.add(target);
if (!config.resetSize && holder.isInvalidateSize()) {
load.override(holder.getWidth(), holder.getHeight());
}
if (holder.getScaleType() == ImageHolder.ScaleType.CENTER_CROP) {
if (holder.isGif()) {
// noinspection ConstantConditions
((GifTypeRequest) load).centerCrop();
} else {
// noinspection ConstantConditions
((BitmapTypeRequest) load).centerCrop();
}
} else if (holder.getScaleType() == ImageHolder.ScaleType.FIT_CENTER) {
if (holder.isGif()) {
// noinspection ConstantConditions
((GifTypeRequest) load).fitCenter();
} else {
// noinspection ConstantConditions
((BitmapTypeRequest) load).fitCenter();
}
}
textView.post(new Runnable() {
@Override
public void run() {
load.placeholder(config.placeHolder).error(config.errorImage).into(target);
}
});
drawableWrapper.setCallback(textView);
return drawableWrapper;
}
use of com.bumptech.glide.GenericRequestBuilder in project BBS-Android by bdpqchen.
the class GlideImageGeter method getDrawable.
@Override
public Drawable getDrawable(String url) {
final UrlDrawable urlDrawable = new UrlDrawable();
GenericRequestBuilder load;
final Target target;
if (isGif(url)) {
load = Glide.with(mContext).load(url).asGif();
target = new GifTarget(urlDrawable);
} else {
load = Glide.with(mContext).load(url).asBitmap();
target = new BitmapTarget(urlDrawable);
}
targets.add(target);
load.into(target);
return urlDrawable;
}
use of com.bumptech.glide.GenericRequestBuilder in project Shuttle by timusus.
the class QueuePagerFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_queue_pager, container, false);
unbinder = ButterKnife.bind(this, rootView);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
if (ShuttleUtils.isLandscape(getContext())) {
textProtectionScrim.setVisibility(View.GONE);
}
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(viewModelAdapter);
SnapHelper snapHelper = new PagerSnapHelper() {
@Override
public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
int snapPosition = super.findTargetSnapPosition(layoutManager, velocityX, velocityY);
if (snapPosition < viewModelAdapter.items.size()) {
Observable.timer(200, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(o -> {
if (mediaManager.getQueuePosition() != snapPosition) {
mediaManager.setQueuePosition(snapPosition);
}
}, throwable -> LogUtils.logException(TAG, "Error setting queue position", throwable));
}
return snapPosition;
}
};
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.addOnScrollListener(new RecyclerViewPreloader<>(new ListPreloader.PreloadModelProvider<QueuePagerItemView>() {
@Override
public List<QueuePagerItemView> getPreloadItems(int position) {
QueuePagerItemView queuePagerItemView = (QueuePagerItemView) viewModelAdapter.items.get(position);
return Collections.singletonList(queuePagerItemView);
}
@Override
public GenericRequestBuilder getPreloadRequestBuilder(QueuePagerItemView item) {
return requestManager.load(item.song).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(PlaceholderProvider.getInstance(getContext()).getPlaceHolderDrawable(item.song.name, true, settingsManager));
}
}, (item, adapterPosition, perItemPosition) -> imageSize, 3));
recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
// This null check doesn't make sense to me, but there was an NPE here..
if (recyclerView != null) {
imageSize = new int[] { recyclerView.getWidth(), recyclerView.getHeight() };
recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
}
return false;
}
});
return rootView;
}
use of com.bumptech.glide.GenericRequestBuilder in project FastHub by k0shk0sh.
the class DrawableGetter method getDrawable.
@Override
public Drawable getDrawable(@NonNull String url) {
final UrlDrawable urlDrawable = new UrlDrawable();
if (container != null && container.get() != null) {
Context context = container.get().getContext();
final GenericRequestBuilder load = Glide.with(context).load(url).placeholder(ContextCompat.getDrawable(context, R.drawable.ic_image)).dontAnimate();
final GlideDrawableTarget target = new GlideDrawableTarget(urlDrawable, container, width);
load.override(width, width / 2);
load.into(target);
cachedTargets.add(target);
}
return urlDrawable;
}
Aggregations