public async Task <ObservableCollection <ForumThreadEntity> > GetForumThreads(ForumEntity forumCategory, int page) { // TODO: Remove parsing logic from managers. I don't think they have a place here... string url = forumCategory.Location + string.Format(Constants.PAGE_NUMBER, page); HtmlDocument doc = (await _webManager.GetData(url)).Document; HtmlNode bodyNode = doc.DocumentNode.Descendants("body").First(); int forumId = Convert.ToInt32(bodyNode.GetAttributeValue("data-forum", string.Empty)); HtmlNode forumNode = doc.DocumentNode.Descendants() .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("threadlist")); var forumThreadList = new ObservableCollection <ForumThreadEntity>(); foreach ( HtmlNode threadNode in forumNode.Descendants("tr") .Where(node => node.GetAttributeValue("class", string.Empty).StartsWith("thread"))) { var threadEntity = new ForumThreadEntity(); threadEntity.Parse(threadNode); threadEntity.ForumId = forumId; forumThreadList.Add(threadEntity); } return(forumThreadList); }
public static void CreateToastNotification(ForumThreadEntity forumThread) { XmlDocument notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01); XmlNodeList toastElements = notificationXml.GetElementsByTagName("text"); toastElements[0].AppendChild(notificationXml.CreateTextNode(string.Format("\"{0}\" has {1} unread replies!", forumThread.Name, forumThread.RepliesSinceLastOpened))); XmlNodeList imageElement = notificationXml.GetElementsByTagName("image"); string imageName = string.Empty; if (string.IsNullOrEmpty(imageName)) { imageName = @"Assets/Logo.scale-100.png"; } imageElement[0].Attributes[1].NodeValue = imageName; IXmlNode toastNode = notificationXml.SelectSingleNode("/toast"); string test = "{" + string.Format("type:'toast'") + "}"; var xmlElement = (XmlElement)toastNode; if (xmlElement != null) { xmlElement.SetAttribute("launch", test); } var toastNotification = new ToastNotification(notificationXml); ToastNotificationManager.CreateToastNotifier().Show(toastNotification); }
public async Task SaveThreadReplyDraft(string replyText, ForumThreadEntity thread) { using (var db = new DataSource()) { var savedDraft = await db.DraftRepository.Items.Where(node => node.ThreadId == thread.ThreadId).FirstOrDefaultAsync(); if (savedDraft == null) { savedDraft = new DraftEntity() { ThreadId = thread.ThreadId, Draft = replyText, ForumId = thread.ForumId, NewThread = false, Id = thread.ThreadId }; await db.DraftRepository.Create(savedDraft); return; } savedDraft.Draft = replyText; await db.DraftRepository.Update(savedDraft); } }
public async Task <ForumThreadEntity> GetThread(string url) { var forumThread = new ForumThreadEntity(); WebManager.Result result = await _webManager.GetData(url); HtmlDocument doc = result.Document; try { forumThread.ParseFromThread(doc); } catch (Exception) { return(null); } var query = Extensions.ParseQueryString(url); if (!query.ContainsKey("postid")) { return(forumThread); } // If we are going to a post, it won't use #pti but instead uses the post id. forumThread.ScrollToPost = Convert.ToInt32(query["postid"]); forumThread.ScrollToPostString = "#post" + query["postid"]; return(forumThread); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper" /> /// </param> /// <param name="e"> /// Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited. /// </param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { loadingProgressBar.Visibility = Visibility.Visible; _forumThread = (ForumThreadEntity)e.NavigationParameter; pageTitle.Text = _forumThread.Name; _threadPosts = await _postManager.GetThreadPosts(_forumThread); CurrentPageSelector.ItemsSource = Enumerable.Range(1, _forumThread.TotalPages).ToArray(); CurrentPageSelector.SelectedValue = _forumThread.CurrentPage; BackButton.IsEnabled = _forumThread.CurrentPage > 1; ForwardButton.IsEnabled = _forumThread.TotalPages != _forumThread.CurrentPage; ReplyButton.IsEnabled = !_forumThread.IsLocked; DefaultViewModel["Posts"] = _threadPosts; if (_forumThread.ScrollToPost > 0) { ThreadListFullScreen.ScrollIntoView(_threadPosts[_forumThread.ScrollToPost]); } loadingProgressBar.Visibility = Visibility.Collapsed; // TODO: Remove duplicate buttons and find a better way to handle navigation BackButtonSnap.IsEnabled = _forumThread.CurrentPage > 1; ForwardButtonSnap.IsEnabled = _forumThread.TotalPages != _forumThread.CurrentPage; CurrentPageSelectorSnap.ItemsSource = Enumerable.Range(1, _forumThread.TotalPages).ToArray(); CurrentPageSelectorSnap.SelectedValue = _forumThread.CurrentPage; }
public async override void Execute(object parameter) { var args = parameter as ItemClickEventArgs; if (args == null) { AwfulDebugger.SendMessageDialogAsync("Thread navigation failed!:(", new Exception("Arguments are null")); return; } var thread = args.ClickedItem as SearchEntity; if (thread == null) { return; } App.RootFrame.Navigate(typeof(ThreadPage)); Locator.ViewModels.ThreadPageVm.IsLoading = true; var newThreadEntity = new ForumThreadEntity() { Location = Constants.BaseUrl + thread.ThreadLink, ImageIconLocation = "/Assets/ThreadTags/noicon.png" }; Locator.ViewModels.ThreadPageVm.ForumThreadEntity = newThreadEntity; await Locator.ViewModels.ThreadPageVm.GetForumPostsAsync(); }
public void Location_Is_Parsed_Successfully() { ForumThreadEntity thread = ParseEntity(DefaultThread); Assert.AreEqual("http://forums.somethingawful.com/showthread.php?threadid=3580313&perpage=40", thread.Location); }
public async Task <bool> Initialize(string jsonObjectString) { IsLoading = true; long threadId = 0; var replyManager = new ReplyManager(); try { _forumThread = JsonConvert.DeserializeObject <ForumThreadEntity>(jsonObjectString); } catch (Exception) { threadId = Convert.ToInt64(jsonObjectString); } try { if (_forumThread != null) { ForumReplyEntity = await replyManager.GetReplyCookies(_forumThread); } else { ForumReplyEntity = await replyManager.GetReplyCookies(threadId); } } catch (Exception ex) { ForumReplyEntity = null; } IsLoading = false; return(ForumReplyEntity != null); }
public async Task <DraftEntity> LoadThreadDraftEntity(ForumThreadEntity thread) { using (var db = new DataSource()) { return(await db.DraftRepository.Items.Where(node => node.ThreadId == thread.ThreadId).FirstOrDefaultAsync()); } }
public void ImageIconLocation_Is_Parsed_Successfully() { ForumThreadEntity thread = ParseEntity(DefaultThread); Assert.AreEqual("http://fi.somethingawful.com/forums/posticons/icons-08/drugs.png#122", thread.ImageIconLocation); }
public async Task <ObservableCollection <ForumThreadEntity> > GetBookmarks(ForumEntity forumCategory, int page) { var forumThreadList = new ObservableCollection <ForumThreadEntity>(); String url = Constants.BOOKMARKS_URL; if (forumCategory.CurrentPage >= 0) { url = Constants.BOOKMARKS_URL + string.Format(Constants.PAGE_NUMBER, page); } HtmlDocument doc = (await _webManager.GetData(url)).Document; HtmlNode forumNode = doc.DocumentNode.Descendants() .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("threadlist")); foreach ( HtmlNode threadNode in forumNode.Descendants("tr") .Where(node => node.GetAttributeValue("class", string.Empty).StartsWith("thread"))) { var threadEntity = new ForumThreadEntity(); threadEntity.Parse(threadNode); threadEntity.IsBookmark = true; forumThreadList.Add(threadEntity); } return(forumThreadList); }
public async Task AddThreadToTabListAsync(ForumThreadEntity thread) { using (var db = new DataSource()) { await db.TabRepository.Create(thread); } }
public static void CreateToastNotification(ForumThreadEntity forumThread) { string replyText = forumThread.RepliesSinceLastOpened > 1 ? " has {0} replies." : " has {0} reply."; XmlDocument notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02); XmlNodeList toastElements = notificationXml.GetElementsByTagName("text"); toastElements[0].AppendChild( notificationXml.CreateTextNode(string.Format("\"{0}\"", forumThread.Name))); toastElements[1].AppendChild( notificationXml.CreateTextNode(string.Format(replyText, forumThread.RepliesSinceLastOpened))); XmlNodeList imageElement = notificationXml.GetElementsByTagName("image"); string imageName = string.Empty; if (string.IsNullOrEmpty(imageName)) { imageName = forumThread.ImageIconLocation; } imageElement[0].Attributes[1].NodeValue = imageName; IXmlNode toastNode = notificationXml.SelectSingleNode("/toast"); string test = "{" + string.Format("type:'toast', 'threadId':{0}", forumThread.ThreadId) + "}"; var xmlElement = (XmlElement)toastNode; if (xmlElement != null) xmlElement.SetAttribute("launch", test); var toastNotification = new ToastNotification(notificationXml); var nameProperty = toastNotification.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "Tag"); if (nameProperty != null) { nameProperty.SetValue(toastNotification, forumThread.ThreadId.ToString()); } ToastNotificationManager.CreateToastNotifier().Show(toastNotification); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="Common.NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { if (e.NavigationParameter == null) { return; } try { var threadId = (long)e.NavigationParameter; var bookmarkdata = new BookmarkDataSource(); _lastSelectedItem = await bookmarkdata.BookmarkForumRepository.Items.Where(node => node.ThreadId == threadId).FirstOrDefaultAsync(); if (_lastSelectedItem != null) { Locator.ViewModels.BookmarksPageVm.NavigateToThreadPageViaToastCommand.Execute(_lastSelectedItem); if (AdaptiveStates.CurrentState == NarrowState) { Frame.Navigate(typeof(ThreadPage), null, new DrillInNavigationTransitionInfo()); } } } catch (Exception ex) { AwfulDebugger.SendMessageDialogAsync("Failed to load Bookmarks page", ex); } }
public async Task RemoveThreadFromTabListAsync(ForumThreadEntity thread) { using (var db = new DataSource()) { await db.TabRepository.Delete(thread); } }
public async Task SetThreadNotified(ForumThreadEntity thread) { using (var bds = new BookmarkDataSource()) { thread.IsNotified = !thread.IsNotified; await bds.BookmarkForumRepository.Update(thread); } }
public async Task <bool> DoesTabExist(ForumThreadEntity thread) { using (var db = new DataSource()) { var thread2 = db.TabRepository.Items.Where(node => node.ThreadId == thread.ThreadId); var test = await thread2.FirstOrDefaultAsync(); return(test != null); } }
private ForumThreadEntity ParseEntity(string html) { var doc = new HtmlDocument(); doc.LoadHtml(html); var thread = new ForumThreadEntity(); thread.Parse(doc.DocumentNode.Descendants("tr").First(node => node.GetAttributeValue("class", string.Empty).StartsWith("thread"))); return(thread); }
public object Convert(object value, Type targetType, object parameter, string language) { ForumThreadEntity thread = value as ForumThreadEntity; if (thread == null) { return(false); } return(thread.TotalPages != thread.CurrentPage); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper" /> /// </param> /// <param name="e"> /// Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited. /// </param> private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { _forumPost = e.NavigationParameter as ForumPostEntity; if (_forumPost != null) { ReplyText.Text = string.Format(Constants.QUOTE_EXP, _forumPost.User.Username, _forumPost.PostId, _forumPost.PostFormatted); } _forumThread = e.NavigationParameter as ForumThreadEntity; }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { var jsonObjectString = (string)e.NavigationParameter; _forumThread = JsonConvert.DeserializeObject <ForumThreadEntity>(jsonObjectString); if (_forumThread == null) { return; } await _vm.GetForumPosts(_forumThread); }
private void PopularThreadList_ItemClick(object sender, ItemClickEventArgs e) { var threadEntity = e.ClickedItem as PopularThreadsTrendsEntity; var thread = new ForumThreadEntity(); if (threadEntity != null) { string title = string.IsNullOrEmpty(threadEntity.Title) ? string.Empty : threadEntity.Title; thread.ParseFromPopularThread(threadEntity.Title, threadEntity.Id); Frame.Navigate(typeof(ThreadPage), thread); } }
/// The methods provided in this section are simply used to allow /// NavigationHelper to respond to the page's navigation methods. /// /// Page specific logic should be placed in event handlers for the /// <see cref="GridCS.Common.NavigationHelper.LoadState" /> /// and /// <see cref="GridCS.Common.NavigationHelper.SaveState" /> /// . /// The navigation parameter is available in the LoadState method /// in addition to page state preserved during an earlier session. protected override void OnNavigatedTo(NavigationEventArgs e) { _vm.Html = string.Empty; _forumThread = Locator.ViewModels.ThreadVm.ForumThreadEntity; _navigationHelper.OnNavigatedTo(e); Rect bounds = Window.Current.Bounds; ChangeViewTemplate(bounds.Width); Loaded += PageLoaded; Unloaded += PageUnloaded; }
public async Task <List <ForumPostEntity> > GetThreadPosts(ForumThreadEntity forumThread) { string url = forumThread.Location; if (forumThread.CurrentPage > 0) { url = forumThread.Location + string.Format(Constants.PAGE_NUMBER, forumThread.CurrentPage); } else if (forumThread.HasBeenViewed) { url = forumThread.Location + Constants.GOTO_NEW_POST; } var forumThreadPosts = new List <ForumPostEntity>(); //TEMP CODE var result = await _webManager.DownloadHtml(url); HtmlDocument doc = result.Document; string responseUri = result.AbsoluteUri; /* TODO: The following checks the thread URL for "pti" (which indicated which post to scroll to) * Having it in the post manager though, is wrong. This needs to be refactored and a better method of * getting this needs to be put in. */ string[] test = responseUri.Split('#'); if (test.Length > 1 && test[1].Contains("pti")) { forumThread.ScrollToPost = Int32.Parse(Regex.Match(responseUri.Split('#')[1], @"\d+").Value) - 1; } HtmlNode threadNode = doc.DocumentNode.Descendants("div").FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("thread")); foreach (HtmlNode postNode in threadNode.Descendants("table").Where(node => node.GetAttributeValue("class", string.Empty).Contains("post"))) { var post = new ForumPostEntity(); post.Parse(postNode); forumThreadPosts.Add(post); } threadNode = doc.DocumentNode.Descendants("div").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("pages top")); threadNode = threadNode.Descendants("option").FirstOrDefault(node => node.GetAttributeValue("selected", string.Empty).Contains("selected")); if (forumThread.CurrentPage <= 0) { forumThread.CurrentPage = GetPageNumber(threadNode); } HtmlNode pageNode = doc.DocumentNode.Descendants("select").FirstOrDefault(); forumThread.TotalPages = forumThread.CurrentPage <= 1 ? 1 : Convert.ToInt32(pageNode.Descendants("option").LastOrDefault().GetAttributeValue("value", string.Empty)); return(forumThreadPosts); }
public static void CreateBookmarkLiveTile(ForumThreadEntity forumThread) { XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text05); XmlNodeList tileAttributes = tileXml.GetElementsByTagName("text"); tileAttributes[0].AppendChild(tileXml.CreateTextNode(forumThread.Name)); tileAttributes[1].AppendChild(tileXml.CreateTextNode(string.Format("Killed By: {0}", forumThread.KilledBy))); tileAttributes[2].AppendChild( tileXml.CreateTextNode(string.Format("Unread Posts: {0}", forumThread.RepliesSinceLastOpened))); //var imageElement = tileXml.GetElementsByTagName("image"); //imageElement[0].Attributes[1].NodeValue = "http://fi.somethingawful.com/forums/posticons/lf-arecountry.gif" ; var tileNotification = new TileNotification(tileXml); TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); }
private async void LaunchAppInForegroundWithThread(ForumThreadEntity thread) { var userMessage = new VoiceCommandUserMessage(); userMessage.SpokenMessage = "Opening the thread..."; var response = VoiceCommandResponse.CreateResponse(userMessage); string test = "{" + string.Format("type:'toast', 'threadId':{0}", thread.ThreadId) + "}"; response.AppLaunchArgument = test; await voiceServiceConnection.RequestAppLaunchAsync(response); }
private void PopularThreadList_ItemClick(object sender, ItemClickEventArgs e) { var threadEntity = e.ClickedItem as PopularThreadsTrendsEntity; var thread = new ForumThreadEntity(); if (threadEntity == null) { return; } thread.ParseFromPopularThread(threadEntity.Title, threadEntity.Id); string jsonObjectString = JsonConvert.SerializeObject(thread); Frame.Navigate(typeof(ThreadPage), jsonObjectString); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper" /> /// </param> /// <param name="e"> /// Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited. /// </param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { var jsonObjectString = (string)e.NavigationParameter; _forumThread = JsonConvert.DeserializeObject <ForumThreadEntity>(jsonObjectString); if (_forumThread == null) { return; } await _vm.GetForumPosts(_forumThread); // Set the default focus on the page to either one of the web views. CheckOrientation(); }
public static void CreateToastNotification(ForumThreadEntity forumThread) { string replyText = forumThread.RepliesSinceLastOpened > 1 ? " has {0} replies." : " has {0} reply."; string test = "{" + string.Format("type:'toast', 'threadId':{0}", forumThread.ThreadId) + "}"; ToastContent content = new ToastContent() { Launch = test, Visual = new ToastVisual() { TitleText = new ToastText() { Text = string.Format("\"{0}\"", forumThread.Name) }, BodyTextLine1 = new ToastText() { Text = string.Format(replyText, forumThread.RepliesSinceLastOpened) }, AppLogoOverride = new ToastAppLogo() { Source = new ToastImageSource(forumThread.ImageIconLocation) } }, Actions = new ToastActionsCustom() { Buttons = { new ToastButton("Open Thread", test) { ActivationType = ToastActivationType.Foreground }, new ToastButton("Sleep", "sleep") { ActivationType = ToastActivationType.Background } } }, Audio = new ToastAudio() { Src = new Uri("ms-winsoundevent:Notification.Reminder") } }; XmlDocument doc = content.GetXml(); var toastNotification = new ToastNotification(doc); var nameProperty = toastNotification.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "Tag"); nameProperty?.SetValue(toastNotification, forumThread.ThreadId.ToString()); ToastNotificationManager.CreateToastNotifier().Show(toastNotification); }
public async Task <ForumThreadEntity> GetThreadPosts(ForumThreadEntity forumThread) { string url = forumThread.Location; if (forumThread.CurrentPage > 0) { url = forumThread.Location + string.Format(Constants.PAGE_NUMBER, forumThread.CurrentPage); } else if (forumThread.HasBeenViewed) { url = forumThread.Location + Constants.GOTO_NEW_POST; } var forumThreadPosts = new ObservableCollection <ForumPostEntity>(); //TEMP CODE var threadManager = new ThreadManager(); var doc = await threadManager.GetThread(forumThread, url); HtmlNode threadNode = doc.DocumentNode.Descendants("div") .FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("thread")); foreach ( HtmlNode postNode in threadNode.Descendants("table") .Where(node => node.GetAttributeValue("class", string.Empty).Contains("post"))) { var post = new ForumPostEntity(); post.Parse(postNode); forumThreadPosts.Add(post); } threadNode = doc.DocumentNode.Descendants("div") .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("pages top")); if (threadNode != null) { threadNode = threadNode.Descendants("option") .FirstOrDefault(node => node.GetAttributeValue("selected", string.Empty).Contains("selected")); if (forumThread.CurrentPage <= 0) { forumThread.CurrentPage = GetPageNumber(threadNode); } } forumThread.ForumPosts = forumThreadPosts; return(forumThread); }
public static void CreateBookmarkLiveTile(ForumThreadEntity forumThread) { var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text05); var tileAttributes = tileXml.GetElementsByTagName("text"); tileAttributes[0].AppendChild(tileXml.CreateTextNode(forumThread.Name)); tileAttributes[1].AppendChild(tileXml.CreateTextNode(string.Format("Killed By: {0}", forumThread.KilledBy))); tileAttributes[2].AppendChild(tileXml.CreateTextNode(string.Format("Unread Posts: {0}", forumThread.RepliesSinceLastOpened))); //var imageElement = tileXml.GetElementsByTagName("image"); //imageElement[0].Attributes[1].NodeValue = "http://fi.somethingawful.com/forums/posticons/lf-arecountry.gif" ; var tileNotification = new TileNotification(tileXml); TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); }
private async Task FormatPmHtml(ForumPostEntity postEntity) { var list = new List<ForumPostEntity> {postEntity}; var thread = new ForumThreadEntity() { IsPrivateMessage = true }; #if WINDOWS_PHONE_APP thread.PlatformIdentifier = PlatformIdentifier.WindowsPhone; #else thread.PlatformIdentifier = PlatformIdentifier.Windows8; #endif Html = await HtmlFormater.FormatThreadHtml(thread, list); }
private void Thread_OnClick(object sender, ItemClickEventArgs e) { var clickedItem = (ForumThreadEntity)e.ClickedItem; _lastSelectedItem = clickedItem; Locator.ViewModels.BookmarksPageVm.NavigateToThreadPageCommand.Execute(e); if (AdaptiveStates.CurrentState == NarrowState) { // Use "drill in" transition for navigating from master list to detail view App.RootFrame.Navigate(typeof(ThreadPage), null, new DrillInNavigationTransitionInfo()); } else { // Play a refresh animation when the user switches detail items. //EnableContentTransitions(); } }
public static void CreateBookmarkLiveTile(ForumThreadEntity forumThread) { var bindingContent = new TileBindingContentAdaptive() { Children = { new TileText() { Text = forumThread.Name, Style = TileTextStyle.Body }, new TileText() { Text = string.Format("Unread Posts: {0}", forumThread.RepliesSinceLastOpened), Wrap = true, Style = TileTextStyle.CaptionSubtle }, new TileText() { Text = string.Format("Killed By: {0}", forumThread.KilledBy), Wrap = true, Style = TileTextStyle.CaptionSubtle } } }; var binding = new TileBinding() { Branding = TileBranding.NameAndLogo, Content = bindingContent }; var content = new TileContent() { Visual = new TileVisual() { TileMedium = binding, TileWide = binding, TileLarge = binding } }; var tileXml = content.GetXml(); var tileNotification = new TileNotification(tileXml); TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); }
public async override void Execute(object parameter) { var args = parameter as ItemClickEventArgs; if (args == null) { AwfulDebugger.SendMessageDialogAsync("Thread navigation failed!:(", new Exception("Arguments are null")); return; } var thread = args.ClickedItem as SearchEntity; if (thread == null) return; App.RootFrame.Navigate(typeof(ThreadPage)); Locator.ViewModels.ThreadPageVm.IsLoading = true; var newThreadEntity = new ForumThreadEntity() { Location = Constants.BaseUrl + thread.ThreadLink, ImageIconLocation = "/Assets/ThreadTags/noicon.png" }; Locator.ViewModels.ThreadPageVm.ForumThreadEntity = newThreadEntity; await Locator.ViewModels.ThreadPageVm.GetForumPostsAsync(); }
public async Task<bool> DoesTabExist(ForumThreadEntity thread) { using (var db = new DataSource()) { var thread2 = db.TabRepository.Items.Where(node => node.ThreadId == thread.ThreadId); var test = await thread2.FirstOrDefaultAsync(); return test != null; } }
public static async void WebView_ScriptNotify(object sender, NotifyEventArgs e) { var webview = sender as WebView; var threadEntity = Locator.ViewModels.ThreadPageVm.ForumThreadEntity; if (webview == null || threadEntity == null) { return; } try { string stringJson = e.Value; var command = JsonConvert.DeserializeObject<ThreadCommand>(stringJson); switch (command.Command) { case "openLink": await Windows.System.Launcher.LaunchUriAsync(new Uri(command.Id)); break; case "userProfile": var navUser = new NavigateToUserProfilePageCommand(); navUser.Execute(Convert.ToInt64(command.Id)); break; case "downloadImage": _url = command.Id; var message = string.Format("Do you want to download this image?{0}{1}", Environment.NewLine, command.Id); var msgBox = new MessageDialog(message, "Download Image"); var okButton = new UICommand("Yes") { Invoked = PictureOkButtonClick }; var cancelButton = new UICommand("No") { Invoked = PictureCancelButtonClick }; msgBox.Commands.Add(okButton); msgBox.Commands.Add(cancelButton); await msgBox.ShowAsync(); break; case "showPosts": await webview.InvokeScriptAsync("ShowHiddenPosts", new[] {string.Empty}); break; case "profile": //Frame.Navigate(typeof(UserProfileView), command.Id); break; case "openPost": var addIgnoredUserPostCommand = new AddIgnoredUserPostCommand(); var test = new WebViewCollection() { PostId = command.Id, WebView = webview }; try { addIgnoredUserPostCommand.Execute(test); } catch (Exception ex) { AwfulDebugger.SendMessageDialogAsync("Error getting post", ex); } break; case "post_history": //Frame.Navigate(typeof(UserPostHistoryPage), command.Id); break; case "rap_sheet": //Frame.Navigate(typeof(RapSheetView), command.Id); break; case "quote": var navigateToNewReplyViaQuoteCommand = new NavigateToNewReplyViaQuoteCommand(); navigateToNewReplyViaQuoteCommand.Execute(command.Id); break; case "edit": var navigateToEditPostPageCommand = new NavigateToEditPostPageCommand(); navigateToEditPostPageCommand.Execute(command.Id); break; case "scrollToPost": try { if (command.Id != null) { await webview.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", command.Id) }); } else if (!string.IsNullOrEmpty(threadEntity.ScrollToPostString)) { webview.InvokeScriptAsync("ScrollToDiv", new[] { threadEntity.ScrollToPostString }); } } catch (Exception) { Debug.WriteLine("Could not scroll to post..."); } break; case "markAsLastRead": try { var threadManager = new ThreadManager(); await threadManager.MarkPostAsLastReadAs(Locator.ViewModels.ThreadPageVm.ForumThreadEntity, Convert.ToInt32(command.Id)); int nextPost = Convert.ToInt32(command.Id) + 1; await webview.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) }); NotifyStatusTile.CreateToastNotification("Last Read", "Post marked as last read."); } catch (Exception ex) { AwfulDebugger.SendMessageDialogAsync("Could not mark thread as last read", ex); } break; case "setFont": if (_localSettings.Values.ContainsKey("zoomSize")) { _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]); webview.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() }); } else { // _zoomSize = 20; } break; case "openThread": var query = Extensions.ParseQueryString(command.Id); if (query.ContainsKey("action") && query["action"].Equals("showPost")) { //var postManager = new PostManager(); //var html = await postManager.GetPost(Convert.ToInt32(query["postid"])); return; } Locator.ViewModels.ThreadPageVm.IsLoading = true; var newThreadEntity = new ForumThreadEntity() { Location = command.Id, ImageIconLocation = "/Assets/ThreadTags/noicon.png" }; Locator.ViewModels.ThreadPageVm.ForumThreadEntity = newThreadEntity; await Locator.ViewModels.ThreadPageVm.GetForumPostsAsync(); var tabManager = new MainForumsDatabase(); var test2 = await tabManager.DoesTabExist(newThreadEntity); if (!test2) { await tabManager.AddThreadToTabListAsync(newThreadEntity); } Locator.ViewModels.ThreadPageVm.LinkedThreads.Add(newThreadEntity); break; default: var msgDlg = new MessageDialog("Not working yet!") { DefaultCommandIndex = 1 }; await msgDlg.ShowAsync(); break; } } catch (Exception ex) { Debug.WriteLine(ex); } }
private void GetDarkModeSetting(ForumThreadEntity forumThreadEntity) { var localSettings = ApplicationData.Current.LocalSettings; if (!localSettings.Values.ContainsKey(Constants.DarkMode)) return; var darkMode = (bool) localSettings.Values[Constants.DarkMode]; switch (darkMode) { case true: forumThreadEntity.PlatformIdentifier = PlatformIdentifier.WindowsPhone; break; case false: forumThreadEntity.PlatformIdentifier = PlatformIdentifier.Windows8; break; } }
public static async Task<string> FormatThreadHtml(ForumThreadEntity forumThreadEntity, List<ForumPostEntity> postEntities) { string html = await PathIO.ReadTextAsync("ms-appx:///Assets/Website/thread.html"); var doc2 = new HtmlDocument(); doc2.LoadHtml(html); HtmlNode head = doc2.DocumentNode.Descendants("head").FirstOrDefault(); switch (forumThreadEntity.PlatformIdentifier) { case PlatformIdentifier.WindowsPhone: head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/WindowsPhone-Default.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">"; break; } switch (forumThreadEntity.ForumId) { case 219: head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/219.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">"; break; case 26: head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/26.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">"; break; case 267: head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/267.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">"; break; case 268: head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/268.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">"; break; } HtmlNode bodyNode = doc2.DocumentNode.Descendants("div").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("row clearfix")); if (postEntities == null) return WebUtility.HtmlDecode(WebUtility.HtmlDecode(doc2.DocumentNode.OuterHtml)); string threadHtml = string.Empty; if (forumThreadEntity.Poll != null) { //threadHtml += FormatVotePoll(forumThreadEntity.Poll); } if (forumThreadEntity.ScrollToPost > 1) { threadHtml += "<div><div id=\"showPosts\">"; var clickHandler = $"window.ForumCommand('showPosts', '{"true"}')"; string showThreadsButton = HtmlButtonBuilder.CreateSubmitButton( $"Show {forumThreadEntity.ScrollToPost} Previous Posts", clickHandler, "showHiddenPostsButton", false); threadHtml += showThreadsButton; threadHtml += "</div><div style=\"display: none;\" id=\"hiddenPosts\">"; threadHtml += ParsePosts(0, forumThreadEntity.ScrollToPost, postEntities, forumThreadEntity.IsPrivateMessage); threadHtml += "</div>"; threadHtml += ParsePosts(forumThreadEntity.ScrollToPost, postEntities.Count, postEntities, forumThreadEntity.IsPrivateMessage); } else { threadHtml += ParsePosts(0, postEntities.Count, postEntities, forumThreadEntity.IsPrivateMessage); } bodyNode.InnerHtml = threadHtml; var images = bodyNode.Descendants("img").Where(node => node.GetAttributeValue("class", string.Empty) != "av"); foreach (var image in images) { var src = image.Attributes["src"].Value; if (Path.GetExtension(src) != ".gif") continue; if (src.Contains("somethingawful.com")) continue; if (src.Contains("emoticons")) continue; if (src.Contains("smilies")) continue; image.Attributes.Add("data-gifffer", image.Attributes["src"].Value); image.Attributes.Remove("src"); } return doc2.DocumentNode.OuterHtml; }
public async Task<DraftEntity> LoadThreadDraftEntity(ForumThreadEntity thread) { using (var db = new DataSource()) { return await db.DraftRepository.Items.Where(node => node.ThreadId == thread.ThreadId).FirstOrDefaultAsync(); } }