Jump to content
View in the app

A better way to browse. Learn more.

FGX Native

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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 by Luke

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

  • Author

Hi Knsg12,
you are right...
AlbumId is not unique... excuse me.
I check better if now it is solved.

Thanks a lot,
Luke.

  • 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.
 

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.

  • 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

Similar Content

Recently Browsing 0

  • No registered users viewing this page.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.