private async void mnuUnsubscribe_Click(object sender, RoutedEventArgs e) { FrameworkElement fe = sender as FrameworkElement; if (fe == null) { return; } if (fe.Tag is WhirlPoolAPIData.WATCHED) { WhirlPoolAPIData.WATCHED watched = (WhirlPoolAPIData.WATCHED)fe.Tag; await WhirlPoolAPIClient.UnsubscribeThreadAsync(watched.ID, true); } }
private async void Watched_Tapped(object sender, TappedRoutedEventArgs e) { FrameworkElement fe = e.OriginalSource as FrameworkElement; if (fe == null) { return; } if (fe.DataContext is WhirlPoolAPIData.WATCHED) { WhirlPoolAPIData.WATCHED watched = (WhirlPoolAPIData.WATCHED)fe.DataContext; String url = string.Format(@"http://forums.whirlpool.net.au/forum-replies.cfm?t={0}&p={1}&#r{2}", watched.ID, watched.LASTPAGE, watched.LASTREAD); var uri = new Uri(url); var success = await Windows.System.Launcher.LaunchUriAsync(uri); if (success) { await WhirlPoolAPIClient.MarkThreadReadAsync(watched.ID, true); } } else if (fe.DataContext is WhirlPoolAPIData.RECENT) { WhirlPoolAPIData.RECENT recent = fe.DataContext as WhirlPoolAPIData.RECENT; String url = string.Format(@"http://forums.whirlpool.net.au/forum-replies.cfm?t={0}&p=-1&#bottom", recent.ID); var uri = new Uri(url); var success = await Windows.System.Launcher.LaunchUriAsync(uri); } else if (fe.Tag != null) { // Forum Header Click String url = String.Format(@"https://forums.whirlpool.net.au/forum/{0}", fe.Tag); var uri = new Uri(url); var success = await Windows.System.Launcher.LaunchUriAsync(uri); } }
static public bool UpdateUIData(WhirlPoolAPIData.RootObject root) { synchronizationContext.Post(new SendOrPostCallback(o => { var r = (WhirlPoolAPIData.RootObject)o; // Watched if (r.WATCHED != null) { // new IEnumerable <WatchedThreads> watched = from item in r.WATCHED group item by item.FORUM_NAME into threadGroup select new WatchedThreads(threadGroup) { Forum = threadGroup.Key, forumId = threadGroup.ElementAtOrDefault(0).FORUM_ID }; var grpWatched = new ThreadForumGroups(watched); var cvsWatched = (CollectionViewSource)Application.Current.Resources["srcWatched"]; if (cvsWatched.Source == null) { cvsWatched.Source = grpWatched; } else { // Merge var current = (ThreadForumGroups)cvsWatched.Source; // Update all thread groups and threads for (int gIdx = current.Count - 1; gIdx >= 0; gIdx--) { WatchedThreads grp = current[gIdx]; var _grp = grpWatched.SingleOrDefault(g => g.forumId == grp.forumId); if (_grp == null) { // group no longer exists current.RemoveAt(gIdx); continue; } // Check exisiting threads in group for (var tIdx = grp.Count - 1; tIdx >= 0; tIdx--) { WhirlPoolAPIData.WATCHED wItem = grp[tIdx]; var _w = _grp.SingleOrDefault(w => w.ID == wItem.ID); if (_w == null) { // Remove thread grp.RemoveAt(tIdx); continue; } // Update? if (!wItem.Equals(_w)) { grp[tIdx] = _w; } } // Check for new Threads for (var tIdx = _grp.Count - 1; tIdx >= 0; tIdx--) { WhirlPoolAPIData.WATCHED wItem = _grp[tIdx]; var _w = grp.SingleOrDefault(w => w.ID == wItem.ID); if (_w == null) { // Add thread grp.Add(wItem); } } } // Check for new Groups for (int gIdx = grpWatched.Count - 1; gIdx >= 0; gIdx--) { WatchedThreads grp = grpWatched[gIdx]; var _grp = current.SingleOrDefault(g => g.forumId == grp.forumId); if (_grp == null) { // Add current.Add(grp); } } } } // news if (r.NEWS != null) { IEnumerable <NewsItems> news = from item in r.NEWS group item by item.DATE_D.Date into newsGroup select new NewsItems(newsGroup) { Date = newsGroup.Key }; var cvsNews = (CollectionViewSource)Application.Current.Resources["srcNews"]; cvsNews.Source = new NewsDateGroup(news); } // Recent if (r.RECENT != null) { // new IEnumerable <RecentThreads> recent = from item in r.RECENT group item by item.FORUM_NAME into threadGroup select new RecentThreads(threadGroup) { Forum = threadGroup.Key, forumId = threadGroup.ElementAtOrDefault(0).FORUM_ID }; var grpRecent = new RecentForumGroups(recent); var cvsRecent = (CollectionViewSource)Application.Current.Resources["srcRecent"]; cvsRecent.Source = grpRecent; } }), root); return(true); }