private async void OnPost_Deleted(object sender, RoutedEventArgs e) { _autoUpdateCountTimer.Stop(); PostWidget post = sender as PostWidget; if (post == null) { _autoUpdateCountTimer.Start(); return; } if (ViewModel.LastNewHeadPostId == post.CurrentPostData.Id) { await UpdatePosts() .ConfigureAwait(true); _autoUpdateCountTimer.Start(); return; } lstPosts.Children.Remove(post); --ViewModel.Offset; if (lstPosts.Children.Count == 0) { IsEmpty = true; } _autoUpdateCountTimer.Start(); }
protected override void OnAppearing() { base.OnAppearing(); SubredditWidget.PostSelected += SubredditWidget_PostSelected; PostWidget.OnAppearing(); SubredditWidget.OnAppearing(); }
public Task AddMorePosts(List <PostSchema> posts) { return(Task.Run(async() => { foreach (var post in posts) { await Dispatcher.InvokeAsync(() => { PostWidget widget = new PostWidget { CurrentPostData = post, TextSizeLimit = true }; widget.PostClick += OnPost_Click; widget.PostDelete += OnPost_Deleted; lstPosts.Children.Add(widget); }).Task.ConfigureAwait(false); } Dispatcher.Invoke(() => { ViewModel.Offset += posts.Count; }); })); }
public async Task UpdatePosts() { _autoUpdateCountTimer.Stop(); btnRefresh.IsEnabled = false; await ShowLoadingGrid(true) .ConfigureAwait(true); ViewModel.NewPostsCount = 0; svPosts.IsEnabled = false; foreach (var post in lstPosts.Children) { PostWidget postWidget = post as PostWidget; if (postWidget == null) { continue; } ImageBehavior.SetAnimatedSource(postWidget.PostImage, null); } lstPosts.Children.Clear(); svPosts.ScrollToHorizontalOffset(0); ViewModel.Offset = 0; IsEmpty = true; UpdateLayout(); GC.WaitForPendingFinalizers(); GC.Collect(); await LoadMorePosts() .ConfigureAwait(true); if (lstPosts.Children.Count == 0) { ViewModel.LastNewHeadPostId = -1; } else { ViewModel.LastNewHeadPostId = (lstPosts.Children[0] as PostWidget)? .CurrentPostData.Id ?? -1; IsEmpty = false; } svPosts.IsEnabled = true; await ShowLoadingGrid(false) .ConfigureAwait(true); btnRefresh.IsEnabled = true; _autoUpdateCountTimer.Start(); }
async Task <bool> UpdatePosts(PostRequest filters) { postsPanel.Items.Clear(); var postsResponse = await PostAPI.GetAllPosts(filters, AppPersistent.UserToken); if (postsResponse == null) { return(false); } foreach (var post in postsResponse.data) { PostWidget widget = new PostWidget() { PostText = post.text, ImageURL = post.attachments[0].photo.photo_medium, CurrentPostData = post }; postsPanel.Items.Add(widget); } return(true); }