public ForumPostsPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; rftopic = new ForumsTopic(); mlibrary = new methodLibrary(); APILibrary = new Library_APICall(); rfpost = new ObservableCollection<ForumsPost>(); /*ReplyToPostBox.MaxHeight = ReplyToPostBox.Height; replybutton.MaxHeight = ReplyToPostBox.MaxHeight; replybutton.Height = ReplyToPostBox.Height;*/ }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); Frame rootFrame = Window.Current.Content as Frame; if (rootFrame.CanGoBack) { // If we have pages in our in-app backstack and have opted in to showing back, do so SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; } else { // Remove the UI from the title bar if there are no pages in our in-app back stack SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; } rftopic = (ForumsTopic)e.Parameter; pageTitle.Text = rftopic.title; var rftopicpost = rftopic.post; rfpost.Clear(); foreach(var rfp in rftopicpost) { rfpost.Add(rfp); } }
public static async Task<string> fetchForumTopics() { string hreftopics = "https://api.teamsnap.com/v3/forum_topics/search?team_id=" + teamid.ToString(); string hrefposts = "https://api.teamsnap.com/v3/forum_posts/search?team_id=" + teamid.ToString(); string access_token = (string)ApplicationData.Current.LocalSettings.Values["Tokens"]; string topics_resp = await APILibrary.apiCall(access_token, hreftopics); if (topics_resp == "fail") { return "networkProblem"; } string posts_resp = await APILibrary.apiCall(access_token, hrefposts); if (posts_resp == "fail") { return "networkProblem"; } rforumposts = forum_posts.forumpostsDataDeserializer(posts_resp); rforumtopics = forum_topics.forumtopicsDataDeserializer(topics_resp); Hashtable rforumposts_ht = new Hashtable(); Hashtable rforumtopics_ht = new Hashtable(); mlibrary.writeFile("forum_topics", topics_resp); mlibrary.writeFile("forum_posts", posts_resp); rforumdata.topics = new List<ForumsTopic>(); try { int len = 0; while (len < rforumtopics.collection.items.Count) { ForumsTopic rforumdatatopic = new ForumsTopic(); for (int i = 0; i < rforumtopics.collection.items[len].data.Count; i++) { if (!rforumtopics_ht.ContainsKey(rforumtopics.collection.items[len].data[i].name)) { rforumtopics_ht.Add(rforumtopics.collection.items[len].data[i].name, i); } } rforumdatatopic.forum_topic_id = (long)rforumtopics.collection.items[len].data[(int)rforumtopics_ht["id"]].value; rforumdatatopic.title = (string)rforumtopics.collection.items[len].data[(int)rforumtopics_ht["title"]].value; rforumdatatopic.post = new List<ForumsPost>(); int postslen = 0; while (postslen < rforumposts.collection.items.Count) { for (int i = 0; i < rforumposts.collection.items[postslen].data.Count; i++) { if (!rforumposts_ht.ContainsKey(rforumposts.collection.items[postslen].data[i].name)) rforumposts_ht.Add(rforumposts.collection.items[postslen].data[i].name, i); } if (postslen < 1) { rforumdatatopic.started_by = (string)rforumposts.collection.items[postslen].data[(int)rforumposts_ht["poster_name"]].value; } if (rforumdatatopic.forum_topic_id == (long)rforumposts.collection.items[postslen].data[(int)rforumposts_ht["forum_topic_id"]].value) { ForumsPost rforumdataposts = new ForumsPost(); rforumdataposts.forum_post_id = rforumposts.collection.items[postslen].data[(int)rforumposts_ht["id"]].value == null ? 0 : (long)rforumposts.collection.items[postslen].data[(int)rforumposts_ht["id"]].value; rforumdataposts.member_id = rforumposts.collection.items[postslen].data[(int)rforumposts_ht["member_id"]].value == null ? 0 : (long)rforumposts.collection.items[postslen].data[(int)rforumposts_ht["member_id"]].value; rforumdataposts.message = methodLibrary.StripTagsRegexCompiled((string)rforumposts.collection.items[postslen].data[(int)rforumposts_ht["message"]].value); rforumdataposts.poster_name = (string)rforumposts.collection.items[postslen].data[(int)rforumposts_ht["poster_name"]].value; DateTime updated_at = rforumposts.collection.items[postslen].data[(int)rforumposts_ht["updated_at"]].value == null ? DateTime.MinValue : (DateTime)rforumposts.collection.items[postslen].data[(int)rforumposts_ht["updated_at"]].value; updated_at = updated_at.ToLocalTime(); rforumdatatopic.last_updated_at = updated_at == null ? DateTime.MinValue : (DateTime)updated_at; rforumdataposts.updated_at = String.Format("{0:ddd, MMM d, hh:mm tt}", updated_at); rforumdatatopic.last_updated_at_string = rforumdataposts.updated_at; rforumdatatopic.post.Add(rforumdataposts); } if (rforumdatatopic.post.Count == 1) { rforumdatatopic.replies = "No replies"; } else if (rforumdatatopic.post.Count == 2) { rforumdatatopic.replies = (rforumdatatopic.post.Count - 1).ToString() + " reply"; } else { rforumdatatopic.replies = (rforumdatatopic.post.Count - 1).ToString() + " replies"; } rforumposts_ht.Clear(); postslen++; } rforumdata.topics.Add(rforumdatatopic); rforumtopics_ht.Clear(); len++; } } catch (Exception ex) { Debug.WriteLine("Exception returned : " + ex); return "noData"; } return "allGood"; }