Esempio n. 1
0
        IEnumerable <Widget> _buildComments(BuildContext context)
        {
            List <string> channelComments = new List <string>();

            if (this.widget.viewModel.channelMessageList.ContainsKey(this._article.channelId))
            {
                channelComments = this.widget.viewModel.channelMessageList[this._article.channelId];
            }
            var mediaQuery = MediaQuery.of(context);
            var comments   = new List <Widget> {
                new Container(
                    color: CColors.White,
                    width: mediaQuery.size.width,
                    padding: EdgeInsets.only(16, 16, 16),
                    child: new Text(
                        "评论",
                        style: CTextStyle.H5,
                        textAlign: TextAlign.left
                        )
                    )
            };

            var titleHeight = CTextUtils.CalculateTextHeight(
                "评论",
                CTextStyle.H5,
                mediaQuery.size.width - 16 * 2, // 16 is horizontal padding
                null
                ) + 16;                         // 16 is top padding

            var height = mediaQuery.size.height - navBarHeight - 44 - mediaQuery.padding.vertical;

            if (channelComments.Count == 0)
            {
                var blankView = new Container(
                    height: height - titleHeight,
                    child: new BlankView(
                        "快来写下第一条评论吧",
                        "image/default-comment"
                        )
                    );
                comments.Add(item: blankView);
                return(comments);
            }

            var   messageDict    = this.widget.viewModel.channelMessageDict[this._article.channelId];
            float contentHeights = 0;

            foreach (var commentId in channelComments)
            {
                if (!messageDict.ContainsKey(commentId))
                {
                    break;
                }

                var  message    = messageDict[commentId];
                bool isPraised  = _isPraised(message, this.widget.viewModel.loginUserId);
                var  parentName = "";
                if (message.parentMessageId.isNotEmpty())
                {
                    if (messageDict.ContainsKey(message.parentMessageId))
                    {
                        var parentMessage = messageDict[message.parentMessageId];
                        parentName = parentMessage.author.fullName;
                    }
                }

                var content = MessageUtils.AnalyzeMessage(message.content, message.mentions,
                                                          message.mentionEveryone) + (parentName.isEmpty() ? "" : $"回复@{parentName}");
                var contentHeight = CTextUtils.CalculateTextHeight(
                    content,
                    CTextStyle.PLargeBody,
                    // 16 is horizontal padding, 24 is avatar size, 8 is content left margin to avatar
                    mediaQuery.size.width - 16 * 2 - 24 - 8,
                    null
                    ) + 16 + 24 + 3 + 5 + 22 + 12;
                // 16 is top padding, 24 is avatar size, 3 is content top margin to avatar, 5 is content bottom margin to commentTime
                // 22 is commentTime height, 12 is commentTime bottom margin
                contentHeights += contentHeight;
                var card = new CommentCard(
                    message,
                    isPraised,
                    parentName,
                    () => ReportManager.showReportView(this.widget.viewModel.isLoggedIn,
                                                       commentId,
                                                       ReportType.comment, this.widget.actionModel.pushToLogin, this.widget.actionModel.pushToReport
                                                       ),
                    replyCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        AnalyticsManager.ClickComment("Article_Comment", this._article.channelId,
                                                      this._article.title, commentId);
                        ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                                  message.author.fullName.isEmpty() ? "" : message.author.fullName,
                                                                  text => {
                            ActionSheetUtils.hiddenModalPopup();
                            this.widget.actionModel.sendComment(this._article.channelId,
                                                                text,
                                                                Snowflake.CreateNonce(),
                                                                commentId
                                                                );
                        })
                                                              );
                    }
                },
                    praiseCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        if (isPraised)
                        {
                            this.widget.actionModel.removeLikeComment(message);
                        }
                        else
                        {
                            this.widget.actionModel.likeComment(message);
                        }
                    }
                });
                comments.Add(card);
            }

            float endHeight = 0;

            if (!this._article.hasMore)
            {
                comments.Add(new Container(
                                 height: 52,
                                 alignment: Alignment.center,
                                 child: new Text(
                                     "一 已经全部加载完毕 一",
                                     style: CTextStyle.PRegularBody4,
                                     textAlign: TextAlign.center
                                     )
                                 ));
                endHeight = 52;
            }
            if (titleHeight + contentHeights + endHeight < height)
            {
                return(new List <Widget> {
                    new Container(
                        height: height,
                        child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: comments
                            )
                        )
                });
            }
            return(comments);
        }
Esempio n. 2
0
        IEnumerable <Widget> _buildComments(BuildContext context)
        {
            List <string> channelComments = new List <string>();

            if (this.widget.viewModel.channelMessageList.ContainsKey(key: this._article.channelId))
            {
                channelComments = this.widget.viewModel.channelMessageList[key : this._article.channelId];
            }

            var mediaQuery = MediaQuery.of(context);
            var comments   = new List <Widget> {
                new Container(
                    color: CColors.White,
                    width: mediaQuery.size.width,
                    padding: EdgeInsets.only(16, 16, 16),
                    child: new Text(
                        "评论",
                        style: CTextStyle.H5,
                        textAlign: TextAlign.left
                        )
                    )
            };

            var titleHeight = CTextUtils.CalculateTextHeight(
                "评论",
                CTextStyle.H5,
                mediaQuery.size.width - 16 * 2, // 16 is horizontal padding
                null
                ) + 16;                         // 16 is top padding

            float safeAreaPadding = 0;

            if (Application.platform != RuntimePlatform.Android)
            {
                safeAreaPadding = mediaQuery.padding.vertical;
            }

            var height = mediaQuery.size.height - navBarHeight - 44 - safeAreaPadding;

            if (channelComments.Count == 0)
            {
                var blankView = new Container(
                    height: height - titleHeight,
                    child: new BlankView(
                        "快来写下第一条评论吧",
                        "image/default-comment"
                        )
                    );
                comments.Add(item: blankView);
                return(comments);
            }

            var   messageDict    = this.widget.viewModel.channelMessageDict[key : this._article.channelId];
            float contentHeights = 0;

            foreach (var commentId in channelComments)
            {
                if (!messageDict.ContainsKey(key: commentId))
                {
                    break;
                }

                var  message        = messageDict[key : commentId];
                bool isPraised      = _isPraised(message: message, loginUserId: this.widget.viewModel.loginUserId);
                var  parentName     = "";
                var  parentAuthorId = "";
                if (message.upperMessageId.isNotEmpty())
                {
                    if (messageDict.ContainsKey(key: message.upperMessageId))
                    {
                        var parentMessage = messageDict[key : message.upperMessageId];
                        parentName     = parentMessage.author.fullName;
                        parentAuthorId = parentMessage.author.id;
                    }
                }
                else if (message.parentMessageId.isNotEmpty())
                {
                    if (messageDict.ContainsKey(key: message.parentMessageId))
                    {
                        var parentMessage = messageDict[key : message.parentMessageId];
                        parentName     = parentMessage.author.fullName;
                        parentAuthorId = parentMessage.author.id;
                    }
                }

                var content = MessageUtils.AnalyzeMessage(message.content, message.mentions,
                                                          message.mentionEveryone) + (parentName.isEmpty() ? "" : $"回复@{parentName}");
                var contentHeight = CTextUtils.CalculateTextHeight(
                    content,
                    CTextStyle.PLargeBody,
                    // 16 is horizontal padding, 24 is avatar size, 8 is content left margin to avatar
                    mediaQuery.size.width - 16 * 2 - 24 - 8,
                    null
                    ) + 16 + 24 + 3 + 5 + 22 + 12;
                // 16 is top padding, 24 is avatar size, 3 is content top margin to avatar, 5 is content bottom margin to commentTime
                // 22 is commentTime height, 12 is commentTime bottom margin
                contentHeights += contentHeight;
                var card = new CommentCard(
                    message: message,
                    isPraised: isPraised,
                    parentName: parentName,
                    parentAuthorId: parentAuthorId,
                    () => ReportManager.showReportView(
                        isLoggedIn: this.widget.viewModel.isLoggedIn,
                        reportType: ReportType.comment,
                        () => this.widget.actionModel.pushToLogin(),
                        () => this.widget.actionModel.pushToReport(arg1: commentId, arg2: ReportType.comment)
                        ),
                    replyCallBack: () => this._sendComment(
                        "Article_Comment",
                        message.parentMessageId.isNotEmpty() ? message.parentMessageId : commentId,
                        message.parentMessageId.isNotEmpty() ? commentId : "",
                        message.author.fullName.isEmpty() ? "" : message.author.fullName
                        ),
                    praiseCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        if (isPraised)
                        {
                            this.widget.actionModel.removeLikeComment(arg: message);
                        }
                        else
                        {
                            this.widget.actionModel.likeComment(arg: message);
                        }
                    }
                },
                    pushToUserDetail: this.widget.actionModel.pushToUserDetail
                    );
                comments.Add(item: card);
            }

            float endHeight = 0;

            if (!this._article.hasMore)
            {
                comments.Add(new EndView());
                endHeight = 52;
            }

            if (titleHeight + contentHeights + endHeight < height)
            {
                return(new List <Widget> {
                    new Container(
                        height: height,
                        child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: comments
                            )
                        )
                });
            }

            return(comments);
        }
Esempio n. 3
0
        List <Widget> _buildComments()
        {
            if (this._channelComments.isEmpty())
            {
                return(new List <Widget>());
            }

            var comments = new List <Widget>();

            if (!this.widget.viewModel.channelMessageDict.ContainsKey(this._channelId))
            {
                return(comments);
            }

            var messageDict = this.widget.viewModel.channelMessageDict[this._channelId];

            foreach (var commentId in this._channelComments)
            {
                if (!messageDict.ContainsKey(commentId))
                {
                    break;
                }

                var  message    = messageDict[commentId];
                bool isPraised  = _isPraised(message, this.widget.viewModel.loginUserId);
                var  parentName = "";
                if (message.parentMessageId.isNotEmpty())
                {
                    if (messageDict.ContainsKey(message.parentMessageId))
                    {
                        var parentMessage = messageDict[message.parentMessageId];
                        parentName = parentMessage.author.fullName;
                    }
                }

                var card = new CommentCard(
                    message,
                    isPraised,
                    parentName,
                    () => ReportManager.showReportView(this.widget.viewModel.isLoggedIn,
                                                       commentId,
                                                       ReportType.comment, this.widget.actionModel.pushToLogin, this.widget.actionModel.pushToReport
                                                       ),
                    replyCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                                  message.author.fullName.isEmpty() ? "" : message.author.fullName,
                                                                  text => {
                            ActionSheetUtils.hiddenModalPopup();
                            this.widget.actionModel.sendComment(this._channelId,
                                                                text,
                                                                Snowflake.CreateNonce(),
                                                                commentId
                                                                );
                        })
                                                              );
                    }
                },
                    praiseCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        if (isPraised)
                        {
                            this.widget.actionModel.removeLikeComment(commentId);
                        }
                        else
                        {
                            this.widget.actionModel.likeComment(commentId);
                        }
                    }
                });
                comments.Add(card);
            }

            return(comments);
        }
        List <Widget> _buildComments()
        {
            if (this._channelComments.Count == 0)
            {
                return(new List <Widget>());
            }

            var comments = new List <Widget> {
                new Container(
                    color: CColors.White,
                    padding: EdgeInsets.only(16, 16, 16),
                    child: new Text(
                        "评论",
                        style: CTextStyle.H5,
                        textAlign: TextAlign.left
                        )
                    )
            };

            var messageDict = this.widget.viewModel.channelMessageDict[this._channelId];

            foreach (var commentId in this._channelComments)
            {
                if (!messageDict.ContainsKey(commentId))
                {
                    break;
                }

                var  message    = messageDict[commentId];
                bool isPraised  = _isPraised(message, this.widget.viewModel.loginUserId);
                var  parentName = "";
                if (message.parentMessageId.isNotEmpty())
                {
                    if (messageDict.ContainsKey(message.parentMessageId))
                    {
                        var parentMessage = messageDict[message.parentMessageId];
                        parentName = parentMessage.author.fullName;
                    }
                }

                var card = new CommentCard(
                    message,
                    isPraised,
                    parentName,
                    () => ReportManager.showReportView(this.widget.viewModel.isLoggedIn,
                                                       commentId,
                                                       ReportType.comment, this.widget.actionModel.pushToLogin, this.widget.actionModel.pushToReport
                                                       ),
                    replyCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        AnalyticsManager.ClickComment("Article_Comment", this._article.channelId,
                                                      this._article.title, commentId);
                        ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                                  message.author.fullName.isEmpty() ? "" : message.author.fullName,
                                                                  text => {
                            ActionSheetUtils.hiddenModalPopup();
                            this.widget.actionModel.sendComment(this._channelId,
                                                                text,
                                                                Snowflake.CreateNonce(),
                                                                commentId
                                                                );
                        })
                                                              );
                    }
                },
                    praiseCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        if (isPraised)
                        {
                            this.widget.actionModel.removeLikeComment(message);
                        }
                        else
                        {
                            this.widget.actionModel.likeComment(message);
                        }
                    }
                });
                comments.Add(card);
            }

            return(comments);
        }