Exemple #1
0
 public void SetDiscussionUnsaved(Discussion discussionToUnsave)
 {
     // Look through the children of the discussion page
     foreach (Discussion discussionInFeed in discussionFeed.Children)
     {
         if (discussionInFeed.GetDiscussionId() == discussionToUnsave.GetDiscussionId())
         {
             // If the discussion is saved, remove it
             discussionInFeed.Saved = false;
         }
     }
 }
        public void AddPost(UserControl post)
        {
            // Check the type of the post to add
            if (post.GetType() == typeof(Discussion))
            {
                // Cast the post properly
                Discussion discussionToAdd = (Discussion)post;

                // Look through the children of the saved page
                foreach (UserControl postInFeed in savedFeed.Children)
                {
                    // If a child is the same type as the post being add it, compare them
                    if (postInFeed.GetType() == typeof(Discussion))
                    {
                        Discussion discussionInFeed = (Discussion)postInFeed;
                        if (discussionInFeed.GetDiscussionId() == discussionToAdd.GetDiscussionId())
                        {
                            // If the discussion is already saved, don't add it again
                            // Simply leave this method
                            return;
                        }
                    }
                }

                // Add the discussion to the SavedPage.
                AddToTop(discussionToAdd);
            }
            else if (post.GetType() == typeof(Photo))
            {
                // Cast the post properly
                Photo photoToAdd = (Photo)post;
                foreach (UserControl postInFeed in savedFeed.Children)
                {
                    // If a child is the same type as the post being add it, compare them
                    if (postInFeed.GetType() == typeof(Photo))
                    {
                        Photo photoInFeed = (Photo)postInFeed;
                        if (photoInFeed.photoId == photoToAdd.photoId)
                        {
                            // If the photo is already saved, don't add it again
                            // Simply leave this method
                            return;
                        }
                    }
                }

                // Add the photo to the SavedPage.
                AddToTop(photoToAdd);
            }

            emptyMessage.Visibility = Visibility.Collapsed;
        }
        public void RemovePost(UserControl post)
        {
            UserControl[] posts = new UserControl[savedFeed.Children.Count];
            savedFeed.Children.CopyTo(posts, 0);

            // Check the type of the post to add
            if (post.GetType() == typeof(Discussion))
            {
                // Cast the post properly
                Discussion discussionToRemove = (Discussion)post;

                // Look through the children of the saved page
                foreach (UserControl postInFeed in posts)
                {
                    // If a child is the same type as the post being removed, compare them
                    if (postInFeed.GetType() == typeof(Discussion))
                    {
                        Discussion discussionInFeed = (Discussion)postInFeed;
                        if (discussionInFeed.GetDiscussionId() == discussionToRemove.GetDiscussionId())
                        {
                            // If the discussion is saved, remove it
                            savedFeed.Children.Remove(discussionInFeed);
                        }
                    }
                }
            }
            else if (post.GetType() == typeof(Photo))
            {
                // Cast the post properly
                Photo photoToRemove = (Photo)post;
                foreach (UserControl postInFeed in posts)
                {
                    // If a child is the same type as the post being add it, compare them
                    if (postInFeed.GetType() == typeof(Photo))
                    {
                        Photo photoInFeed = (Photo)postInFeed;
                        if (photoInFeed.photoId == photoToRemove.photoId)
                        {
                            // If the photo is saved, remove it
                            savedFeed.Children.Remove(photoInFeed);
                        }
                    }
                }
            }

            if (savedFeed.Children.Count == 0)
            {
                emptyMessage.Visibility = Visibility.Visible;
            }
        }
 public Discussion(Discussion newDiscussion)
 {
     InitializeComponent();
     discussionId    = newDiscussion.discussionId;
     user            = userName.Text = newDiscussion.user;
     title           = discussionTitle.Text = newDiscussion.title;
     description     = newDiscussion.description;
     numReplies      = newDiscussion.numReplies;
     score           = newDiscussion.score;
     comments        = newDiscussion.comments;
     currUser        = newDiscussion.currUser;
     main            = newDiscussion.main;
     Saved           = newDiscussion.saved;
     replyCount.Text = numReplies.ToString() + ((numReplies != 1) ? " replies" : " reply");
 }
Exemple #5
0
 public void DisplayDiscussionPosts()
 {
     discussionFeed.Children.Clear();
     foreach (KeyValuePair <int, Discussion> pair in discussionDict.AsEnumerable().Reverse())
     {
         var parent = VisualTreeHelper.GetParent(pair.Value);
         if (parent == null)
         {
             Discussion discussionToAdd = new Discussion(pair.Value);
             discussionToAdd.main = this.parent;
             discussionFeed.Children.Add(discussionToAdd);
             MakeDiscussionClickable(discussionToAdd);
         }
     }
     SetParentOfEachDiscussion();
 }
        public ProfilePageOtherUser(MainWindow main)
        {
            InitializeComponent();

            this.main = main;

            userName.Content = "Lawrence";

            // Determine whether this user is being followed.
            if (main.followingSomeone)
            {
                followButton.Content = "Unfollow";
            }
            else
            {
                followButton.Content = "Follow";
            }

            // Create a photo and discussion.
            photo              = new Photo(103, "Images/miami.jpg");
            photo.username     = "******";
            photo.title        = "From my trip in miami";
            photo.score        = 5;
            photo.commentCount = 1;
            photo.comments.Add(new Comment("Emilio", "I see that hotel in so many miami nightlife pictures. Has some cool lighting"));
            photo.displaySideInfo();
            photo.sidePhotoInfo.Visibility = Visibility.Collapsed;
            photo.main = this.main;
            photo.MouseLeftButtonDown += ClickPost;

            discussion       = new Discussion(100, "Lawrence", "Is there even a point to stand alone cameras?", "Google keeps mentioning how amazing the Pixel 2 camera is with its machine learning stuffs, and in general phone cameras are super convenient. Is there even a point to them anymore?", 3);
            discussion.score = -1;
            Comment commentWithReply = new Comment("Angela", "I'll be honest, all I need at this point is my Google Pixel.");

            commentWithReply.repliesFeed.Children.Add(new Comment("Lawrence", "This is exactly what I mean, why should I pay $2000 for a stand alone camer?"));
            discussion.GetComments().Add(commentWithReply);
            discussion.GetComments().Add(new Comment("Anonymoose", "Point and shoots barely have a purpose now, but DSLRs and professional gear are still relevant. For any regular user, a phone is fine. But think about the professionals who need the features of a DSLR. Manual focus and switching lenses is a big deal, let alone the massive boost in quality. They let you be more creative, as opposed to shooting a picture the same way every time."));
            discussion.main                 = this.main;
            discussion.numReplies           = 3;
            discussion.MouseLeftButtonDown += ClickPost;

            // Photo = 5 Score, 1 Comment, Discussion = -1 score, 3 comments
            userProfileFeed.Children.Add(photo);
            userProfileFeed.Children.Add(discussion);

            currentFilterOption.Content = filterAll.Content;
        }
 private void ClickPost(object sender, MouseEventArgs e)
 {
     if (sender.GetType() == typeof(Discussion))
     {
         Discussion      temp            = (Discussion)sender;
         DiscussionPopup discussionPopup = new DiscussionPopup(parent, temp);
         discussionPopup.SetValue(Grid.RowProperty, 2);
         discussionPopup.SetValue(Grid.ColumnSpanProperty, 3);
         parent.mainGrid.Children.Add(discussionPopup);
     }
     else if (sender.GetType() == typeof(Photo))
     {
         Photo      temp       = (Photo)sender;
         PhotoPopup photoPopup = new PhotoPopup(parent, temp);
         photoPopup.SetValue(Grid.RowProperty, 2);
         photoPopup.SetValue(Grid.ColumnSpanProperty, 3);
         parent.mainGrid.Children.Add(photoPopup);
     }
 }
Exemple #8
0
        /// <summary>
        /// Creates a new following page that is either empty or has some posts of the people the user is following.
        /// Hard-coded.
        /// </summary>
        /// <param name="main"> The MainWindow the following page is created in. </param>
        /// <param name="followingFlag"> If set to false, no posts appear. If true, will show 2 hardcoded posts. </param>
        public FollowingPage(MainWindow main, bool followingFlag)
        {
            InitializeComponent();

            parent = main;

            if (followingFlag == true)
            {
                // Create a photo and discussion.
                photo              = new Photo(103, "Images/miami.jpg");
                photo.username     = "******";
                photo.title        = "From my trip in miami";
                photo.score        = 5;
                photo.commentCount = 1;
                photo.comments.Add(new Comment("Emilio", "I see that hotel in so many miami nightlife pictures. Has some cool lighting"));
                photo.displaySideInfo();
                photo.main                 = this.parent;
                photo.IsPrivate            = false;
                photo.MouseLeftButtonDown += ClickPost;

                discussion       = new Discussion(100, "Lawrence", "Is there even a point to stand alone cameras?", "Google keeps mentioning how amazing the Pixel 2 camera is with its machine learning stuffs, and in general phone cameras are super convenient. Is there even a point to them anymore?", 3);
                discussion.score = -1;
                Comment commentWithReply = new Comment("Angela", "I'll be honest, all I need at this point is my Google Pixel.");
                commentWithReply.repliesFeed.Children.Add(new Comment("Lawrence", "This is exactly what I mean, why should I pay $2000 for a stand alone camer?"));
                discussion.GetComments().Add(commentWithReply);
                discussion.GetComments().Add(new Comment("Anonymoose", "Point and shoots barely have a purpose now, but DSLRs and professional gear are still relevant. For any regular user, a phone is fine. But think about the professionals who need the features of a DSLR. Manual focus and switching lenses is a big deal, let alone the massive boost in quality. They let you be more creative, as opposed to shooting a picture the same way every time."));
                discussion.main                 = this.parent;
                discussion.numReplies           = 3;
                discussion.MouseLeftButtonDown += ClickPost;

                // Add to the children of feed.
                followingFeed.Children.Add(photo);
                followingFeed.Children.Add(discussion);
            }
            else
            {
                // Clear children of the feed.
                followingFeed.Children.Clear();

                AddEmptyMessage();
            }
        }
        /*private void HardcodedPhotosAndDiscussions()
         * {
         *  userProfileFeed.Children.Add(new Photo());
         *  userProfileFeed.Children.Add(new Discussion());
         *  userProfileFeed.Children.Add(new Photo(parent.currPhotosPage.photoIdCounter, new BitmapImage(new Uri("Images/Coast.jpg", UriKind.Relative))));
         *
         *  foreach (UserControl post in userProfileFeed.Children)
         *  {
         *      MakePostClickable(post);
         *      // Add to user's photos or discussions
         *      if (post is Photo)
         *      {
         *          displayedUser.userPhotos.Add((Photo)post);
         *      }
         *      else if (post is Discussion)
         *      {
         *          displayedUser.userDiscussions.Add((Discussion)post);
         *      }
         *  }
         * }*/

        public void DisplayPosts()
        {
            userProfileFeed.Children.Clear();
            foreach (KeyValuePair <int, Photo> photo in displayedUser.userPhotos)
            {
                Photo newPhoto = new Photo(photo.Value);
                newPhoto.sidePhotoInfo.Visibility = Visibility.Collapsed;
                userProfileFeed.Children.Add(newPhoto);
                newPhoto.main = this.parent;
                MakePostClickable(newPhoto);
            }
            foreach (KeyValuePair <int, Discussion> discussion in displayedUser.userDiscussions)
            {
                Discussion newDiscussion = new Discussion(discussion.Value);
                newDiscussion.main = this.parent;
                userProfileFeed.Children.Add(newDiscussion);
                MakePostClickable(newDiscussion);
            }

            if ((displayedUser.userDiscussions.Count == 0) && (displayedUser.userPhotos.Count == 0))
            {
                Border border = new Border();
                border.BorderBrush     = Brushes.Gray;
                border.BorderThickness = new Thickness(2);
                border.Opacity         = 50;
                border.Width           = 750;
                border.Margin          = new Thickness(10);
                TextBlock text = new TextBlock();
                text.Text                = "There are no posts here. \nPost some discussions and photos, and they will show on your profile!";
                text.FontFamily          = new FontFamily("Microsoft YaHei");
                text.FontSize            = 26;
                text.TextAlignment       = TextAlignment.Center;
                text.HorizontalAlignment = HorizontalAlignment.Center;
                text.VerticalAlignment   = VerticalAlignment.Center;
                text.TextWrapping        = TextWrapping.Wrap;

                border.Child = text;

                userProfileFeed.Children.Add(border);
            }
        }
Exemple #10
0
        public void SortByNew()
        {
            // Get the array of all the children in the page.
            Discussion[] discussionsToSort = new Discussion[discussionFeed.Children.Count];
            discussionFeed.Children.CopyTo(discussionsToSort, 0);

            discussionFeed.Children.Clear();
            foreach (KeyValuePair <int, Discussion> pair in discussionDict.AsEnumerable().Reverse())
            {
                Discussion discussionToAdd = new Discussion(discussionsToSort[SearchFor(pair.Value.GetDiscussionId(), discussionsToSort)]);
                discussionToAdd.main = this.parent;
                discussionFeed.Children.Add(discussionToAdd);
                MakeDiscussionClickable(discussionToAdd);

                /*
                 * Discussion discussionToAdd = new Discussion(pair.Value);
                 * discussionToAdd.main = this.parent;
                 * discussionFeed.Children.Add(discussionToAdd);
                 * MakeDiscussionClickable(discussionToAdd);*/
            }
        }
        public DiscussionPopup(MainWindow main, Discussion sender)
        {
            InitializeComponent();

            this.main = main;
            main.ChangeFill(Visibility.Visible);

            this.discussion = sender;

            Username.Text              = sender.GetUser();
            DiscussionTitle.Text       = sender.GetTitle();
            DiscussionDescription.Text = sender.GetDescription();
            NumRepliesButton.Content   = sender.GetNumReplies() + " replies";
            DisplayComments();
            MessageOrDeleteButton();
            SaveOrUnsaveButton();
            editable = false;
            Loaded  += discussionLoaded;

            window.Height = System.Windows.SystemParameters.PrimaryScreenHeight * 0.80;
            window.Width  = System.Windows.SystemParameters.PrimaryScreenWidth * 0.7;
        }
        private void InitializePosts()
        {
            photo          = new Photo(102, "Images/Mountains.jpg");
            photo.username = "******";
            photo.title    = "Rate my mountains photo";
            photo.score    = 5;
            photo.displaySideInfo();
            photo.commentCount = 1;
            photo.comments.Add(new Comment("Emilio", "Cool photo. Where was this?"));
            photo.main      = this.parent;
            photo.IsPrivate = false;
            photo.displaySideInfo();

            discussion       = new Discussion(102, "Jessi", "Good places to take mountain pictures in Alberta?", "I'm visiting Alberta this summer, and was wondering what the best places to take mountain pictures are. Ideally they would be near the Banff area.", 2);
            discussion.score = 1;
            discussion.GetComments().Add(new Comment("Lawrence", "Lake Louise looks spectacular during the summer! Just go early to avoid the crowds."));
            discussion.GetComments().Add(new Comment("Anonymoose", "Basically anywhere near the rockies. Alberta is pretty amazing like that."));
            discussion.numReplies = 2;
            discussion.main       = this.parent;

            photo.MouseLeftButtonDown      += ClickPost;
            discussion.MouseLeftButtonDown += ClickPost;
        }
        private void SaveClick(object sender, RoutedEventArgs e)
        {
            if (main.signedIn)
            {
                if (!saved)
                {
                    // Create a new instance with the same attributes
                    Discussion copyOfDiscussion = new Discussion(discussionId, user, title, description, numReplies);
                    copyOfDiscussion.score    = this.score;
                    copyOfDiscussion.main     = this.main;
                    copyOfDiscussion.comments = this.comments;

                    // Set the saved flag of the new Discussion to true
                    copyOfDiscussion.Saved = true;
                    //  Pass it to SavedPage.AddPost()
                    main.currSavedPage.AddPost(copyOfDiscussion);

                    // Set the Saved button content of this discussion to Unsave
                    // Set the saved flag of this dicussion to true
                    this.Saved = true;
                }
                else if (saved)
                {
                    this.Saved = false;

                    main.currSavedPage.RemovePost(this);
                    main.currDiscussionPage.SetDiscussionUnsaved(this);
                }
            }
            else if (!main.signedIn)
            {
                LoginPrompt prompt = new LoginPrompt(main);
                prompt.SetMessage("You must sign in to save discussions.");
                prompt.ShowDialog();
                main.HighlightTab();
            }
        }
Exemple #14
0
        public void SortByMostCommented()
        {
            currentSortOption.Content = "Most Commented";

            // Get the array of all the children in the page.
            Discussion[] discussionsToSort = new Discussion[discussionFeed.Children.Count];
            discussionFeed.Children.CopyTo(discussionsToSort, 0);

            // Sort the array using linear sort.
            int i = 1;
            int j;

            while (i < discussionsToSort.Length)
            {
                j = i;
                while ((j > 0) && (discussionsToSort[j - 1].GetNumReplies() > discussionsToSort[j].GetNumReplies()))
                {
                    Discussion temp = discussionsToSort[j];
                    discussionsToSort[j]     = discussionsToSort[j - 1];
                    discussionsToSort[j - 1] = temp;
                    j--;
                }
                i++;
            }

            // Clear the children.
            discussionFeed.Children.Clear();
            // Add the sorted list of children (backwards | highest popularity at top)
            for (int k = discussionsToSort.Length - 1; k >= 0; k--)
            {
                Discussion discussionToAdd = new Discussion(discussionsToSort[k]);
                discussionToAdd.main = this.parent;
                discussionFeed.Children.Add(discussionToAdd);
                MakeDiscussionClickable(discussionToAdd);
            }
        }
Exemple #15
0
 private void MakeDiscussionClickable(Discussion discussion)
 {
     discussion.MouseLeftButtonDown += new MouseButtonEventHandler(this.DiscussionClickTest);
 }
        protected void ButtonClick(object sender, EventArgs e)
        {
            if (main.signedIn)
            {
                if (sender.Equals(PostCommentButton))
                {
                    if (replyFlag == 0)
                    {
                        Comment newComment = new Comment(main.currUser.UserName, CommentBox.Text, this);
                        newComment.CurrentUser = true;
                        commentsFeed.Children.Add(newComment);
                        ScrollViewComments.ScrollToEnd();
                        discussion.GetComments().Add(newComment);
                        CommentBox.Text        = "";
                        CommentBoxDefault.Text = "Type a message...";
                        discussion.numReplies++;
                        string repliesString = discussion.numReplies.ToString();
                        repliesString             += (discussion.numReplies != 1) ? " replies" : " reply";
                        NumRepliesButton.Content   = repliesString;
                        discussion.replyCount.Text = repliesString;
                        CommentBox.Focus();
                        //parent.GetDiscussionDict()[discussion.GetDiscussionId()] = discussion;
                    }
                    else if (replyFlag == 1)
                    {
                        //string[] reply = CommentBox.Text.Split('\n');
                        Comment newComment = new Comment(main.currUser.UserName, CommentBox.Text, this);
                        newComment.CurrentUser = true;
                        commentToReplyTo.repliesFeed.Children.Add(newComment);
                        CommentBox.Text        = "";
                        CommentBoxDefault.Text = "Type a message...";
                        replyFlag        = 0;
                        commentToReplyTo = null;
                        discussion.numReplies++;
                        string repliesString = discussion.numReplies.ToString();
                        repliesString             += (discussion.numReplies != 1) ? " replies" : " reply";
                        NumRepliesButton.Content   = repliesString;
                        discussion.replyCount.Text = repliesString;
                        CommentBox.Focus();
                    }
                }
                else if (sender.Equals(DeleteButton))
                {
                    DeletePrompt prompt = new DeletePrompt(main, this);
                    prompt.SetMessage("This action cannot be undone, are you sure you want to proceed?");
                    prompt.ShowDialog();
                    main.HighlightTab();
                    if (prompt.confirmed == true)
                    {
                        // remove from discussions page
                        main.currDiscussionPage.discussionDict.Remove(discussion.discussionId);
                        main.currDiscussionPage.DisplayDiscussionPosts();
                        // remove from user's profile page
                        main.currUser.userDiscussions.Remove(discussion.discussionId);
                        main.currProfilePage.DisplayPosts();
                        // close popup window
                        this.Visibility = Visibility.Hidden;
                        main.ChangeFill(Visibility.Hidden);
                    }
                }
                else if (sender.Equals(EditButton))
                {
                    if (editable == false)
                    {
                        EditButton.Content    = "Save Changes";
                        EditButton.Background = Brushes.Yellow;

                        editable = true;

                        descriptionTextBox.Text          = DiscussionDescription.Text;
                        DiscussionDescription.Visibility = Visibility.Hidden;
                        descriptionTextBox.Visibility    = Visibility.Visible;
                        Keyboard.Focus(descriptionTextBox);
                        descriptionTextBox.CaretIndex = descriptionTextBox.Text.Length;
                    }
                    else
                    {
                        EditButton.Content               = "EDIT";
                        EditButton.Background            = Brushes.LightGray;
                        DiscussionDescription.Visibility = Visibility.Visible;
                        editable = false;
                        updateDescription();
                    }
                }
                else if (sender.Equals(saveButton))
                {
                    if (!discussion.saved)
                    {
                        // Create a new instance with the same attributes
                        Discussion copyOfDiscussion = new Discussion(discussion.discussionId, discussion.user, discussion.title, discussion.description, discussion.numReplies);
                        copyOfDiscussion.score    = discussion.score;
                        copyOfDiscussion.main     = discussion.main;
                        copyOfDiscussion.comments = discussion.comments;

                        // Set the saved flag of the new Discussion to true
                        copyOfDiscussion.Saved = true;
                        //  Pass it to SavedPage.AddPost()
                        main.currSavedPage.AddPost(copyOfDiscussion);

                        // Set the Saved button content of this discussion to Unsave
                        // Set the saved flag of this dicussion to true
                        discussion.saved = true;
                        discussion.saveDiscussion.Content = "Unsave";
                        saveButton.Content = "Unsave";
                    }
                    else if (discussion.saved)
                    {
                        discussion.saved = false;

                        main.currSavedPage.RemovePost(discussion);
                        main.currDiscussionPage.SetDiscussionUnsaved(discussion);
                        discussion.saveDiscussion.Content = "Save";
                        saveButton.Content = "Save";
                    }
                }
                else if (sender.Equals(MessageUserButton))
                {
                    MessageDevelopmentPrompt prompt = new MessageDevelopmentPrompt(this);
                    prompt.ShowDialog();
                }
            }
            else if (!main.signedIn)
            {
                if (sender.Equals(saveButton))
                {
                    NoBlurPrompt prompt = new NoBlurPrompt(main, this);
                    prompt.SetMessage("You must sign in to save posts.");
                    prompt.ShowDialog();
                    main.HighlightTab();
                }
                else
                {
                    NoBlurPrompt prompt = new NoBlurPrompt(main, this);
                    prompt.SetMessage("You must sign in to discuss with users.");
                    prompt.ShowDialog();
                    main.HighlightTab();
                }
            }
        }
Exemple #17
0
 public void UpdateDiscussionDict(int id, Discussion newDiscussion)
 {
     discussionDict[id] = newDiscussion;
 }
Exemple #18
0
 public void AddDiscussionPost(Discussion newDiscussion)
 {
     discussionDict.Add(discussionIdCtr++, newDiscussion);
     discussionIdCtr++;
     DisplayDiscussionPosts();
 }