Lates version of Find movies to watch introduced movie details presentation. This also includes actor profile pictures.
These images are based on info from The Movie Database. When profile is show we do lazy loading of image using ImageProvide. This means either loading from local cache and presenting. Or retrieving it from remote source, caching for future use, and presenting.
But in some cases actor profile is missing image and I wanted to handle it by showing generated image with actor initials. Same way how The Movie Database does it. All this should ideally be done without changing existing presentation logic. I did not want to add additional code for handling generated images caching and presentation.
First step in achieving it was to introduced different profile image URL for missing ones. When TMDB was missing image, then actor object returned custom URL with following format:
Last characters are for actor name initials to be used in generated image.
ImageProvide is using the fetcher pattern where it requires that app injects logic for retrieving data from network. This gave me a perfect interception point for handling missing images.
With minimal changes outside presentation logic I was able to leverage the usual pull/cache/present logic that was already available for other images.
When time permits, I do my best to come up with simplest and most elegant solution possible. By adding some code outside main application logic I was able to introduce new feature with minimal effort.
I may not always get there, but this time I do feel like I nailed it :)
Tags: ios, programming, design