glidex
glidex copied to clipboard
[Question] Configuration
Hi Jonathan, great work! I would love to see a fully functional Glide in Xamarin. Is there a way to configure glidex from Xamarin.Android ? I saw, that you excluded the annotation package. But the official documentation says to use @GlideModule
like
@GlideModule
public class YourAppGlideModule extends AppGlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
int diskCacheSizeBytes = 1024 * 1024 * 100; // 100 MB
builder.setDiskCache(
new InternalCacheDiskCacheFactory(context, "cacheFolderName", diskCacheSizeBytes));
}
}
from Glide Documentation
So I would need to look into how this actually works ^^ Hopefully it's not some gradle plugin or something that happens at build time?
Does Glide use Java reflection to find this type? It might work in Xamarin if I added the binding back for these types, and just documented how to do it.
The way this works is via "Java Annotation Processing", which happens at build time unfortunately...
So when javac
is called, you pass something like:
javac -processor com.yourpackage.GlideProcessor *.java
Then javac
generates Java code that makes the plumbing behind this work. However, Xamarin.Android does not have support for augmenting it's Javac MSBuild task to supply the -processor
switch...
Links on "Java Annotation Processing":
- https://www.baeldung.com/java-annotation-processing-builder
- http://hannesdorfmann.com/annotation-processing/annotationprocessing101
So what do we do?
The docs you linked to mention using the "Options" API as an alternate way to configure Glide: http://bumptech.github.io/glide/doc/options.html
Aside: They didn't have these nice docs when I wrote this thing!
The "Options" API is what I used in GlideExtensions.cs
: https://github.com/jonathanpeppers/glidex/blob/0dbbebb6d7499684fa70034eefb21d0720f45c13/glidex.forms/GlideExtensions.cs#L33-L34
I hope this helps, is there a particular feature or toggle you need to set in your app? We may need to expose a set of options in glidex.forms
so you won't have to implement your own IImageViewHandler
.
Thank you for the quick reply. I need to configure location and size of the disk cache. In addition I have to use custom loaders. I think the only way to achieve this with Glide is to write a small Java wrapper and call this from Xamarin.Android.
@nasibu post what you get working, or if you get stuck.
It might be that I can add something to make this easier to work from C#/Xamarin.
hah i came here looking for a way to configure glide disk caching on xam.android too. guess i'm out of luck. my issue is that loading images in my recyclerview adapter with glide results in the image not loading when the activity is resumed from the call stack because of some caching error(i presume as nothing else fixed the issue).
i used requestOptions.SkipMemoryCache(true)
to resolve the problem but i think this will cause issues in the future. might have to switch to FFImageLoading after all even though the performance of that is considerably slower
@kkarakk can you open a new issue, maybe include a code example?
We should just fix the problem so your layout works when resuming.