Matt
Matt

Reputation: 1131

MVVMCross Downloadcache - ProgressView during loading

I'm currently testing the downloadcache and this really looks great.

I have some questions regarding this plugin (I'm pretty new to C# and don't understand the full source code of the plugin):

1) ProgressView

I would like to show a progressview on the image until it has been loaded. To do that, I need to be notified when the image is loaded.

In the "MvxImageViewLoader" I see there is an Action "afterImageChangeAction" (null by default). However, I don't understand if and how I can access that Action from "MvxImageView"? (how to set it)

2) Don't load old image

When using Tables or Cellectionviews in iOS, it's important to check if the URL has been changed before setting the image (because iOS reuses the objects). I looked at the source code of the downloadcache and I don't see this check.

However, in the "MvxDynamicImageHelper.cs" class, I see that when a new URL is set, it calls "ClearCurrentHttpImageRequest();" which removes the "update" Events.

So I assume this is enough to prevent that an image is set to the wrong UIImageView?

3) ImageCache size in (mega)bytes

The ImageCache does not have a property to define the mamiximum size (megabytes for example) of the persistent image store (on the HD). I prefer to use a maximum size in (mega)bytes instead of a maximum amount of files because the user will care more how much space an app takes instead of how many files are stored by the app.

I assume the easiest for me is to define a "TimeSpan PeriodSaveInterval" independent from the one in MvxFileDownloadCache to just check the size of the folder defined for the Image Cache or any other recommendations?

Is it dangerous for performance to scan the folder and calculate the size of all the images in a folder?

Regards, Matt

Upvotes: 1

Views: 1720

Answers (2)

Bjarke
Bjarke

Reputation: 1295

I know Stuart already provided an excellent answer. But what I did, when I needed the exact same feature, was to subclass MvxImageView and override the UIImageView.Image property. When the image is set I fire an event which is caught by the viewcontroller.

Upvotes: 0

Stuart
Stuart

Reputation: 66882

1) ProgressView

I would like to show a progressview on the image until it has been loaded. To do that, I need to be notified when the image is loaded.

There is a DefaultImagePath which provides the path of an image that should be shown during loading.

But if you need a dynamic animation or other custom view, then afterImageChangeAction can be used

As you've seen, you can't do this in MvxImageView - the Action wasn't really a suitable candidate to be a bindable property so it wasn't exposed as a property.

However, you can:


As an alternative to using the Action callback, you can also inherit from MvxBaseImageViewLoader<T> and provide an override for the ImageHelperOnImageChanged method - see https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding/Views/MvxBaseImageViewLoader.cs#L49

2) Don't load old image

3) ImageCache size in (mega)bytes

The interface-driven and plugin structure of MvvmCross is defined to allow you to implement alternatives.

In the case of loading images from HTTP, there are many alternatives - you don't have to use the MvvmCross download cache for image loading.

The only docs available for the download cache plugin currently is https://github.com/slodge/MvvmCross/wiki/MvvmCross-plugins#downloadcache

For Android, some suggestions for alternative implementations are listed in: https://github.com/slodge/MvvmCross/issues/416

For iOS, it may be useful to read https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html including the section on <Application_Home>/Library/Caches

Upvotes: 1

Related Questions