public async void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); try { if (_helper.Read <bool>("BackgroundEnable", false)) { if (NotifyStatusTile.IsInternet()) { var result = await LoginUser(); if (result) { await Update(taskInstance); } } } } catch (Exception) { } deferral.Complete(); }
private void CreateBookmarkLiveTiles(IEnumerable <ForumThreadEntity> forumThreads) { foreach (ForumThreadEntity thread in forumThreads.Where(thread => thread.RepliesSinceLastOpened > 0)) { NotifyStatusTile.CreateBookmarkLiveTile(thread); } }
private void CreateToastNotifications(IEnumerable <ForumThreadEntity> forumThreads) { foreach (ForumThreadEntity thread in forumThreads.Where(thread => thread.RepliesSinceLastOpened > 0)) { NotifyStatusTile.CreateToastNotification(thread); } }
public async void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); if (NotifyStatusTile.IsInternet()) { await Update(taskInstance); } deferral.Complete(); }
private async Task CreateNotificationToast(DateTime lastRefreshTime) { var notifications = await _client.GetNotifications(); var newNotifications = notifications.Where(node => node.CreatedAt > lastRefreshTime); foreach (var notification in newNotifications) { NotifyStatusTile.CreateToastNotification(notification); } }
public override async void Execute(object parameter) { var forumEntity = parameter as ForumEntity; if (forumEntity == null) { return; } var result = await NotifyStatusTile.CreateSecondaryForumLinkTile(forumEntity); }
private async Task CreateStatusTiles(DateTime lastRefreshTime) { var statusList = await _client.GetHomeTimeline(); var newStatus = statusList.Where(node => node.CreatedAt > lastRefreshTime && (node.Sensitive == null || node.Sensitive.Value == false)); foreach (var status in newStatus) { NotifyStatusTile.CreateStatusLiveTile(status); } }
private async Task Update(IBackgroundTaskInstance taskInstance) { try { var userAccountEntity = new UserAccountEntity(); var authManager = new AuthenticationManager(); bool loginTest = await authManager.RefreshAccessToken(userAccountEntity); if (loginTest) { UserAccountEntity.User user = await authManager.GetUserEntity(userAccountEntity); if (user == null) { return; } userAccountEntity.SetUserEntity(user); NotificationEntity notificationEntity = await GetNotifications(userAccountEntity); if (notificationEntity == null) { return; } if (notificationEntity.Notifications == null) { return; } // Debug //NotifyStatusTile.CreateNotificationLiveTile(notificationEntity.Notifications.First()); //NotifyStatusTile.CreateToastNotification(notificationEntity.Notifications.First()); var notificationList = notificationEntity.Notifications.Where(o => o.SeenFlag == false); foreach (var notification in notificationList) { NotifyStatusTile.CreateNotificationLiveTile(notification); NotifyStatusTile.CreateToastNotification(notification); await NotificationManager.ClearNotification(notification, userAccountEntity); } } } catch (Exception) { Debug.WriteLine("Failed to show toast/live tile notification"); } }
public async void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); try { if ((bool)_localSettings.Values[Constants.BackgroundEnable]) { if (NotifyStatusTile.IsInternet()) { await Update(taskInstance); } } } catch (Exception) { } deferral.Complete(); }
private async Task Update(IBackgroundTaskInstance taskInstance) { NotifyStatusTile.ClearCurrentTiles(); if (_helper.Read <bool>("RecentActivityBackground", false)) { var recentActivityManager = new RecentActivityManager(); var feedResultEntity = await recentActivityManager.GetActivityFeed(_accountUser.Username, 0, true, true, new UserAuthenticationEntity(_accountUser.AccessToken, _accountUser.RefreshToken, _accountUser.RefreshDate), _accountUser.Region, _accountUser.Language); if (string.IsNullOrEmpty(feedResultEntity?.ResultJson)) { // No Items, return false. return; } var feedEntity = JsonConvert.DeserializeObject <RecentActivityResponse>(feedResultEntity.ResultJson); if (!feedEntity.Feed.Any()) { return; } var feeds = feedEntity.Feed.Take(5); foreach (var feed in feeds) { NotifyStatusTile.CreateRecentActvityLiveTile(feed); } } //var newbookmarkthreads = new List<Thread>(); //try //{ // var pageNumber = 1; // var hasItems = false; // while (!hasItems) // { // var bookmarkResult = await _threadManager.GetBookmarksAsync(pageNumber); // var bookmarks = JsonConvert.DeserializeObject<List<Thread>>(bookmarkResult.ResultJson); // if (!bookmarks.Any()) // { // hasItems = true; // } // else // { // pageNumber++; // } // newbookmarkthreads.AddRange(bookmarks); // } // _helper.Read<DateTime>("LastRefresh", DateTime.UtcNow); // await _bdb.RefreshBookmarkedThreads(newbookmarkthreads); // newbookmarkthreads = await _bdb.GetBookmarkedThreadsFromDb(); //} //catch (Exception ex) //{ // //AwfulDebugger.SendMessageDialogAsync("Failed to get Bookmarks", ex); //} //if (!newbookmarkthreads.Any()) //{ // return; //} //if (_helper.Read<bool>("BookmarkBackground", false)) //{ // CreateBookmarkLiveTiles(newbookmarkthreads); //} //if (_helper.Read<bool>("BookmarkNotifications", false)) //{ // var notifyList = newbookmarkthreads.Where(node => node.IsNotified); // CreateToastNotifications(notifyList); //} }
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 async void WebView_ScriptNotify(object sender, NotifyEventArgs e) { try { string stringJson = e.Value; var command = JsonConvert.DeserializeObject <ReplyView.ThreadCommand>(stringJson); switch (command.Command) { case "profile": Frame.Navigate(typeof(UserProfileView), command.Id); break; case "openPost": break; case "post_history": Frame.Navigate(typeof(UserPostHistoryPage), command.Id); break; case "rap_sheet": Frame.Navigate(typeof(RapSheetView), command.Id); break; case "quote": Frame.Navigate(typeof(ReplyView), command.Id); break; case "edit": Frame.Navigate(typeof(EditReplyPage), command.Id); break; case "scrollToPost": if (command.Id != null) { await ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", command.Id) }); await ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", command.Id) }); } else if (!string.IsNullOrEmpty(_vm.ForumThreadEntity.ScrollToPostString)) { ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString }); ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString }); } break; case "markAsLastRead": await _threadManager.MarkPostAsLastRead(_forumThread, Convert.ToInt32(command.Id)); int nextPost = Convert.ToInt32(command.Id) + 1; await ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) }); await ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) }); NotifyStatusTile.CreateToastNotification("Post marked as last read! Now smash this computer and live your life!"); break; case "setFont": if (_localSettings.Values.ContainsKey("zoomSize")) { _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]); ThreadFullView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() }); ThreadSnapView.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; } var threadManager = new ThreadManager(); var threadEntity = new ForumThreadEntity(); var thread = await threadManager.GetThread(threadEntity, command.Id); if (thread == null) { var error = new MessageDialog("Specified post was not found in the live forums.") { DefaultCommandIndex = 1 }; await error.ShowAsync(); break; } string jsonObjectString = JsonConvert.SerializeObject(threadEntity); Frame.Navigate(typeof(ThreadPage), jsonObjectString); break; default: var msgDlg = new MessageDialog("Not working yet!") { DefaultCommandIndex = 1 }; await msgDlg.ShowAsync(); break; } } catch (Exception ex) { Debug.WriteLine(ex); } }