示例#1
0
        public static List <PostItemStackLayout> LoadFeedDataIntoFeedList(List <PostItem> PostData, List <CommentItem> CommentData, string groupid)      //load comments into feed here
        {
            PostItemStackLayout postTemp = null;

            CommentItem[] CommentDataArray = null;

            if (CommentData != null && CommentData.Count > 0)              //check if this group has any comments in the posts
            {
                CommentDataArray = CommentData.ToArray();
            }
            else
            {
                CommentDataArray = new CommentItem[] { };
            }

            try{
                var PostDataArray = PostData.ToArray();

                List <PostItemStackLayout> FeedList = new List <PostItemStackLayout> ();

                if (PostData == null)
                {
                    Debug.WriteLine("LoadFeedDataIntoFeedList error: Azure data passed to parameter is null");
                }
                else
                {
                    for (int c = 0; c < PostDataArray.Length; c++)
                    {
                        postTemp = new PostItemStackLayout(PostDataArray[c]);
                        //add comments from server to postTemp
                        if (CommentDataArray.Length > 0)                            //if groupfeed has any comments in the posts
                        {
                            for (int ctr = 0; ctr < CommentDataArray.Length; ctr++) //add all the comments in their respective posts
                            {
                                if (string.Equals(CommentDataArray[ctr].PostID, PostDataArray[c].ID))
                                {
                                    postTemp.stack.Children.Add(new CommentStackLayout(postTemp, PostDataArray[c], CommentDataArray[ctr].UserImage,
                                                                                       CommentDataArray[ctr].UserCommentName, CommentDataArray[ctr].CommentText));//build commentstacklayouts and add to UI under respective poststacklayouts
                                }
                            }
                        }
                        FeedList.Add(postTemp);
                    }
                    return(FeedList);
                }
            }catch (Exception e) {
                Debug.WriteLine("User has no posts in this page: " + e.Message);
                //UserDialogs.Instance.WarnToast ("Your data connection is a bit slow right now");
            }

            return(null);
        }
示例#2
0
        public async Task ListenForNewComments(PostItemStackLayout parentPost, StackLayout container, PostItem post)
        {
            App.ChatClient.OnCommentReceived += async(sender, message) => {
                if (message is CommentItem)
                {
                    Debug.WriteLine("Recieved Comment from SignalR: comment by {0}, comment body: {1}, in group {2}, in post {3}", message.UserCommentName, message.CommentText, message.GroupID, message.PostID);

                    if (string.Equals(message.PostID, post.ID))
                    {
                        Debug.WriteLine("Found post where comment was typed, adding it in");
                        //post comment
                        Device.BeginInvokeOnMainThread(() => {
                            UIBuilder.ReplaceTransparentCommentOrAdd(container, message, parentPost, post);
                        });
                    }
                }
            };
        }
示例#3
0
        public CommentStackLayout(PostItemStackLayout parentPost, PostItem post, string imgFile, string commentername, string bodytext, bool GrayedOut = false)
        {
            Text = bodytext;
            ImageString = imgFile;
            UserCommenter = commentername;

            this.BackgroundColor = Color.White;
            postImage = new Image{
                Source = imgFile,
                HorizontalOptions = LayoutOptions.Start,
                Aspect = Aspect.AspectFit,

            };
            PostTitle = new Label{
                Text = commentername,
                HorizontalOptions = LayoutOptions.Start,
                FontSize = (Device.GetNamedSize (NamedSize.Small, typeof(Label)) * 0.8)*0.8
            };
            TextBody = new Label{
                Text = commentername + "\t" + bodytext,
                LineBreakMode = LineBreakMode.WordWrap,
                HorizontalTextAlignment = TextAlignment.Start,
                FontSize = (Device.GetNamedSize (NamedSize.Small, typeof(Label)) * 0.8)*0.9
            };
            React = new Label{
                FontSize = (Device.GetNamedSize (NamedSize.Small, typeof(Label)) * 0.8)*0.9,
                Text = "Like",
                TextColor = Color.Teal
            };
            Reply = new Label{
                FontSize = (Device.GetNamedSize (NamedSize.Small, typeof(Label)) * 0.8)*0.9,
                Text = "Reply",
                TextColor = Color.Teal
            };
            Tag = new Label {
                FontSize = (Device.GetNamedSize (NamedSize.Small, typeof(Label)) * 0.8)*0.9,
                Text = "@anonymousperson",
                TextColor = Color.Teal
            };

            ReactHandler = new TapGestureRecognizer ();
            ReactHandler.Tapped += (sender, e) => {
                Util.UpdatePostReactionCount (post);
                if(string.Equals (React.Text, Values.LIKE)){
                    React.Text = Values.DISLIKE;
                }else{
                    React.Text = Values.LIKE;
                }
            };
            var refertoself = this;
            ReplyHandler = new TapGestureRecognizer ();
            ReplyHandler.Tapped += (sender, e) => {
                Debug.WriteLine("Focusing for comment reply");
                parentPost.CommentEntry.Focus ();
                parentPost.CommentEntry.Text = "@"+commentername;
            };
            Reply.GestureRecognizers.Add (ReplyHandler);
            React.GestureRecognizers.Add (ReactHandler);

            stack = new StackLayout {
                Orientation = StackOrientation.Vertical,
                //Padding = new Thickness(30, 0, 20, 10),
                Children = {
                    new StackLayout{
                        Orientation = StackOrientation.Horizontal,
                        Children = {postImage,
                            new StackLayout{
                                Orientation = StackOrientation.Vertical,
                                Children = {TextBody, new StackLayout{
                                        Orientation = StackOrientation.Horizontal,
                                        VerticalOptions = LayoutOptions.End,
                                        Children = {
                                            React,
                                            Reply
                                        }
                                    }}
                            }
                        }
                    }
                }
            };

            this.Children.Add (stack);

            if (GrayedOut) {
                this.Opacity = 0.3;//gray out while broadcast hasnt been received. solidify once received. add resend functions
            } else {
            }
        }
示例#4
0
        public static void ReplaceTransparentCommentOrAdd(StackLayout container, CommentItem message, PostItemStackLayout parentPost, PostItem post)
        {
            View[] view = new View[container.Children.Count];
            container.Children.CopyTo(view, 0);
            Debug.WriteLine("{0} comments in stack", view.Length);

            for (int c = 6; c < view.Length; c++)
            {
                try{
                    //Debug.WriteLine ("View {0} is {1}", c, view[c].GetType ());
                    if (view[c].GetType() == typeof(CommentStackLayout))
                    {
                        Debug.WriteLine("Checking commenter {0} at index {1}", (view [c] as CommentStackLayout).UserCommenter, c);

                        //if pending comment exists (current user is the commenter), replace the pending comment - else just add the comment at the bottom of the comment stack
                        if (string.Equals((view[c] as CommentStackLayout).Text, message.CommentText) && (view[c] as CommentStackLayout).Opacity == 0.3 && string.Equals((view[c] as CommentStackLayout).UserCommenter, Settings.Username))
                        {
                            Debug.WriteLine("user has a pending comment at index {0}, solidifying it", c);
                            container.Children.RemoveAt(c);
                            container.Children.Insert(c, new CommentStackLayout(parentPost, post, Settings.ProfilePic, Settings.Username, message.CommentText));
                            c = view.Length + 1;                           //exit loop to prevent duplicate comments - dont know why it repeats so much
                        }
                    }

                    if (c == view.Length - 1)
                    {
                        Debug.WriteLine("received comment by {0} hasnt been added", message.UserCommentName);
                        container.Children.Add(new CommentStackLayout(parentPost, post, message.UserImage, message.UserCommentName, message.CommentText));
                        //c = view.Length +1;//exit loop to prevent duplicate comments - dont know why it repeats so much
                    }
                }catch (Exception) {
                    Debug.WriteLine("not a comment");
                }
            }
        }