public async Task<List<ElectionArticle>> GetElectionArticlesAfterAsync (ElectionArticle latestArticle, Priority priority) { List<ElectionArticle> articles = new List<ElectionArticle>(); Task<List<ElectionArticle>> getArticlesTask; var timestamp = latestArticle.CreatedAt.ToUnixTimestamp (); switch (priority) { case Priority.Background: getArticlesTask = _apiService.Background.GetElectionArticlesAfter (timestamp, ApiService.Device); break; case Priority.UserInitiated: getArticlesTask = _apiService.UserInitiated.GetElectionArticlesAfter (timestamp, ApiService.Device); break; case Priority.Speculative: getArticlesTask = _apiService.Speculative.GetElectionArticlesAfter (timestamp, ApiService.Device); break; default: getArticlesTask = _apiService.UserInitiated.GetElectionArticlesAfter (timestamp, ApiService.Device); break; } if (CrossConnectivity.Current.IsConnected) { articles = await Policy .Handle<WebException> () .WaitAndRetryAsync (2, retryAttempt => TimeSpan.FromSeconds (Math.Pow (2, retryAttempt))) .ExecuteAsync(async () => await getArticlesTask); } return articles.Select(article => { if (article.Type == ElectionArticle.MediaType.Video) { article.VideoImageUrl = YoutubeHelper.GetThumbnailUrl(ApiService.Device, article.VideoUrl); article.VideoId = YoutubeHelper.GetVideoId(article.VideoUrl); } else if (article.Type == ElectionArticle.MediaType.Image) { article.ImageUrl = ApiService.ApiBaseAddress + article.ImageUrl; } return article; }).ToList(); }
public ElectionArticleItemViewModel(ElectionArticle model, Action<ElectionArticleItemViewModel> gotoCommand, bool addIndex = false) { Model = model; Id = model.Id; Title = model.Title; Body = model.Body; MediaType = model.Type; VideoUrl = model.VideoUrl; VideoImageUrl = model.VideoImageUrl; VideoId = model.VideoId; ImageUrl = model.ImageUrl; CreatedAt = model.CreatedAt; GoToCommand = ReactiveCommand.Create (); GoToCommand.Subscribe (x => gotoCommand (this)); if (addIndex) { _latestIndex += 1; Index = _latestIndex; } }