void GenerateCommentView(Comment comment) { try { StackLayout TextHolderStack = new StackLayout { // contain Name label , Comment label and date stack Orientation = StackOrientation.Vertical, Spacing = 0, HorizontalOptions = LayoutOptions.End, Padding = new Thickness(0, 10, 0, 0) }; if (!string.IsNullOrEmpty(comment.comment_txt)) { commentLayout = new StackLayout { Spacing = 0, Orientation = StackOrientation.Horizontal, ClassId = comment.comment_id, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, Padding = 0 }; ///////////////////////// profileIcone ///////////////////////// Image profileIcone = new Image { HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, HeightRequest = App.screenHeight * Device.OnPlatform(.13, .13, .14), WidthRequest = App.screenWidth * Device.OnPlatform(.13, .13, .14) }; if (!string.IsNullOrEmpty(comment.profileurl)) { profileIcone.Source = Constants.SERVICE_BASE_URL + comment.profileurl; } else { profileIcone.Source = Device.OnPlatform("noimage.png", "noimage.png", "//Assets//noimage.png"); } commentLayout.Children.Add(new StackLayout { Padding = new Thickness(5, Device.OnPlatform(-3, -5, -10), 5, 0), VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Start, //HeightRequest = App.screenHeight * Device.OnPlatform(.15,.12,.12), //WidthRequest = App.screenWidth * Device.OnPlatform(.15,.12,.12), Children = { profileIcone } }); //profileIcone.TranslationY = 0; // not working ///////////////////////// commentText ///////////////////////// Label commentTextLabel = new Label { Text = comment.comment_txt, TextColor = Color.Gray, FontSize = Device.OnPlatform(14, 14, 18), WidthRequest = App.screenWidth * Device.OnPlatform(.75, .70, .70), HorizontalOptions = LayoutOptions.Start }; ///////////////////////// firstname ///////////////////////// Label nameText = new Label { Text = !string.IsNullOrEmpty(comment.firstname) ? comment.firstname :" ", TextColor = Color.Black, FontSize = Device.OnPlatform(16, 16, 21), HorizontalOptions = LayoutOptions.Start }; TextHolderStack.Children.Add(nameText); TextHolderStack.Children.Add(commentTextLabel); ///////////////////////// comment_datetime ///////////////////////// if (!string.IsNullOrEmpty(comment.comment_datetime)) { Label dateText = new Label { Text = Convert.ToDateTime(comment.comment_datetime).ToLocalTime().ToString("f", CultureInfo.InvariantCulture), //comment.comment_datetime, TextColor = Color.Gray, FontSize = Device.OnPlatform(8, 8, 16), HorizontalOptions = LayoutOptions.Start }; if (currentUserId == comment.user_id) { Label removeLabel = new Label { Text = "remove", TextColor = Color.FromRgb(30, 126, 210), FontSize = Device.OnPlatform(8, 8, 16), HorizontalOptions = LayoutOptions.Start, ClassId = comment.comment_id }; removeLabelTap = new TapGestureRecognizer(); removeLabelTap.Tapped += RemoveLabelTap_Tapped; removeLabel.GestureRecognizers.Add(removeLabelTap); TextHolderStack.Children.Add(new StackLayout { Children = { dateText, removeLabel }, Orientation = StackOrientation.Horizontal, Spacing = 5, Padding = new Thickness(0, 1, 0, 0), HorizontalOptions = LayoutOptions.Start }); } else { TextHolderStack.Children.Add(dateText); } } commentLayout.Children.Add(TextHolderStack); } // testing add grayline // //listContainer.Children.Add(new BoxView{HeightRequest = 1, BackgroundColor = Color.Gray}); listContainer.Children.Add(commentLayout); } catch (Exception) { } }
private async void addCommentButtonTapped(object sender, EventArgs e) { if (isPosting == true || string.IsNullOrEmpty(newCommentEntry.Text)) { return; } string commentText = string.Empty; try { addCommentButtonTap.Tapped -= addCommentButtonTapped; isPosting = true; commentText = newCommentEntry.Text.Trim(); progressBar.ShowProgressbar("Saving comment"); isPosting = true; PurposeColor.Model.User user = App.Settings.GetUser(); if (user == null) { progressBar.HideProgressbar(); progressBar.ShowToast( "user name is not valid." ); isPosting = false; return; } string actionId = string.Empty; string eventId = string.Empty; string goalId = string.Empty; switch (curentGemType) { case GemType.Goal: goalId = currentGemId; break; case GemType.Event: eventId = currentGemId; break; case GemType.Action: actionId = currentGemId; break; case GemType.Emotion: break; default: break; } string commentSharingCode = isCommunityShared ? "1" : "0"; /// "0" denotes its private comment var response = await PurposeColor.Service.ServiceHelper.AddComment(user.UserId.ToString(), commentText, commentSharingCode, goalId, eventId, actionId); if (response.code != null && response.code == "200") { isPosting = false; progressBar.HideProgressbar(); progressBar.ShowToast("Comment saved"); // add the new comment to the comments list view. try { listContainer.BackgroundColor = Color.White; //add comment to view Comment newComment = new Comment { comment_id = string.IsNullOrEmpty(response.comment_id.ToString()) ? "000" : response.comment_id.ToString(), comment_txt = commentText, user_id = currentUserId, firstname = !string.IsNullOrEmpty(user.UserName)? user.UserName:(!string.IsNullOrEmpty(user.DisplayName)? user.DisplayName :" "), profileurl = string.IsNullOrEmpty(user.ProfileImageUrl) ? "admin/uploads/default/noprofile.png" : user.ProfileImageUrl,// profile picture should be of this person// can take it from local. ==> user.prfilePicUrl comment_datetime = DateTime.UtcNow.ToString("f", CultureInfo.InvariantCulture) }; Comments.Add(newComment); //firstComment var noCommentsLabel = listContainer.Children.FirstOrDefault(s => s.ClassId == "NoCommentContainer"); if (noCommentsLabel != null) { listContainer.Children.Remove(noCommentsLabel); noCommentsLabel = null; } GenerateCommentView(newComment); // update the label with current comment count. if (Comments.Count > 0) { commentLabel.Text = "Comments(" + Comments.Count + ")"; } else { commentLabel.Text = "Comments"; } } catch (Exception ex) { } } else { progressBar.HideProgressbar(); progressBar.ShowToast("Could not save the comment now, please try again later"); } newCommentEntry.Text = string.Empty; } catch (Exception) { isPosting = false; progressBar.ShowToast("Could not save the comment now, please try again later"); } addCommentButtonTap.Tapped += addCommentButtonTapped; }