These are full of my app specific stuff – dependent on my data I get from the server for my list… I chopped out a little flotsam and jetsom here and there… Caveat Emptor my friend.
From my image populate listener…
[lua]
– imagePopulateListener(event) -called back when the image for the row onscreen is downloaded…
–
local function imagePopulateListener(event)
print(" – imagePopulateListener(event) event.response ==", event.response)
– Let’s see if messageList even exists still, user could have left screen before server replied…
if( (this ~= nil) and (event ~= nil)) then – Dont do it if user has left the screen…
if( this.messageList ~= nil ) then – Don’t do it if there’s no list of messages somehow
– print(" – rows == “, this.messageList._view._categoryGroup._rows)
local rows = this.messageList._view._rows
local maxRows = #rows – #this.messageList.content.rows
if( maxRows == nil ) then
maxRows = 0
end
– print (” – maxRows == ", maxRows)
if( (maxRows > 0) and (event.url ~= nil) ) then
– print(" – messageList.view.content.rows[1] == “, this.messageList.content.rows[1] )
local localFilename = utils.getBaseFilename(event.url)
– print(” – localFilename == ", localFilename)
– Search for the right list item for this image…
local rowIndex = 0
for i=1, maxRows do
– print(" – row #, view == “, i, this.messageList.content.rows[i].view)
– print(” – fileloc, imageloc == “, rows[i].FILELOCATION, rows[i].imageLocation)
if( rows[i].id ~= nil ) then
– print(” – Found one with an image… “, rows[i].id)
if( utils.getBaseFilename(rows[i].id) == localFilename ) then
– print(” ******** Found the Image **********")
rowIndex = i – Found the right rows index.
local myImage = getMessageThumbnail(localFilename) – Routine that just loads up the image (thumbnail scale)
myImage.x = 590
myImage.y = (rows[rowIndex]._height / 2) - 1 – Center it for now
rows[rowIndex]._view:insert(myImage) – Jam it into the item.
myImage.isVisible = true
– print(" ******** Added image to row: “, localFilename)
refreshWG() – refresh the popups if need be
break
end
end
end
else
print(” *** NO ROWS / no url")
end
else
print(" – messageList == nil")
end
else
print(" – this == nil")
end
[/lua]
And this is the bit of my onRowRender that calls out to get it going if there is an image for the row…
[lua]
if( utils.isEmpty(currMess.FILELOCATION) == false ) then – Yes, we have an image for this row
– Let’s see if we have the file in our download cache already…
local localFilename = utils.getBaseFilename(currMess.FILELOCATION)
if( utils.cacheFileExists(localFilename) == true ) then – do we have an already downloaded and ready to go image with this message?
local myImage = getMessageThumbnail(localFilename)
myImage.x = 588
myImage.y = math.floor(row.height / 2) – Center it for now
myImage.isVisible = true
row:insert(myImage) – add it to the row.
– print(" ******** Added image to row: ", localFilename)
else
– Let’s call for the the file to be downloaded (it could already be cached, or in process of download too)…
utils.downloadFile(currMess.FILELOCATION, imagePopulateListener)
end
end
[/lua]
I’ve had to hack it up a little, but I think it’s all there for reference anyways.