tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/976-itemrenderer-loading-and-displaying-thumbnails-with-a-custom-loaderRobotlegs: Discussion 2012-08-25T14:42:04Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/176554072012-07-28T18:31:59Z2012-07-28T18:31:59ZItemrenderer - loading and displaying thumbnails with a custom loader<div><p>Well, perhaps you could set up a Binding class which holds a
reference to the VO and the loader. It listens to the loader,
populates the VO and then deposes itself.<br>
Is that the problem, getting the Image into the VO?</p></div>neiltag:robotlegs.tenderapp.com,2009-10-18:Comment/176554072012-07-29T05:17:57Z2012-07-29T05:17:58ZItemrenderer - loading and displaying thumbnails with a custom loader<div><p>Hello neil,</p>
<p>No, that's not the problem.<br>
The problem is, that there may be hundreds of VOs around, and due
to performance I don't want to store the thumb in them.<br>
I just don't know what is the best way to get the thumb into the
itemrenderer - without touching the VO.</p></div>Christag:robotlegs.tenderapp.com,2009-10-18:Comment/176554072012-07-29T12:50:26Z2012-07-29T12:50:26ZItemrenderer - loading and displaying thumbnails with a custom loader<div><p>Hey Chris,</p>
<p>I took a look at Mihai Corlan’s example:</p>
<p><a href=
"http://corlan.org/2011/07/11/creating-flex-mobile-lists-part-ii-using-virtualization/">
http://corlan.org/2011/07/11/creating-flex-mobile-lists-part-ii-usi...</a></p>
<p>where he uses ContentCache, which I think is what you need.</p>
<p>Let’s take his example as a base for our discussion.</p>
<p>In his View, VirtualLayout, there is a SectionList, which has an
ArrayCollection as data provider. SectionList uses a custom
ItemRenderer: TileItemRenderer, which makes use of
ContentCache.</p>
<p>Now, if the View, VirtualLayout, would be mediated through
VirtualLayoutMediator, you could let it pass the ArrayCollection to
the View, after receiving it from a Model or Service( ask for data
by dispatching an event, that triggers a command, that accesses a
service etc).</p>
<p>In VirtualLayout you’d have a method,”
populateListWithData”, or something with a better name, where
you’d set SectionList’s dataProvider to the
ArrayCollection loaded by the service. The ItemRenderer would take
care of loading the images according to the urls provided in that
ArrayCollection.</p>
<p>You don’t need hundreds of VO’s, you just provide
the list with data as it needs it, ArrayCollection, IList, XMLList
or whatever. You parse the data loaded by the Service to the
appropriate format, let the Model manipulate it, if need be, and
then pass it to the Mediator->View->List.</p>
<p>You also don’t need to mediate the ItemRenderer. If you
want to dispatch events from within your ItemRenderer, you can
create a custom event, with bubbles set to true (!!), and
VirtualLayoutMediator will be able to listen to it and relay it to
other framework classes, if need be. Or you can let VirtualLayout
listen for events dispatched by the ItemRenderer and redispatch
them.</p>
<p>So, let the VirtualLayout View take care of layout and
rendering, through SectionList’s SectionTileListLayout and
TileItemRenderer and let VirtualLayoutMediator be the link between
your View and the rest of your application.</p>
<p>Would this work for you?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/176554072012-07-30T12:40:22Z2012-07-30T12:46:24ZItemrenderer - loading and displaying thumbnails with a custom loader<div><p>Second part of my answer that I couldn’t finish
yesterday:</p>
<p>You said that you extended the ContentCache. So, you could use
the ContentCache as a Service instead of having it inside the
ItemRenderer.</p>
<p>A Model would build the collection for the List with the needed
images (from cache or new ones) and other info, and when
you’re refreshing the List’s dataProvider (with the
payload of the event dispatched by the
Model->Mediator->View->List), the ItemRenderer would read
the values of its “data” property and set the images
and everything else. Without trying it out, I can’t say how
well it would perform (in a mobile application) refreshing the
List’s dataProvider this way<br>
(ItemRenderer->event->View->event->Mediator-event->Command->Services->event->Command->Model-event->Mediator->View->List->dataProvider->Itemrenderer)
on every scrollPositionChanged event, or if having ContentCache
inside the ItemRenderer would be easier to mange and better for
performance….</p>
<p>As a side note, you can set the ItemRenderer’s data
property to a VO, but I guess you knew this already, and you also
said, you didn’t want to store the images in a VO.</p>
<p>Then, I think, you could build your collection in the Model,
when the Services (for images and other data) have finished their
jobs, having 2 objects:<br>
the loaded or cached images <em>and</em> the VOs (containing only
info like label, name etc) :<br>
yourCollection[imagesVOS], yourCollection[thumbnails], and the
ItemRenderer will read the data accordingly. I hope it’s
clear what I’m trying to say.</p>
<blockquote>
<p>But I need access to the framework to dispatch error events and
such</p>
</blockquote>
<p>Do you mean from the class extending ContentCache? If so, you
can provide that class with the shared eventDispatcher –
it’s all you need to be able to communicate with other
framework classes.</p>
<p>Maybe a PresentationModel pattern would serve you better than
the Mediator one, but you’ll have to investigate that on your
own.</p></div>Ondina D.F.