I am using MvvmCross in my Android project. I have a MvxRecyclerView
that contains an image in each item (downloaded from a url), and there are hundreds of items, so I want to use the DownloadCache
plugin to help me manage the images/memory so my app doesn't crash with a OutOfMemory exception.
Ideally, when the image/memory limit has been reached, the first image that was downloaded (and is the farthest non-visible item in the MvxRecyclerView
) should be freed to make room for the next visible item with its image.
I found the source for it here: https://github.com/MvvmCross/MvvmCross/tree/develop/MvvmCross-Plugins/DownloadCache
How can I use this plugin to achieve this?
EDIT
After trying a few things, I'm stuck over this error that I get when I call Mvx.Resolve<IMvxImageCache<byte[]>>().RequestImage(myImageUrl)
Failed to resolve type MvvmCross.Plugins.DownloadCache.IMvxLocalFileImageLoader
I'm registering the type like this so I don't know why it can't resolve it:
Mvx.ConstructAndRegisterSingleton<IMvxLocalFileImageLoader<Bitmap>, MvxAndroidLocalFileImageLoader>();
I'm registering the IMvxImageCache
like this:
Mvx.RegisterSingleton(typeof(IMvxImageCache<byte[]>), () =>
{
return new MvxImageCache<byte[]>(Mvx.Resolve<IMvxFileDownloadCache>(), 2, 5000000, true);
});
I feel like I'm doing something wrong...
The documentation is available here. The documentation seems to suggest:
MvxImageView
instead of ImageView
.MvxDownloadCacheConfiguration
in Setup.GetPluginConfiguration
override to customize the cache options as needed.