Skip to content

Instantly share code, notes, and snippets.

@Nimrodda
Last active February 5, 2021 15:34
Show Gist options
  • Save Nimrodda/16072fd0d1cec10da79c4a82c5470d31 to your computer and use it in GitHub Desktop.
Save Nimrodda/16072fd0d1cec10da79c4a82c5470d31 to your computer and use it in GitHub Desktop.
Glide migration from v3 to v4 cheatsheet

Glide v3 Migration to v4 Cheatsheet

Description V3 V4
Entry point - optional unless you have a custom GlideModule Glide GlideApp
Bitmap transformations bitmapTransform() transform()
Release bitmap Glide.clear() GlideApp.with(context).clear()
Custom animations animate(android.R.anim.fade_in) transition(GenericTransitionOptions.with(android.R.anim.fade_in))
Request builder DrawableRequestBuilder<CustomModel> RequestBuilder<Drawable>
Request builder DrawableRequestBuilder<String> RequestBuilder<Drawable>
Custom model usage RequestManager.from(Model.class) not needed anymore. Must be configured in GlideModule.
Custom model loaders implements StreamModelLoader<T> ModelLoader<Model, InputStream> (or BaseGlideUrlLoader<Model> for http/s schemes only)
Non-view targets SimpleTarget CustomTarget
Caching strategy DiskCacheStrategy.SOURCE DiskCacheStrategy.DATA
Caching strategy DiskCacheStrategy.RESULT DiskCacheStrategy.RESOURCE
Target specification into<SimpleTarget<Bitmap>>(target) into(target) no need for generic
Request listener RequestListener<Model, GlideDrawable> RequestListener<Drawable>
Request listener RequestListener<String, GlideDrawable> RequestListener<Drawable>
Drawables GlideDrawable Drawable
Video decoder config videoDecoder() frame() and do video decoder config in GlideModule registry.prepend(ParcelFileDescriptor::class.java, Bitmap::class.java, VideoDecoder.parcel(glide.bitmapPool))
Cache key signature(new StringSignature("foo") signature(new ObjectKey("foo"))
Loading into bitmap with fixed size into(640, 640) submit(640, 640)
Bitmap loading only bitmap = Glide.with(context).load(profileImageUrl).asBitmap().into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get() bitmap = GlideApp.with(context).asBitmap().load(profileImageUrl) .submit().get()
Registering custom model loaders glide.register(CenterCropImageInformation.class, InputStream.class, new CenterCropImageInformationLoader.Factory()) registry.append( CenterCropImageInformation::class.java, InputStream::class.java, CenterCropImageInformationLoader.Factory(context, ModelCache(500)))
@trietbui85
Copy link

Thanks for your gist.

bitmap = Glide.with(context).load(profileImageUrl).asBitmap().into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get()
This LOC looks so long, thus make V4 column hard to read (I must scroll to right in order to see it fully). So could you please edit it by splitting it to 2 or 3 line?
(The same for glide.register(CenterCropImageInformation.class, InputStream.class, new CenterCropImageInformationLoader.Factory()))

@skvaryk
Copy link

skvaryk commented Feb 5, 2021

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment