private static Element CreateElement(Tuple <EventModel, BaseEventsViewModel.EventBlock> e) { try { if (e.Item2 == null) { return(null); } var imgKey = ChooseImage(e.Item1); var img = Octicon.Alert; if (_eventToImage.ContainsKey(imgKey)) { img = _eventToImage[imgKey]; } var avatar = e.Item1.Actor != null ? e.Item1.Actor.AvatarUrl : null; var headerBlocks = new List <NewsFeedElement.TextBlock>(); foreach (var h in e.Item2.Header) { Action act = null; var anchorBlock = h as BaseEventsViewModel.AnchorBlock; if (anchorBlock != null) { act = anchorBlock.Tapped; } headerBlocks.Add(new NewsFeedElement.TextBlock(h.Text, act)); } var bodyBlocks = new List <NewsFeedElement.TextBlock>(); foreach (var h in e.Item2.Body) { Action act = null; var anchorBlock = h as BaseEventsViewModel.AnchorBlock; if (anchorBlock != null) { act = anchorBlock.Tapped; } var block = new NewsFeedElement.TextBlock(h.Text, act); bodyBlocks.Add(block); } var weakTapped = new WeakReference <Action>(e.Item2.Tapped); var githubAvatar = new GitHubAvatar(avatar).ToUri(64)?.AbsoluteUri; return(new NewsFeedElement(githubAvatar, e.Item1.CreatedAt, headerBlocks, bodyBlocks, img.ToImage(), () => weakTapped.Get()?.Invoke(), e.Item2.Multilined)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to add event: " + ex.Message); return(null); } }
private static Element CreateElement(Tuple <EventModel, BaseEventsViewModel.EventBlock> e) { try { if (e.Item2 == null) { return(null); } var img = ChooseImage(e.Item1); var avatarUrl = e.Item1?.User?.Avatar; var avatar = new Avatar(avatarUrl); var headerBlocks = new System.Collections.Generic.List <NewsFeedElement.TextBlock>(); foreach (var h in e.Item2.Header) { Action act = null; var anchorBlock = h as BaseEventsViewModel.AnchorBlock; if (anchorBlock != null) { act = anchorBlock.Tapped; } headerBlocks.Add(new NewsFeedElement.TextBlock(h.Text, act)); } var bodyBlocks = new System.Collections.Generic.List <NewsFeedElement.TextBlock>(); foreach (var h in e.Item2.Body) { Action act = null; var anchorBlock = h as BaseEventsViewModel.AnchorBlock; if (anchorBlock != null) { act = anchorBlock.Tapped; } var block = new NewsFeedElement.TextBlock(h.Text, act); if (act == null) { block.Color = UIColor.DarkGray; } bodyBlocks.Add(block); } return(new NewsFeedElement(avatar.ToUrl(), e.Item1.UtcCreatedOn, headerBlocks, bodyBlocks, img, e.Item2.Tapped)); } catch (Exception ex) { Utilities.LogException("Unable to add event", ex); return(null); } }