Posted July 13, 20205 yr 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; begin TRY Item:=RestPhotos.Items[AIndex]; 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; end); EXCEPT ON E:EXCEPTION DO FGX.Log.TfgLog.Log(TfgLogLevel.Debug,'fgCollectionView1BindItem ' + e.Message); END; end; 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 July 13, 20205 yr by Luke
July 13, 20205 yr 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 July 13, 20205 yr by knsg12
July 13, 20205 yr Author Hi Knsg12, you are right... AlbumId is not unique... excuse me. I check better if now it is solved. Thanks a lot, Luke.
July 13, 20205 yr Author 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.
July 13, 20205 yr When you query a picture for the first time, it uploads it and save to Assets, the next time it will no longer upload a picture. And your fgimage always geting pic from Assets.
July 15, 20205 yr Author Hi Knsg12, thanks for support. I will do more tests and i will close the post if solved. Thanks a lot.
Create an account or sign in to comment