示例#1
0
 private async void Editor_EditorCancelledMessage()
 {
     try
     {
         await ThreadWebView.InvokeScriptAsync("resetAllMultiQuotes", new string[0]);
     }
     catch (Exception e)
     {
         App.TelemetryClient.TrackException(e);
     }
 }
示例#2
0
 private void CurrentThread_ThreadReadyToBeDisplayed(Thread thread)
 {
     if (thread != null)
     {
         ThreadWebView.Navigate(Strings.TopicPageCacheUri);
     }
     else
     {
         ThreadWebView.NavigateToString("");
     }
 }
示例#3
0
 private void SetFontSize()
 {
     if (_localSettings.Values.ContainsKey("zoomSize"))
     {
         _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]);
         try
         {
             ThreadWebView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
         }
         catch (Exception ex)
         {
             AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
         }
     }
     else
     {
         _zoomSize = 14;
     }
 }
示例#4
0
 private async void ThreadWebView_OnDOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
 {
     try
     {
         SetFontSize();
         if (_forumThread != null && _forumThread.ScrollToPost > 0)
         {
             try
             {
                 await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { _forumThread.ScrollToPostString });
             }
             catch (Exception ex)
             {
                 AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
             }
         }
         _vm.IsLoading = false;
     }
     catch (Exception)
     {
     }
 }
示例#5
0
 async Task ScrollTo(string anchor)
 {
     await ThreadWebView.InvokeScriptAsync("scrollTo", new string[1] {
         anchor
     });
 }
示例#6
0
 private void RemoveStyle_Click(object sender, RoutedEventArgs e)
 {
     _zoomSize = 14;
     ThreadWebView.InvokeScriptAsync("RemoveCustomStyle", null);
     _localSettings.Values["zoomSize"] = null;
 }
示例#7
0
 private void FontDecrease_Click(object sender, RoutedEventArgs e)
 {
     _zoomSize -= 1;
     ThreadWebView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
     _localSettings.Values["zoomSize"] = _zoomSize;
 }
示例#8
0
 private void ScrollToLastPostButton_OnClick(object sender, RoutedEventArgs e)
 {
     ThreadWebView.InvokeScriptAsync("ScrollToBottom", null);
 }
示例#9
0
        private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            if (_vm.ForumThreadEntity == null)
            {
                return;
            }
            if (e == null)
            {
                return;
            }
            string        stringJson = e.Value;
            ThreadCommand command    = null;

            try
            {
                command = JsonConvert.DeserializeObject <ThreadCommand>(stringJson);
            }
            catch (Exception ex)
            {
                AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
            }
            if (command == null)
            {
                return;
            }
            switch (command.Command)
            {
            case "quote":
                Frame.Navigate(typeof(ReplyPage), command.Id);
                break;

            case "edit":
                Frame.Navigate(typeof(EditPage), command.Id);
                break;

            case "setFont":
                SetFontSize();
                break;

            case "scrollToPost":
                if (!string.IsNullOrEmpty(_vm.ForumThreadEntity.ScrollToPostString))
                {
                    try
                    {
                        await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString });
                    }
                    catch (Exception ex)
                    {
                        AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                    }
                }
                break;

            case "markAsLastRead":
                await _threadManager.MarkPostAsLastRead(_forumThread, Convert.ToInt32(command.Id));

                int nextPost = Convert.ToInt32(command.Id) + 1;

                try
                {
                    await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });
                }
                catch (Exception ex)
                {
                    AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                    return;
                }
                var message = new MessageDialog("Post marked as last read! Now go on and live your life!")
                {
                    DefaultCommandIndex = 1
                };
                await message.ShowAsync();

                break;

            case "openThread":
                var query = Extensions.ParseQueryString(command.Id);
                if (query.ContainsKey("action") && query["action"].Equals("showPost"))
                {
                    var postManager = new PostManager();
                    try
                    {
                        var html = await postManager.GetPost(Convert.ToInt32(query["postid"]));
                    }
                    catch (Exception ex)
                    {
                        AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                        return;
                    }
                    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;
            }
        }