async Task <ViewModelBase> MapThing(Thing thing, ViewModelBase parent) { if (thing.Data is More) { var depth = 0; if (parent is CommentViewModel) { depth = ((CommentViewModel)parent).Depth + 1; } var more = new MoreViewModel(_baconProvider, ((More)thing.Data).Children, _targetName, _subreddit, RunLoadMore, parent as CommentViewModel, depth); more.Parent = parent as CommentViewModel; return(more); } else if (thing.Data is Link) { return(new LinkViewModel(thing, _baconProvider)); } else if (thing.Data is Comment) { var oddNesting = false; var depth = 0; if (parent is CommentViewModel) { oddNesting = !((CommentViewModel)parent).OddNesting; depth = ((CommentViewModel)parent).Depth + 1; } var commentViewModel = new CommentViewModel(_baconProvider, thing, ((Comment)thing.Data).LinkId, oddNesting, depth); commentViewModel.Replies = new ObservableCollection <ViewModelBase>(await MapListing(((Comment)thing.Data).Replies, commentViewModel)); commentViewModel.Parent = parent as CommentViewModel; return(commentViewModel); } else { return(null); } }
public MoreInfoWindow(ProcessList process) { InitializeComponent(); DataContext = new MoreViewModel(process); }
public async Task LoadMore(MoreViewModel target) { List<ViewModelBase> flatChilden = new List<ViewModelBase>(); string moreId = null; await SnooStreamViewModel.NotificationService.Report("loading more comments", async () => { var listing = await SnooStreamViewModel.RedditService.GetMoreOnListing(new More { Children = target.Ids, ParentId = target.ParentId, Count = target.Count }, Link.Link.Id, Link.Link.Subreddit); lock(this) { FixupParentage(listing); var firstChild = listing.Data.Children.FirstOrDefault(thing => thing.Data is Comment); if(firstChild == null) return; var parentId = ((Comment)firstChild.Data).ParentId; CommentShell parentShell; if (!_comments.TryGetValue(parentId.Replace("t1_", ""), out parentShell)) { parentShell = null; } MergeComments(parentShell, listing.Data.Children, parentShell == null ? 0 : parentShell.Comment.Depth + 1); moreId = ((Comment)firstChild.Data).Id; InsertIntoFlatList(moreId, flatChilden); foreach (var child in flatChilden) { _knownUnloaded.Remove(GetId(child)); } } }); if (moreId != null) MergeDisplayChildren(flatChilden, target.Ids); else FlatComments.Remove(target); }
private void MergeComments(CommentShell parent, IEnumerable<Thing> things, int depth = 0) { CommentShell priorSibling = parent != null ? LastChild(parent) : null; MoreViewModel priorMore = null; foreach (var child in things) { if(child.Data is More && ((More)child.Data).Children.Count > 0) { if(priorMore != null) { priorMore.Ids.AddRange(((More)child.Data).Children); priorMore.Count += ((More)child.Data).Count; } else { var firstId = ((More)child.Data).Children.First(); if (priorSibling == null) //need to attach to parent { parent.FirstChild = firstId; } else { priorSibling.NextSibling = firstId; } if (!_knownUnloaded.ContainsKey(firstId)) { priorMore = new MoreViewModel(this, parent != null ? parent.Id : null, firstId, ((More)child.Data).Children,((More)child.Data).Count, depth ); _knownUnloaded.Add(firstId, priorMore); } } } else if (child.Data is Comment) { priorMore = null; var commentId = ((Comment)child.Data).Id; if (priorSibling == null && parent == null) { if (_firstChild != null) { priorSibling = LastSibling(_comments[_firstChild]); } else { _firstChild = commentId; } } if (priorSibling == null && parent != null) //need to attach to parent { parent.FirstChild = commentId; } else if (priorSibling != null) { priorSibling.NextSibling = commentId; } if (!_comments.ContainsKey(commentId)) { priorSibling = MakeCommentShell(child.Data as Comment, depth, priorSibling); _comments.Add(commentId, priorSibling); } else { var current = _comments[commentId]; current.PriorSibling = priorSibling != null ? priorSibling.Id : null; current.NextSibling = null; priorSibling = current; MergeComment(priorSibling, child.Data as Comment); } var replies = ((Comment)child.Data).Replies; if (replies != null) MergeComments(priorSibling, replies.Data.Children, depth + 1); } } }
public MorePage() { InitializeComponent(); ViewModel = new MoreViewModel(); BindingContext = ViewModel; }
public More(string id) { InitializeComponent(); this.BindingContext = moreViewModel = new MoreViewModel(id); }