I'm currently building a media feed in C# Xamarin.
The media feed is an observablecollection of data models for individual posts.
The API I'm using is fairly limited, so I can't properly query to specify the data I want, which means I end up with a lot of data. To make sure users actually get enough content, my collection needs to request anywhere between 100 and 500 elements.
This makes loading times extremely long, and I wish to yield return the collection to continuously update the media feed while retreiving data from the API.
The feed manager
public static async Task<ObservableCollection<PostPresenter>> GetFeed(ApiClient client, string account, int limit = 100) { var feed = new ObservableCollection<PostPresenter>(); var feedResult = await ApiClient.FeedClient.GetFeed(account, limit: limit); if (feedResult != null) { foreach (var feedObj in feedResult.Result) { if (feedObj != null) { var comment = feedObj; feed.Add(new PostPresenter() { Username = comment.Author, Description = comment?.Title ?? comment.Body?.TruncateString(15) ?? "", Media = comment.JsonMetadata.Image != null ? comment?.JsonMetadata?.Image.FirstOrDefault() : null, Tags = comment?.JsonMetadata?.Tags.ToList() ?? new List<string> { "" }, PostTime = comment?.Created.ToString(), Permlink = comment.Permlink, EntryId = feedObj.Id }); } } } foreach (var testObj in feed) { await GetFeedMetadata(client, testObj); } return feed; }
The mainpage/feed page
var tempFeedEntries = await FeedManager.GetFeed(User.ApiClient, User.Username); //var tempFeedEntries = await FeedManager.GetAllFeedData(User.ApiClient, Feed); if (tempFeedEntries != null) { foreach(var tempFeedEntry in tempFeedEntries) { Feed.Add(tempFeedEntry); IsLoading = false; FeedListViewLoading.IsRunning = false; FeedListViewLoading.IsRunning = false; await FeedManager.GetAllFeedData(User.ApiClient, tempFeedEntries); FeedListView.ItemsSource = Feed; } }
How can I return a temporary copy of the collection or posts to fill the feed without waiting for every element to be loaded?