Exemplo n.º 1
0
        private void favorit_Click(object sender, EventArgs e)
        {
            // Add/Remove from favorits. depending on situation and change text on menu item accordinlgy
            ApplicationBarMenuItem mi = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem;

            if (mi == null)
            {
                return;
            }
            if (StoryRepository.CheckStoryTitle(value.post.title))
            {
                if (StoryRepository.RemoveStory(value.post.title))
                {
                    mi.Text = AddToFavoritsString;
                }
            }
            else
            {
                if (StoryRepository.AddNewStory(value.post.title,
                                                DateTime.Parse(value.post.date),
                                                value.post.url,
                                                value.post.content, null) > 0)
                {
                    mi.Text = RemoveFromFavoritsString;
                }
            }
        }
Exemplo n.º 2
0
        private void favorit_Click(object sender, EventArgs e)
        {
            // Add/Remove from favorits. depending on situation and change text on menu item accordinlgy
            ApplicationBarMenuItem mi = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem;

            if (mi == null)
            {
                return;
            }
            if (StoryRepository.CheckStoryTitle(value.post.title, true))
            {
                if (StoryRepository.RemoveStory(value.post.title, true))
                {
                    mi.Text = AddToFavoritsString;
                }
            }
            else
            {
                StoryRepository.RemoveStory(value.post.title, true);
                if (StoryRepository.AddNewStory(value.post.title,
                                                value.post.date != null ? DateTime.Parse(value.post.date) : DateTime.Now,
                                                value.post.url,
                                                value.post.content, true, null) > 0)
                {
                    Microsoft.Devices.VibrateController.Default.Start(TimeSpan.FromMilliseconds(50));
                    mi.Text = RemoveFromFavoritsString;
                }
            }
        }
Exemplo n.º 3
0
        private void webClient_OpenReadCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                return;
            }
            Dispatcher.BeginInvoke(() =>
            {
                value          = JsonConvert.DeserializeObject <PostRoot>(e.Result);
                var caption    = value.post.title.Split('.', '!', '?');
                tbCaption.Text = caption[0];
                // Need some smarter trim here, for O.Henry for example
                if (caption.Length > 1)
                {
                    tbCaptionAuthor.Text = value.post.title.Replace(caption[0], "").Trim(new char[] { '.', '!', '?' });
                }
                //if (NavigationContext.QueryString["b"] != null)
                //{
                //    value.post.content = "<div style='background-color:black;color:white;margin:0;padding:0'>" + value.post.content + "</div>";
                //ContentWebBrowser.Background = new SolidColorBrush(Colors.Black);
                //}

                ShowReadDuration(value.post.content);
                ContentWebBrowser.NavigateToString(InjectedString(value.post.content));
                pi.IsVisible = false;

                // Save downloaded story to HISTORY
                StoryRepository.AddNewStory(value.post.title,
                                            DateTime.Parse(value.post.date),
                                            value.post.url,
                                            value.post.content, false, null);

                ApplicationBarMenuItem mi = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem;
                if (mi != null)
                {
                    mi.Text = StoryRepository.CheckStoryTitle(value.post.title, true) ? RemoveFromFavoritsString : AddToFavoritsString;
                }
            });
        }
Exemplo n.º 4
0
        void DetailsView_Loaded(object sender, RoutedEventArgs e)
        {
            string itemURL = "";
            string randURI = "";
            string title   = "";

            pi.IsIndeterminate = true;
            pi.IsVisible       = true;
            SystemTray.SetProgressIndicator(this, pi);

            if (NavigationContext.QueryString.TryGetValue("title", out title))
            {
                var story = StoryRepository.GetSingleStoryByTitle(title);
                if (story != null && !story.Details.Contains("[..."))
                {
                    value            = new PostRoot();
                    value.post       = new Post();
                    value.post.title = story.Title;
                    value.post.url   = story.Link;
                    ShowReadDuration(story.Details);

                    ContentWebBrowser.NavigateToString(InjectedString(story.Details));
                    pi.IsVisible = false;
                    var caption = story.Title.Split(new char[] { '.', '!', '?' });

                    tbCaption.Text = caption[0];
                    // Need some smarter trim here, for O.Henry for example
                    if (caption.Length > 1)
                    {
                        tbCaptionAuthor.Text = value.post.title.Replace(caption[0], "").Trim(new char[] { '.', '!', '?' });
                    }
                    ApplicationBarMenuItem mi = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem;
                    if (mi != null)
                    {
                        mi.Text = StoryRepository.CheckStoryTitle(value.post.title, true) ? RemoveFromFavoritsString : AddToFavoritsString;
                    }

                    return;
                }
            }

            wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_OpenReadCompleted);

            if (NavigationContext.QueryString.TryGetValue("item", out itemURL))
            {
                itemURL = HttpUtility.UrlDecode(itemURL);

                try
                {
                    wc.DownloadStringAsync(new Uri(itemURL + "?json=1"));
                }
                catch (Exception exception)
                {
                    BugSenseHandler.Instance.LogException(exception);
                    pi.IsVisible = false;
                }
            }
            if (NavigationContext.QueryString.TryGetValue("randURI", out randURI))
            {
                try
                {
                    string         tURL    = HttpUtility.UrlDecode(randURI);
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(HttpUtility.UrlDecode(randURI)));
                    request.Method = "HEAD";
                    request.AllowReadStreamBuffering = false;
                    // Start the asynchronous request.


                    request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
                }
                catch (Exception exception)
                {
                    BugSenseHandler.Instance.LogException(exception);
                    pi.IsVisible = false;
                }
            }
        }