Exemplo n.º 1
0
        /// <summary>
        /// Applies any common formatting to the posts.
        /// </summary>
        /// <param name="posts">Posts to be formatted</param>
        override protected void ApplyCommonFormatting(ref List <Post> posts)
        {
            bool isFrontPage   = m_subreddit != null && (m_subreddit.IsArtifical || m_subreddit.DisplayName.ToLower().Equals("frontpage"));
            bool showSubreddit = isFrontPage || m_subreddit == null;

            foreach (Post post in posts)
            {
                // Set the first line
                DateTime origin   = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime postTime = origin.AddSeconds(post.CreatedUtc).ToLocalTime();

                // if this is going to a subreddit add the user, if this is going to a user add the domain
                if (m_subreddit != null)
                {
                    post.SubTextLine1 = TimeToTextHelper.TimeElapseToText(postTime) + $" ago by {post.Author}";
                }
                else
                {
                    post.SubTextLine1 = TimeToTextHelper.TimeElapseToText(postTime) + $" ago to {post.Domain}";
                }

                // Set the second line
                post.SubTextLine2PartOne = post.NumComments + (post.NumComments == 1 ? " comment " : " comments ");
                post.SubTextLine2PartTwo = (showSubreddit ? post.Subreddit.ToLower() : post.Domain);

                // Set the second line for flipview
                post.FlipViewSecondary = showSubreddit ? $"r/{post.Subreddit.ToLower()}" : TimeToTextHelper.TimeElapseToText(postTime) + " ago";

                // Escape the title, flair, and selftext
                post.Title         = WebUtility.HtmlDecode(post.Title);
                post.LinkFlairText = WebUtility.HtmlDecode(post.LinkFlairText);
                if (!String.IsNullOrEmpty(post.Selftext))
                {
                    post.Selftext = WebUtility.HtmlDecode(post.Selftext);
                }

                // Set the title size
                post.TitleMaxLines = m_baconMan.UiSettingsMan.SubredditList_ShowFullTitles ? 99 : 2;

                // Set if we should show the save image or not
                post.ShowSaveImageMenu = String.IsNullOrWhiteSpace(ImageManager.GetImageUrl(post.Url)) ? Windows.UI.Xaml.Visibility.Collapsed : Windows.UI.Xaml.Visibility.Visible;

                // Set if this is owned by the current user
                if (m_baconMan.UserMan.IsUserSignedIn && m_baconMan.UserMan.CurrentUser != null)
                {
                    post.IsPostOwnedByUser = post.Author.Equals(m_baconMan.UserMan.CurrentUser.Name, StringComparison.OrdinalIgnoreCase);
                }

                // Check if it has been read
                if (ReadPostsList.ContainsKey(post.Id))
                {
                    // Set the text color
                    post.TitleTextColor = Color.FromArgb(255, 152, 152, 152);

                    // Set the comments text if we want to.
                    int commentDiff = post.NumComments - ReadPostsList[post.Id];
                    post.NewCommentText = (ReadPostsList[post.Id] != -1 && commentDiff > 0) ? $"(+{commentDiff})" : String.Empty;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Fired when the subreddits should be formatted.
 /// </summary>
 /// <param name="subreddits"></param>
 protected override void ApplyCommonFormatting(ref List <Post> posts)
 {
     foreach (Post post in posts)
     {
         // Set The time
         DateTime origin   = new DateTime(1970, 1, 1, 0, 0, 0, 0);
         DateTime postTime = origin.AddSeconds(post.CreatedUtc).ToLocalTime();
         post.SubTextLine1 = TimeToTextHelper.TimeElapseToText(postTime) + " ago";
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Applies any common formatting to the posts.
        /// </summary>
        /// <param name="posts">Posts to be formatted</param>
        override protected void ApplyCommonFormatting(ref List <Post> posts)
        {
            bool isFrontPage = m_subreddit.IsArtifical || m_subreddit.DisplayName.ToLower().Equals("frontpage");

            foreach (Post post in posts)
            {
                // Set the first line
                DateTime origin   = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime postTime = origin.AddSeconds(post.CreatedUtc).ToLocalTime();
                post.SubTextLine1 = TimeToTextHelper.TimeElapseToText(postTime) + $" ago by {post.Author}";

                // Set the second line
                post.SubTextLine2PartOne = post.NumComments + (post.NumComments == 1 ? " comment " : " comments ");
                post.SubTextLine2PartTwo = (isFrontPage ? post.Subreddit.ToLower() : post.Domain);

                // Set the second line for flipview
                post.FlipViewSecondary = $"r/{post.Subreddit.ToLower()}";

                // Escape the title, flair, and selftext
                post.Title         = WebUtility.HtmlDecode(post.Title);
                post.LinkFlairText = WebUtility.HtmlDecode(post.LinkFlairText);
                if (!String.IsNullOrEmpty(post.Selftext))
                {
                    post.Selftext = WebUtility.HtmlDecode(post.Selftext);
                    // Some times things are double escaped. So do it twice.
                    post.Selftext = WebUtility.HtmlDecode(post.Selftext);
                }

                // Don't show link flair on the front page
                if (isFrontPage)
                {
                    post.LinkFlairText = "";
                }

                // Set the title size
                post.TitleMaxLines = m_baconMan.UiSettingsMan.SubredditList_ShowFullTitles ? 99 : 2;

                // Set if we should show the save image or not
                post.ShowSaveImageMenu = String.IsNullOrWhiteSpace(ImageManager.GetImageUrl(post.Url)) ? Windows.UI.Xaml.Visibility.Collapsed : Windows.UI.Xaml.Visibility.Visible;

                // Check if it has been read
                if (ReadPostsList.ContainsKey(post.Id))
                {
                    // Set the text color
                    post.TitleTextColor = Color.FromArgb(255, 152, 152, 152);

                    // Set the comments text if we want to.
                    int commentDiff = post.NumComments - ReadPostsList[post.Id];
                    post.NewCommentText = (ReadPostsList[post.Id] != -1 && commentDiff > 0) ? $"(+{commentDiff})" : String.Empty;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Applies any common formatting to the comments.
        /// </summary>
        /// <param name="comments">Commetns to be formatted</param>
        override protected void ApplyCommonFormatting(ref List <Comment> comments)
        {
            // #Todo
            foreach (Comment comment in comments)
            {
                // Set The time
                DateTime origin   = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime postTime = origin.AddSeconds(comment.CreatedUtc).ToLocalTime();
                comment.TimeString = TimeToTextHelper.TimeElapseToText(postTime) + " ago";

                // Decode the body
                comment.Body            = WebUtility.HtmlDecode(comment.Body);
                comment.AuthorFlairText = WebUtility.HtmlDecode(comment.AuthorFlairText);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Applies any common formatting to the comments.
        /// </summary>
        /// <param name="comments">Commetns to be formatted</param>
        override protected void ApplyCommonFormatting(ref List <Comment> comments)
        {
            foreach (Comment comment in comments)
            {
                // Set The time
                DateTime origin   = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime postTime = origin.AddSeconds(comment.CreatedUtc).ToLocalTime();
                comment.TimeString = TimeToTextHelper.TimeElapseToText(postTime) + " ago";

                // Set if this post is from the op
                comment.IsCommentFromOp = m_post != null && comment.Author.Equals(m_post.Author);

                // Set if this comment is from the current user
                if (m_baconMan.UserMan.IsUserSignedIn && m_baconMan.UserMan.CurrentUser != null)
                {
                    comment.IsCommentOwnedByUser = m_baconMan.UserMan.CurrentUser.Name.Equals(comment.Author, StringComparison.OrdinalIgnoreCase);
                }
            }
        }
Exemplo n.º 6
0
        public void PanelSetup(IPanelHost host, Dictionary <string, object> arguments)
        {
            _mHost = host;

            if (!arguments.ContainsKey(PanelManager.NavArgsUserName))
            {
                ReportUserLoadFailed();
                return;
            }

            // Get the user
            var userName = (string)arguments[PanelManager.NavArgsUserName];

            ui_userName.Text = userName;

            // Show loading
            ui_loadingOverlay.Show(true, "Finding " + userName);

            // Do the loading on a thread to get off the UI
            Task.Run(async() =>
            {
                // Make the request
                _mUser = await MiscellaneousHelper.GetRedditUser(App.BaconMan, userName);

                // Jump back to the UI thread, we will use low priority so we don't make any animations choppy.
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    // Check we got it.
                    if (_mUser == null)
                    {
                        ReportUserLoadFailed();
                        return;
                    }

                    // Fill in the UI
                    var origin             = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    var postTime           = origin.AddSeconds(_mUser.CreatedUtc).ToLocalTime();
                    ui_accountAgeText.Text = $"{TimeToTextHelper.TimeElapseToText(postTime)} old";

                    // Set cake day
                    var elapsed   = DateTime.Now - postTime;
                    var fullYears = Math.Floor((elapsed.TotalDays / 365));
                    var daysUntil = (int)(elapsed.TotalDays - (fullYears * 365));
                    ui_cakeDayHolder.Visibility = daysUntil == 0 ? Visibility.Visible : Visibility.Collapsed;

                    // Set karma
                    ui_linkKarmaText.Text    = $"{_mUser.LinkKarma:N0}";
                    ui_commentKarmaText.Text = $"{_mUser.CommentKarma:N0}";

                    // Set Gold
                    ui_goldHolder.Visibility = _mUser.IsGold ? Visibility.Visible : Visibility.Collapsed;

                    // Hide loading
                    ui_loadingOverlay.Hide();

                    // Kick off the updates
                    GetUserComments();
                    GetUserPosts();
                });
            });
        }