public AllComments(ObservableCollection <Comment> Comments, string itemName, Guid selectedComment = new Guid())
        {
            try
            {
                NavigationPage.SetBackButtonTitle(this, "");
                //HockeyApp.MetricsManager.TrackEvent("AllComments Initialize");


                StringBuilder HTMLComments = new StringBuilder();
                HTMLComments.Append("<html><body>");
                foreach (Comment item in Comments)
                {
                    // var photoUrl = Common.CurrentWorkspace.WorkspaceURL + item.UserCreated.PhotoUrl;

                    if (item == null)
                    {
                        continue;
                    }
                    string userHTML = string.Empty;
                    if (!string.IsNullOrEmpty(item.UserCreated.PhotoUrl))
                    {
                        userHTML = string.Format("<img src='{0}'>", Common.CurrentWorkspace.WorkspaceURL + item.UserCreated.PhotoUrl);
                    }
                    else
                    {
                        if (item.UserCreated.AvatarHtml != String.Empty)
                        {
                            userHTML  = "<style>.user-avatar {font-family: 'Open Sans',segoe ui,verdana,helvetica;width: 50px!important;height: 50px!important;border-radius: 2px;line-height: 50px!important;font-size: 32px!important;color: #fff;text-align: center;margin: 0 !important;vertical-align: middle;overflow: hidden;cursor: pointer;display: inline-block;}</style>";
                            userHTML += item.UserCreated.AvatarHtml;
                        }
                    }


                    DateTime CreatedDate = DateTime.Now;

                    if (item.CreatedDateTimeUTC != null)
                    {
                        CreatedDate = TimeZoneInfo.ConvertTimeFromUtc(item.CreatedDateTimeUTC.Value, TimeZoneInfo.Local);
                    }
                    var body = item.CommentBodyRendered;
                    HTMLComments.Append(
                        CommentsHelperClass.CreateHtmlComments(
                            item.UserCreated.FirstName + " " + item.UserCreated.LastName,
                            userHTML,
                            CreatedDate,
                            body.Replace("<img ", "<img style='max-width: 100%;' "), item.Id == selectedComment)
                        );
                }
                //this.viewModel = viewModel;
                //BindingContext = viewModel;

                InitializeComponent();

                Title = itemName;

                // Adding style to HTMLComments Template
                HTMLComments.Append(CommentsHelperClass.GetHtmlCommentsStyle());
                HTMLComments.Append("</body></html>");

                var htmlString = HTMLComments.ToString();
                wvAllComments.Source = new HtmlWebViewSource()
                {
                    Html = htmlString
                };

                //var hybridWebView = new CustomControls.HybridWebView();
                //hybridWebView.Uri = htmlString;
                //hybridWebView.HeightRequest = 600;
                //slComments.Children.Add(hybridWebView);
            }
            catch (Exception ex)
            {
            }
        }
示例#2
0
        public async void ShowComments()
        {
            try
            {
                comments = new List <Comment>();
                comments = await CommentsService.GetAll(relatedId);

                if (comments.Count == 0)
                {
                    return;
                }
                if (comments.Count > 4)
                {
                    btnSeeAll.IsVisible = true;
                }
                else
                {
                    btnSeeAll.IsVisible = false;
                }

                viewModel.Comments = new ObservableCollection <Comment>(comments.Take(4));

                if (slComments.Children.Count > 0)
                {
                    slComments.Children.RemoveAt(0);
                }
                StringBuilder HTMLComments = new StringBuilder();
                if (Device.RuntimePlatform.ToLower() == "android")
                {
                    HTMLComments.Append("<html><body>");
                }
                else
                {
                    HTMLComments.Append("<html><head><meta name='viewport' content='width=device-width; height=device-height; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;'/></head><body>");
                }


                foreach (Comment item in viewModel.Comments)
                {
                    string body = item.CommentBody;
                    body = item.CommentBodyRendered;
                    while (body.Contains("display:none"))
                    {
                        int from = body.Substring(0, body.IndexOf("display:none")).LastIndexOf("<");
                        int to   = body.IndexOf(">", body.IndexOf("display:none;\">") + 15) + 1;
                        body = body.Substring(0, from) + body.Substring(to);
                    }
                    string commentBody = Regex.Replace(body, "<.*?>", String.Empty);
                    //string commentBody = item.CommentBody;
                    bool isCommentCut = false;
                    if (commentBody.Length > 100)
                    {
                        commentBody  = commentBody.Substring(0, 100) + "...";
                        isCommentCut = true;
                    }
                    // var photoUrl = Common.CurrentWorkspace.WorkspaceURL + item.UserCreated.PhotoUrl;


                    string userHTML = string.Empty;
                    if (!string.IsNullOrEmpty(item.UserCreated.PhotoUrl))
                    {
                        userHTML = string.Format("<img src='{0}'>", Common.CurrentWorkspace.WorkspaceURL + item.UserCreated.PhotoUrl);
                    }
                    else
                    {
                        if (item.UserCreated.AvatarHtml != String.Empty)
                        {
                            userHTML  = "<style>.user-avatar {font-family: 'Open Sans',segoe ui,verdana,helvetica;width: 60px!important;height: 60px!important;border-radius: 2px;line-height: 60px!important;font-size: 32px!important;color: #fff;text-align: center;margin: 0 !important;vertical-align: middle;overflow: hidden;cursor: pointer;display: inline-block;}</style>";
                            userHTML += item.UserCreated.AvatarHtml;
                        }
                    }



                    HTMLComments.Append(
                        CommentsHelperClass.CreateHtmlCommentsWithSeeMore(
                            item.UserCreated.Name,
                            userHTML,
                            item.CreatedDateTimeUTC != null ? (DateTime)item.CreatedDateTimeUTC : DateTime.Now,
                            commentBody, item.Id.ToString(),
                            isCommentCut)
                        );
                }

                HTMLComments.Append(CommentsHelperClass.GetHtmlCommentsWithSeeMoreStyle());
                HTMLComments.Append("</body></html>");
                var htmlString    = HTMLComments.ToString();
                var hybridWebView = new CustomControls.HybridWebView();
                hybridWebView.Uri = htmlString;
                hybridWebView.RegisterAction(data => OpenAllComments(data));
                hybridWebView.HorizontalOptions = LayoutOptions.FillAndExpand;
                hybridWebView.VerticalOptions   = LayoutOptions.FillAndExpand;
                hybridWebView.HeightRequest     = 450;
                hybridWebView.Margin            = 0;
                hybridWebView.BackgroundColor   = Color.Transparent;

                slComments.Children.Add(hybridWebView);
            }
            catch (Exception ex)
            {
                //return null;
            }
        }