Delayed Image Load with DataGrid

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

JosepM
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 344
Joined: Tue Jul 20, 2010 12:40 pm

Re: Delayed Image Load with DataGrid

Post by JosepM » Sun Jul 06, 2014 4:43 pm

Hi Klaus,

Yes, only work on desktop, on mobile devices don't work.
Yes, but how pass the "data" of the image to the img control of the row? I'm blocked. :(

Any idea?


JosepM
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 344
Joined: Tue Jul 20, 2010 12:40 pm

Re: Delayed Image Load with DataGrid

Post by JosepM » Sun Jul 06, 2014 5:35 pm

Hi Klaus,

Code: Select all

on FillInData pDataArray
   Global aData
   
   set the text of field "Label" of me to pDataArray["label 4"]
   set the text of field "Label2" of me to pDataArray["label 3"]
   set the text of field "Label3" of me to pDataArray["label 5"]
   
   if pDataArray["Label 1"] is 1 then
      put URL pDataArray["label 6"] into img "f_image" of me
      set the text of field "Label2" of me to pDataArray["label 2"]
   else
      put img "NoImage" into img "f_image" of me -- otherwise put in a placeholder image
      put the dgindex of me into tIndex --grab the index
      
      put tIndex into aData[pDataArray["label 6"]]["Id_row"] --Store the index of the row
      
      load URL pDataArray["label 6"] with message "refreshDg" --load and call "refreshdg" which is a handler on the card
      
   end if

Code: Select all

command refreshDg pURL, pStatus, pData
   Global aData
   
   switch pStatus
      case "cached"
         put aData[pURL]["Id_row"] into tIndexRow
         get the dgDataOfIndex[tIndexRow] of group "DataGrid1" 
         put it into tData
         
         put 1 into tData["Label 1"] 
         put tIndexRow into tData["Label 2"] -- to test if the value is returned
         
         set the dgDataOfIndex [tIndexRow] of group "DataGrid1" to tData -- then pop it right back in, no changes needed.
         break
   end switch
end refreshDg

I store the the dgIndex into an array to pair imageURL and the row index.
From the callbackmessage I update it but still the imageholder into the image... on desktop run fine but not on the device.
Any idea?

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Delayed Image Load with DataGrid

Post by Klaus » Sun Jul 06, 2014 6:31 pm

Hi Josep,

looks ok so far!?

Did you check the content of your global aData array?
Did you check if pStatus is really "cached" at some time?
Just guessing, no brilliant idea in the moment...

But you should REALLY give your LC objects and array keys some more desciptive names! 8)
And you can save some typing:
...
## get the dgDataOfIndex[tIndexRow] of group "DataGrid1"
## put it into tData
## Do not use IT if not neccessary!
put the dgDataOfIndex[tIndexRow] of group "DataGrid1" into tData
...


Best

Klaus

JosepM
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 344
Joined: Tue Jul 20, 2010 12:40 pm

Re: Delayed Image Load with DataGrid

Post by JosepM » Sun Jul 06, 2014 7:44 pm

Hi Klaus,

Code: Select all

command refreshDg pURL, pStatus, pData
   Global aData
         put aData[pURL]["Id_row"] into tIndexRow
         get the dgDataOfIndex[tIndexRow] of group "DataGrid1" 
         put it into tData
         
         put 1 into tData["Label 1"] 
         put URL pURL into tImageData
         put tImageData into tData["Label 2"] -- to test if the value is returned
         
         set the dgDataOfIndex [tIndexRow] of group "DataGrid1" to tData -- then pop it right back in, no changes needed.
end refreshDg

Code: Select all

on FillInData pDataArray
   Global aData
   
   set the text of field "Label" of me to pDataArray["label 4"]
   set the text of field "Label2" of me to pDataArray["label 3"]
   set the text of field "Label3" of me to pDataArray["label 5"]
   
   if pDataArray["Label 1"] is 1 then
      put pDataArray["label 2"] into img "f_image" of me
   else
      put img "NoImage" into img "f_image" of me -- otherwise put in a placeholder image
      put the dgindex of me into tIndex --grab the index
      
      put tIndex into aData[pDataArray["label 6"]]["Id_row"] --Store the index of the row
      load URL pDataArray["label 6"] with message "refreshDg" --load and call "refreshdg" which is a handler on the card
   end if
end FillInData
This code is working on devices, but the callbackmessage seems is diferent, "cached" on desktop and "donwloaded" on device. But seems don't work.
The names are temporary to test :)
If not get the array from it how then I can change the values? Is better put into an array directly?
How improve this? if you touch one element then load the detail image on card 2, but I don't know if the load URL can be improved.
Any idea?

Salut,
Josep M

Attach the stack to testing
Attachments
s_main_prestaboard_android.livecode 2.zip
(81.18 KiB) Downloaded 229 times

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Delayed Image Load with DataGrid

Post by Klaus » Mon Jul 07, 2014 12:45 pm

Hi Josep,
...but the callbackmessage seems is diferent, "cached" on desktop and "donwloaded" on device.
well, then script:

Code: Select all

...
switch pStatus
case "cached"
case "downloaded"
  ## do stuff here...
...
This code is working on devices, ... But seems don't work.
Now what? Does it work or not? Or only seems to work?

I downloaded your stack but lost all data in the datagrid after saving and reopening!?
Unfortunately you do not have any handler for this:
...
set the dgdata of grp "DataGrid1" to AnyDataArray
...


Best

Klaus

Post Reply