コード例 #1
0
ファイル: UIBuilder.cs プロジェクト: ctverceles/SF_Forms
        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");
                }
            }
        }
コード例 #2
0
        public Entry CommentCreatorLayout(PostItem post, StackLayout parent, string imgFile, string posttitle, string bodytext, string groupid, string postid)
        {
            MessagingCenter.Subscribe <CommentStackLayout, string> (this, Values.FOCUSONCOMMENTENTRY, (sender, arg) => {
                Debug.WriteLine("Replying to comment");
                CommentEntry.Focus();
                CommentEntry.Text = "@" + " " + arg;
            });

            commentEntry = new Entry {
                Placeholder       = Values.COMMENTPLACEHOLDER,
                PlaceholderColor  = Color.Gray,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                FontSize          = (Device.GetNamedSize(NamedSize.Small, typeof(Label)) * 0.8),
                Keyboard          = Keyboard.Create(KeyboardFlags.All),
                TextColor         = Color.Gray
            };

            commentEntry.Focused += (sender, e) => {
                //MessagingCenter.Send (this, Values.Busy);
                if (string.Equals(commentEntry.Text, commentEntry.Placeholder))
                {
                    commentEntry.Text = string.Empty;
                }
            };

            commentEntry.Unfocused   += (sender, e) => {
                //fire completed?
            };
            commentEntry.TextChanged += async(sender, e) => {
                this.commentTextToSave = commentEntry.Text;
            };
            commentEntry.Completed += async(object sender, EventArgs e) => {
                //save
                Debug.WriteLine("Finished commenting");

                parent.Children.Add(new CommentStackLayout(this, post, Settings.ProfilePic, Settings.Username, commentEntry.Text, true));

                //save to db
                comment = new CommentItem {
                    CommentText   = this.commentTextToSave, GroupID = groupid, PostID = postid,
                    UserCommentID = Settings.UserId, reactionCount = 0, UserCommentName = Settings.Username, UserImage = Settings.ProfilePic
                };
                await App.DataDB.SaveCommentItemsTaskAsync(comment);

                //Debug.WriteLine ("broadcasting comment");
                //App.ChatClient.SendComment (comment);
                SendOrRetrySendingComment(comment);

                Util.UpdatePostReactionCount(post);
                commentEntry.Text = Values.COMMENTPLACEHOLDER;
                //MessagingCenter.Send (this, Values.NotBusy);
            };



            return(commentEntry);
        }
コード例 #3
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);
        }
コード例 #4
0
 public async Task SaveCommentItemsTaskAsync(CommentItem item)
 {
     try{
         if (item.ID == null)
         {
             await commentTable.InsertAsync(item);
         }
         else
         {
             await commentTable.UpdateAsync(item);
         }
     }catch (Exception e) {
         Debug.WriteLine("CommentItem Save error: " + e.Message);
     }
 }
コード例 #5
0
        async void SendOrRetrySendingComment(CommentItem comment)
        {
            Debug.WriteLine("broadcasting comment");
            try{
                await App.ChatClient.SendComment(comment);
            }catch (Exception e) {
                Debug.WriteLine("problem sending comment, retrying: {0}", e.Message);
                await App.ChatClient.SendComment(comment);

                try{
                    await App.ChatClient.SendComment(comment);
                }catch (Exception ex) {
                    Debug.WriteLine("problem sending comment, retrying: {0}", ex.Message);
                    UserDialogs.Instance.ShowError("Couldn't connect to Secret Files. Your connection isn't so great now");
                }
            }
        }
コード例 #6
0
ファイル: Client.cs プロジェクト: ctverceles/SF_Forms
 public Task SendComment(CommentItem message)
 {
     return(_proxy.Invoke("SendComentsToClients", message));
 }