Jump to content

TfgCollectionView : Fetching thumbnail images from web


Recommended Posts

Hi All,
i'm testing tfgCollectionView with this rest resource : http://jsonplaceholder.typicode.com/photos

In this test my CollectionView Style has 1 fgImage and 1 fgLabel.
I get the RestResouce with a TRESTRequest.ExecuteAsync and it works perfectly.
When i've the ExecuteAsync CallBack i parse the JSON output string and i fill my Photos collection (TList).
I do this step with a separate Task because i've 5000 items ( more or less).

When i link data to the CollectionView i call fgCollectionViewGetItemCount and fgCollectionView1BindItem.
If i bind only the fgLabel all works perfectly.
My problem is link the tfgImage to the thumbnail.
I post my code:

procedure TFramePhoto.fgCollectionView1BindItem(Sender: TObject;const AIndex: Integer; const AStyle: string; const AItem: TfgItemWrapper);
VAR Item:TPhotoData;

    AItem.GetControlByLookupName<TfgLabel>('LblTitle').Text := Item.Ftitle;
    TfgAssetsManager.Current.AddBitmapFromUrlAsync(Item.FalbumId, Item.FthumbnailUrl,
    procedure (const AResultCode: Integer; const AResultMessage: string) begin
      AItem.GetControlByLookupName<TfgImage>('ImgAlbum').ImageName := Item.FalbumId;

    FGX.Log.TfgLog.Log(TfgLogLevel.Debug,'fgCollectionView1BindItem ' + e.Message);

Actually i'm saving the images in assets but i think it is a bad idea...
Can you suggest a best practice for this scenario ?

Thanks a lot guys,
Best Regards.



Edited by Luke
Link to comment
Share on other sites

if not TfgAssetsManager.Current.Contains(Item.FalbumId) then
   TfgAssetsManager.Current.AddBitmapFromUrlAsync(Item.FalbumId, Item.FthumbnailUrl);
AItem.GetControlByLookupName<TfgImage>('ImgAlbum').ImageName := Item.FalbumId;

Try it!

I think Item.FalbumId not uniq field for records, it needs to be replaced by Item.Id.

Edited by knsg12
  • Like 2
Link to comment
Share on other sites

Hi All,
now my demo works better, thanks Knsg12.
However i've seen that TfgAssetsManager.Current.AddBitmapFromUrlAsync take a lot of time ( 20 - 30 seconds ) to download the thumbnail from  'https://via.placeholder.com/150/92c952'.

I've tried also to update your demo AsyncBitmapAssetDemo and i've replaced your sample url with mine.
The first execution take 20 second, the nexts less than 1 second.
How could be possibile ?
Many thanks guys for your support.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...