package com.gh.gamecenter.message;

import android.content.Context;
import android.content.Intent;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;

import com.gh.common.util.NewLogUtils;
import com.gh.gamecenter.common.base.activity.BaseActivity;
import com.gh.common.databind.BindingAdapters;
import com.gh.gamecenter.common.constant.Constants;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.common.utils.TextHelper;
import com.gh.gamecenter.core.utils.ClickUtils;
import com.gh.common.util.DirectUtils;
import com.gh.gamecenter.common.utils.ImageUtils;
import com.gh.gamecenter.core.utils.DisplayUtils;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.common.util.NewsUtils;
import com.gh.gamecenter.CommentDetailActivity;
import com.gh.gamecenter.GameDetailActivity;
import com.gh.gamecenter.MessageDetailActivity;
import com.gh.gamecenter.NewsDetailActivity;
import com.gh.gamecenter.R;
import com.gh.gamecenter.WebActivity;
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder;
import com.gh.gamecenter.common.callback.OnListClickListener;
import com.gh.gamecenter.common.retrofit.Response;
import com.gh.gamecenter.databinding.MessageItemBinding;
import com.gh.gamecenter.common.entity.CommunityEntity;
import com.gh.gamecenter.entity.MessageEntity;
import com.gh.gamecenter.entity.MessageFold;
import com.gh.gamecenter.feature.entity.UserEntity;
import com.gh.gamecenter.gamecollection.detail.GameCollectionDetailActivity;
import com.gh.gamecenter.gamedetail.rating.RatingReplyActivity;
import com.gh.gamecenter.login.user.UserManager;
import com.gh.gamecenter.qa.answer.detail.SimpleAnswerDetailActivity;
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity;
import com.gh.gamecenter.qa.comment.NewCommentDetailActivity;
import com.gh.gamecenter.feature.entity.Questions;
import com.gh.gamecenter.qa.dialog.AskFollowMoreDialog;
import com.gh.gamecenter.qa.questions.newdetail.NewQuestionDetailActivity;
import com.gh.gamecenter.qa.video.detail.ForumVideoDetailActivity;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.gh.gamecenter.video.detail.VideoDetailContainerViewModel;
import com.lightgame.utils.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import retrofit2.HttpException;

import static com.gh.gamecenter.gamedetail.rating.edit.RatingEditActivity.LABEL_REGEX;

/**
 * Created by khy on 23/03/18.
 */

public class MessageItemViewHolder extends BaseRecyclerViewHolder<MessageEntity> {
    MessageItemBinding mBinding;

    // 外层信息，MTA 用
    private String mOuterInfo;

    public MessageItemViewHolder(MessageItemBinding binding,
                                 OnListClickListener listClickListener,
                                 String outerInfo) {
        super(binding.getRoot(), listClickListener);
        mOuterInfo = outerInfo;
        mBinding = binding;
        mBinding.messageOriginal.setOnClickListener(this);
        mBinding.messageItem.setOnClickListener(this);
    }

    public void setMessageItem(MessageEntity messageEntity, Context context, String entrance) {
        mBinding.messageItem.setBackground(ContextCompat.getDrawable(mBinding.getRoot().getContext(), R.drawable.reuse_listview_item_style));
        mBinding.messageOriginal.setBackground(ContextCompat.getDrawable(mBinding.getRoot().getContext(), R.drawable.bg_shape_space_radius_8));
        mBinding.messageUserName.setTextColor(ContextCompat.getColor(mBinding.getRoot().getContext(), R.color.text_title));
        mBinding.messageUserMore.setTextColor(ContextCompat.getColor(mBinding.getRoot().getContext(), R.color.theme_font));
        mBinding.messageCommand.setTextColor(ContextCompat.getColor(mBinding.getRoot().getContext(), R.color.text_title));
        mBinding.messageTime.setTextColor(ContextCompat.getColor(mBinding.getRoot().getContext(), R.color.text_subtitleDesc));
        mBinding.messageContent.setTextColor(ContextCompat.getColor(mBinding.getRoot().getContext(), R.color.text_subtitle));
        mBinding.messageOriginalTitle.setTextColor(ContextCompat.getColor(mBinding.getRoot().getContext(), R.color.text_subtitleDesc));

        setClickData(messageEntity);
        if (messageEntity.getUserEntity().getAuth() != null) {
            mBinding.messageUserIcon.display(messageEntity.getUserEntity().getBorder(), messageEntity.getUserEntity().getIcon(), messageEntity.getUserEntity().getAuth().getIcon());
        } else {
            mBinding.messageUserIcon.display(messageEntity.getUserEntity().getBorder(), messageEntity.getUserEntity().getIcon(), null);
        }
        BindingAdapters.showHide(mBinding.messageUnread, !messageEntity.getRead());
        mBinding.messageUserName.setText(messageEntity.getUserEntity().getName());


        mBinding.messageTime.setText(NewsUtils.getFormattedTime(messageEntity.getTime()));
        List<String> images;
        List<MessageEntity.Video> videos;
        String targetUrl = null; // 防止串行
        String imageCommentStr = "[图片评论]";
        String content = "";
        switch (messageEntity.getType()) {
            case "answer":
                mBinding.messageCommand.setText("回答了你的问题");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getAnswer().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getQuestion().getTitle());
                videos = messageEntity.getQuestion().getVideos();
                if (videos.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, videos.get(0).getPoster());
                } else {
                    images = messageEntity.getQuestion().getImages();
                    if (images.size() > 0) {
                        mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                        ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                    } else {
                        mBinding.messageOriginalIcon.setVisibility(View.GONE);
                    }
                }
                voteMoreUser(messageEntity);
                break;
            case "reply":
                mBinding.messageCommand.setText("回复了你");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getDialogue().getFrom().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getDialogue().getTo().getContent());
                targetUrl = messageEntity.getArticle().getThumb();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "follow_question":
                mBinding.messageCommand.setText("回答了你关注的问题");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getAnswer().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getQuestion().getTitle());
                images = messageEntity.getAnswer().getImages();
                if (images.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                }
                voteMoreUser(messageEntity);
                break;
            case "reply_answer_comment":
                mBinding.messageCommand.setText("回复了你");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getDialogue().getFrom().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getDialogue().getTo().getContent());
                mBinding.messageOriginalIcon.setVisibility(View.GONE);
                voteMoreUser(messageEntity);
                break;
            case "answer_comment":
                mBinding.messageCommand.setText("回复了你的回答");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getComment().getContent();
                if (messageEntity.getAnswer().getContent() != null) {
                    mBinding.messageOriginalTitle.setText(messageEntity.getAnswer().getContent().replace(imageCommentStr, ""));
                }
                images = messageEntity.getAnswer().getImages();
                if (images.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                }
                voteMoreUser(messageEntity);
                break;
            case "answer_vote":
                mBinding.messageCommand.setText("赞同你的回答");
                mBinding.messageContent.setVisibility(View.GONE);
                if (messageEntity.getAnswer().getContent() != null) {
                    mBinding.messageOriginalTitle.setText(messageEntity.getAnswer().getContent().replace(imageCommentStr, ""));
                }
                images = messageEntity.getAnswer().getImages();
                if (images.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                }
                voteMoreUser(messageEntity);
                break;
            case "comment_vote":
                mBinding.messageCommand.setText("赞了你了你的评论");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getArticle().getTitle());
                targetUrl = messageEntity.getArticle().getThumb();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "answer_comment_vote":
                mBinding.messageCommand.setText("赞了你的评论");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getComment().getContent());
                mBinding.messageOriginalIcon.setVisibility(View.GONE);
                voteMoreUser(messageEntity);
                break;
            case "community_article_comment_vote":
            case "video_comment_vote":
                mBinding.messageCommand.setText("赞了你的评论");
                mBinding.messageContent.setVisibility(View.GONE);
                if (messageEntity.getComment().getContent() != null) {
                    mBinding.messageOriginalTitle.setText(messageEntity.getComment().getContent().replace(imageCommentStr, ""));
                }
                images = messageEntity.getComment().getImages();
                if (images.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                }
                voteMoreUser(messageEntity);
                break;
            case "invited":
                mBinding.messageCommand.setText("邀请你回答");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getQuestion().getTitle());
                videos = messageEntity.getQuestion().getVideos();
                if (videos.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, videos.get(0).getPoster());
                } else {
                    images = messageEntity.getQuestion().getImages();
                    if (images.size() > 0) {
                        mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                        ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                    } else {
                        mBinding.messageOriginalIcon.setVisibility(View.GONE);
                    }
                }
                voteMoreUser(messageEntity);
                break;
            case "system_invited":
                mBinding.messageCommand.setText("有新问题等你回答");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getQuestion().getTitle());
                videos = messageEntity.getQuestion().getVideos();
                if (videos.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, videos.get(0).getPoster());
                } else {
                    images = messageEntity.getQuestion().getImages();
                    if (images.size() > 0) {
                        mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                        ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                    } else {
                        mBinding.messageOriginalIcon.setVisibility(View.GONE);
                    }
                }
                voteMoreUser(messageEntity);
                break;
            case "community_article_vote":
                mBinding.messageCommand.setText("赞同你的帖子");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getArticle().getTitle());
                videos = messageEntity.getArticle().getVideos();
                if (videos.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, videos.get(0).getPoster());
                } else {
                    images = messageEntity.getArticle().getImages();
                    if (images.size() > 0) {
                        mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                        ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                    } else {
                        mBinding.messageOriginalIcon.setVisibility(View.GONE);
                    }
                }
                voteMoreUser(messageEntity);
                break;
            case "community_article_comment":
                mBinding.messageCommand.setText("评论了你的帖子");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getComment().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getArticle().getTitle());
                videos = messageEntity.getArticle().getVideos();
                if (videos.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, videos.get(0).getPoster());
                } else {
                    images = messageEntity.getArticle().getImages();
                    if (images.size() > 0) {
                        mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                        ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                    } else {
                        mBinding.messageOriginalIcon.setVisibility(View.GONE);
                    }
                }
                voteMoreUser(messageEntity);
                break;
            case "community_article_comment_reply_vote":
            case "video_comment_reply_vote":
                mBinding.messageCommand.setText("赞了你的回复");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getComment().getContent());
                mBinding.messageOriginalIcon.setVisibility(View.GONE);
                voteMoreUser(messageEntity);
                break;
            case "game_comment_reply_vote":
                mBinding.messageCommand.setText("赞了你的回复");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getReply().getContent());
                mBinding.messageOriginalIcon.setVisibility(View.GONE);
                voteMoreUser(messageEntity);
                break;
            case "reply_community_article_comment":
            case "video_comment_reply":
                if ("reply".equals(messageEntity.getDialogue().getTo().getType())) {
                    mBinding.messageCommand.setText("回复了你");
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageCommand.setText("回复了你的评论");
                    images = messageEntity.getDialogue().getTo().getImages();
                    if (images.size() > 0) {
                        mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                        ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                    } else {
                        mBinding.messageOriginalIcon.setVisibility(View.GONE);
                    }
                }
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getDialogue().getFrom().getContent();
                if (messageEntity.getDialogue().getTo().getContent() != null) {
                    mBinding.messageOriginalTitle.setText(messageEntity.getDialogue().getTo().getContent().replace(imageCommentStr, ""));
                }
                voteMoreUser(messageEntity);
                break;
            case "update-answer":
                mBinding.messageCommand.setText("更新了回答");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getAnswer().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getQuestion().getTitle());
                images = messageEntity.getAnswer().getImages();
                if (images.size() > 0) {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.displayIcon(mBinding.messageOriginalIcon, images.get(0));
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                }
                voteMoreUser(messageEntity);
                break;
            case "game_comment_vote":
                mBinding.messageCommand.setText("赞了你的评价");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getComment().getContent());
                targetUrl = messageEntity.getGame().getDefaultIcon();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "game_comment_reply":
                mBinding.messageCommand.setText("回复了你的评价");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getReply().getContent();
                String parentId = messageEntity.getReply().getParent().getId();
                // parentContent为空代表是回复评价中的回复，否则是回复游戏评价
                if (!TextUtils.isEmpty(parentId)) {
                    mBinding.messageOriginalTitle.setText(messageEntity.getReply().getParent().getContent());
                } else {
                    String comment = messageEntity.getReply().getComment();
                    if (comment != null) {
                        comment = comment.replace("\n", "");
                        Pattern p = Pattern.compile(LABEL_REGEX);
                        Matcher m = p.matcher(comment);
                        if (m.find()) {
                            SpannableStringBuilder contents = TextHelper.getCommentLabelSpannableStringBuilder(comment, R.color.text_subtitleDesc);
                            ExtensionsKt.setTextWithHighlightedTextWrappedInsideWrapper(
                                    mBinding.messageOriginalTitle,
                                    contents,
                                    Constants.DEFAULT_TEXT_WRAPPER,
                                    R.color.text_subtitleDesc,
                                    false,
                                    null
                            );
                        } else {
                            ExtensionsKt.setTextWithHighlightedTextWrappedInsideWrapper(
                                    mBinding.messageOriginalTitle,
                                    comment,
                                    Constants.DEFAULT_TEXT_WRAPPER,
                                    R.color.text_subtitleDesc,
                                    false,
                                    null
                            );
                        }
                    }
                }
                targetUrl = messageEntity.getGame().getDefaultIcon();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "video_comment":
                mBinding.messageCommand.setText("评论了你的帖子");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getComment().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getVideo().getTitle());
                targetUrl = messageEntity.getVideo().getPoster();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "video_vote":
                mBinding.messageCommand.setText("赞同了你的视频");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getVideo().getTitle());
                targetUrl = messageEntity.getVideo().getPoster();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "reply_activity_comment":
                mBinding.messageCommand.setText("回复了你");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getDialogue().getFrom().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getActivity().getTitle());
                targetUrl = messageEntity.getActivity().getImageUrl();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "activity_comment_vote":
                mBinding.messageCommand.setText("赞了你的评论");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getActivity().getTitle());
                targetUrl = messageEntity.getActivity().getImageUrl();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "activity_comment_reply_vote":
                mBinding.messageCommand.setText("赞了你的回复");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getActivity().getTitle());
                targetUrl = messageEntity.getActivity().getImageUrl();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "game_list_vote":
                mBinding.messageCommand.setText("赞了你的游戏单");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getGameList().getTitle());
                targetUrl = messageEntity.getGameList().getCover();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "game_list_comment":
                mBinding.messageCommand.setText("评价了你的游戏单");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getComment().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getGameList().getTitle());
                targetUrl = messageEntity.getGameList().getCover();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "game_list_comment_vote":
                mBinding.messageCommand.setText("赞了你的评评价");
                mBinding.messageContent.setVisibility(View.GONE);
                mBinding.messageOriginalTitle.setText(messageEntity.getComment().getContent());
                targetUrl = messageEntity.getGameList().getCover();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
            case "game_list_comment_reply":
                mBinding.messageCommand.setText("回复了你的游戏单评价");
                mBinding.messageContent.setVisibility(View.VISIBLE);
                content = messageEntity.getComment().getContent();
                mBinding.messageOriginalTitle.setText(messageEntity.getComment().getParent().getContent());
                targetUrl = messageEntity.getGameList().getCover();
                if (TextUtils.isEmpty(targetUrl)) {
                    mBinding.messageOriginalIcon.setVisibility(View.GONE);
                } else {
                    mBinding.messageOriginalIcon.setVisibility(View.VISIBLE);
                    ImageUtils.display(mBinding.messageOriginalIcon, targetUrl);
                }
                voteMoreUser(messageEntity);
                break;
        }

        TextHelper.highlightTextThatIsWrappedInsideWrapperByDefault(mBinding.messageContent, content);

        mBinding.messageOriginalTitle.post(() -> {
            ViewGroup.LayoutParams params = mBinding.messageOriginal.getLayoutParams();
            if (mBinding.messageOriginalTitle.getLineCount() > 1 || mBinding.messageOriginalIcon.getVisibility() == View.VISIBLE) {
                params.height = DisplayUtils.dip2px(52F);
            } else {
                params.height = DisplayUtils.dip2px(36F);
            }
            mBinding.messageOriginal.setLayoutParams(params);
        });

        mBinding.messageUserMore.setOnClickListener(v -> {
            MessageEntity.Fold fold = messageEntity.getFold();
            if (fold != null && !ClickUtils.isFastDoubleClick(mBinding.messageUserMore.getId(), 1000)) {
                getFoldList(context, messageEntity.getFold().getResourceId());
            }
        });
        mBinding.messageUserIcon.setOnClickListener(v -> {
            MtaHelper.onEvent("消息中心", mOuterInfo, "点击头像");
            NewLogUtils.logMessageInformUserClick("message_inform_user_icon_click");
            DirectUtils.directToHomeActivity(itemView.getContext(), messageEntity.getUserEntity().getId(), entrance, "消息中心-赞同及邀请");
        });
        mBinding.messageUserName.setOnClickListener(v -> {
            MtaHelper.onEvent("消息中心", mOuterInfo, "点击名字");
            NewLogUtils.logMessageInformUserClick("message_inform_user_name_click");
            DirectUtils.directToHomeActivity(itemView.getContext(), messageEntity.getUserEntity().getId(), entrance, "消息中心-邀同及赞请");
        });
    }

    private void voteMoreUser(MessageEntity messageEntity) {
        MessageEntity.Fold fold = messageEntity.getFold();
        if (fold != null && fold.getNumber() > 1) {
            mBinding.messageUserMore.setVisibility(View.VISIBLE);
            mBinding.messageUserMore.setText((" 等" + fold.getNumber() + "人"));
        } else {
            mBinding.messageUserMore.setVisibility(View.GONE);
        }
    }

    private void getFoldList(Context context, String resourceId) {
        RetrofitManager
                .getInstance()
                .getApi()
                .getMessageFoldList(UserManager.getInstance().getUserId(), resourceId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Response<List<MessageFold>>() {
                    @Override
                    public void onResponse(@Nullable List<MessageFold> response) {

                        List<UserEntity> list = new ArrayList<>();
                        for (MessageFold messageFold : response) {
                            UserEntity user = messageFold.getUser();
                            user.setTime(messageFold.getTime());
                            list.add(user);
                        }

                        if (context instanceof FragmentActivity) {
                            AskFollowMoreDialog dialog = AskFollowMoreDialog.getInstance("赞同了你", "消息中心-折叠", (ArrayList<UserEntity>) list);
                            dialog.show(((FragmentActivity) context).getSupportFragmentManager(), "more");
                        }
                    }

                    @Override
                    public void onFailure(@Nullable HttpException e) {
                        Utils.toast(context, R.string.request_failure_normal_hint);
                    }
                });
    }

    public static void messageItemClickSkip(View view, MessageEntity entity, String entrance, String outerInfo, String path) {
        if (view == null || entity == null) return;
        Context context = view.getContext();
        CommunityEntity community;

        if (view.getId() == R.id.message_original) {
            MtaHelper.onEvent("消息中心", outerInfo, "点击链接");
        } else if (view.getId() == R.id.message_item) {
            MtaHelper.onEvent("消息中心", outerInfo, "点击卡片");
        }

        Intent intent;
        String messageType;
        switch (entity.getType()) {
            case "comment_vote":
                NewLogUtils.logMessageInformClick(
                        "",
                        entity.getArticle().getId(),
                        "", "",
                        "赞同"
                );
                if (view.getId() == R.id.message_original) {
                    intent = NewsDetailActivity.getIntentById(context, entity.getArticle().getId(), BaseActivity.mergeEntranceAndPath(entrance, path));
                    context.startActivity(intent);
                } else if (view.getId() == R.id.message_item) {
                    intent = MessageDetailActivity.getIntentById(context,
                            entity.getArticle().getId(), -1, false, BaseActivity.mergeEntranceAndPath(entrance, path));
                    context.startActivity(intent);
                }
                break;
            case "reply":
                NewLogUtils.logMessageInformClick(
                        "",
                        entity.getArticle().getId(),
                        "", "",
                        "普通消息"
                );
                if (view.getId() == R.id.message_original) {
                    intent = NewsDetailActivity.getIntentById(context, entity.getArticle().getId(), BaseActivity.mergeEntranceAndPath(entrance, path));
                    context.startActivity(intent);
                } else if (view.getId() == R.id.message_item) {
                    intent = CommentDetailActivity.getIntent(context, entity.getDialogue().getFrom().getId(), entity.getArticle());
                    context.startActivity(intent);
                }
                break;
            case "system_invited":
            case "invited":
                NewLogUtils.logMessageInformClick(
                        entity.getQuestion().getId(),
                        "", "", "",
                        "邀请"
                );
                if (view.getId() == R.id.message_original || view.getId() == R.id.message_item) {
                    MessageEntity.Question question = entity.getQuestion();
                    context.startActivity(NewQuestionDetailActivity.getIntent(context, question.getId(), entrance, path));

                    Questions questions = new Questions();
                    questions.setId(question.getId());
                    questions.setTitle(question.getTitle());
                }
                break;
            case "answer":
            case "answer_vote":
                if ("answer".equals(entity.getType())) {
                    messageType = "普通消息";
                } else {
                    messageType = "赞同";
                }
                NewLogUtils.logMessageInformClick(
                        entity.getQuestion().getId(),
                        "", "", "",
                        messageType
                );
                intent = NewQuestionDetailActivity.getSpecifiedCommentIntent(
                        context,
                        entity.getQuestion().getId(),
                        entity.getAnswer().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "update-answer":
            case "follow_question":
                NewLogUtils.logMessageInformClick(
                        entity.getQuestion().getId(),
                        "", "", "",
                        "普通消息"
                );
                if (view.getId() == R.id.message_original) {
                    MessageEntity.Question question = entity.getQuestion();
                    context.startActivity(NewQuestionDetailActivity.getCommentIntent(context, question.getId(), entity.getAnswer().getId(), entrance, path));
                } else if (view.getId() == R.id.message_item) {
                    context.startActivity(SimpleAnswerDetailActivity.getIntent(context, entity.getAnswer().getId(), entrance, path));
                }
                break;
            case "reply_answer_comment":
                NewLogUtils.logMessageInformClick(
                        entity.getQuestion().getId(),
                        "", "", "",
                        "普通消息"
                );
                intent = NewCommentDetailActivity.Companion.getAnswerCommentIntent(
                        context,
                        entity.getAnswer().getId(),
                        entity.getQuestion().getId(),
                        entity.getDialogue().getFrom().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "answer_comment_vote":
            case "answer_comment":
                if ("answer_comment".equals(entity.getType())) {
                    messageType = "普通消息";
                } else {
                    messageType = "赞同";
                }
                NewLogUtils.logMessageInformClick(
                        entity.getQuestion().getId(),
                        "", "", "",
                        messageType
                );
                intent = NewCommentDetailActivity.Companion.getAnswerCommentIntent(
                        context,
                        entity.getAnswer().getId(),
                        entity.getQuestion().getId(),
                        entity.getComment().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "community_article_comment_vote":
            case "community_article_comment":
                if ("community_article_comment".equals(entity.getType())) {
                    messageType = "普通消息";
                } else {
                    messageType = "赞同";
                }
                NewLogUtils.logMessageInformClick(
                        entity.getArticle().getId(),
                        "", "", "",
                        messageType
                );
                community = new CommunityEntity(entity.getArticle().getCommunityId(), "");
                intent = ArticleDetailActivity.getSpecifiedCommentIntent(
                        context,
                        community,
                        entity.getArticle().getId(),
                        entity.getComment().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "community_article_comment_reply_vote":
                NewLogUtils.logMessageInformClick(
                        entity.getArticle().getId(),
                        "", "", "",
                        "赞同"
                );
                intent = NewCommentDetailActivity.Companion.getArticleCommentIntent(
                        context,
                        entity.getComment().getTopId(),
                        entity.getArticle().getCommunityId(),
                        entity.getArticle().getId(),
                        entity.getComment().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "community_article_vote":
                NewLogUtils.logMessageInformClick(
                        entity.getArticle().getId(),
                        "", "", "",
                        "赞同"
                );
                community = new CommunityEntity(entity.getArticle().getCommunityId(), "");
                intent = ArticleDetailActivity.getIntent(
                        context,
                        community,
                        entity.getArticle().getId(),
                        entrance,
                        path,
                        null
                );
                context.startActivity(intent);
                break;
            case "reply_community_article_comment":
                NewLogUtils.logMessageInformClick(
                        entity.getArticle().getId(),
                        "", "", "",
                        "普通消息"
                );
                intent = NewCommentDetailActivity.Companion.getArticleCommentIntent(
                        context,
                        entity.getDialogue().getTo().getTopId(),
                        entity.getArticle().getCommunityId(),
                        entity.getArticle().getId(),
                        entity.getDialogue().getFrom().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "game_comment_vote":
                NewLogUtils.logMessageInformClick(
                        "", "",
                        entity.getGame().getId(),
                        "",
                        "赞同"
                );
                GameDetailActivity.startGameDetailActivity(
                        context,
                        entity.getGame().getId(),
                        BaseActivity.mergeEntranceAndPath(entrance, path),
                        -1,
                        true,
                        false,
                        false,
                        false,
                        null
                );
                break;
            case "game_comment_reply":
            case "game_comment_reply_vote":
                if ("game_comment_reply".equals(entity.getType())) {
                    messageType = "普通消息";
                } else {
                    messageType = "赞同";
                }
                NewLogUtils.logMessageInformClick(
                        "", "",
                        entity.getGame().getId(),
                        "",
                        messageType
                );
                intent = RatingReplyActivity.getSpecifiedCommentIntent(
                        context,
                        entity.getGame().getId(),
                        entity.getReply().getCommentId(),
                        entity.getReply().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "video_vote":
                NewLogUtils.logMessageInformClick(
                        entity.getVideo().getId(),
                        "", "", "",
                        "赞同"
                );
                DirectUtils.directToVideoDetail(
                        context,
                        entity.getVideo().getId(),
                        VideoDetailContainerViewModel.Location.SINGLE_VIDEO.getValue(),
                        false,
                        "",
                        entrance,
                        outerInfo,
                        ""
                );
                break;
            case "video_comment":
            case "video_comment_vote":
                if ("video_comment".equals(entity.getType())) {
                    messageType = "普通消息";
                } else {
                    messageType = "赞同";
                }
                NewLogUtils.logMessageInformClick(
                        entity.getVideo().getId(),
                        "", "", "",
                        messageType
                );
                intent = ForumVideoDetailActivity.Companion.getSpecifiedCommentIntent(
                        context,
                        entity.getVideo().getId(),
                        entity.getComment().getId()
                );
                context.startActivity(intent);
                break;
            case "video_comment_reply":
                NewLogUtils.logMessageInformClick(
                        entity.getVideo().getId(),
                        "", "", "",
                        "普通消息"
                );
                String commentId;
                if ("reply".equals(entity.getDialogue().getTo().getType())) {
                    commentId = entity.getDialogue().getTo().getTopId();
                } else {
                    commentId = entity.getDialogue().getTo().getId();
                }
                intent = NewCommentDetailActivity.Companion.getVideoCommentIntent(
                        context,
                        commentId,
                        entity.getVideo().getId(),
                        entity.getDialogue().getFrom().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "video_comment_reply_vote":
                NewLogUtils.logMessageInformClick(
                        entity.getVideo().getId(),
                        "", "", "",
                        "赞同"
                );
                intent = NewCommentDetailActivity.Companion.getVideoCommentIntent(
                        context,
                        entity.getComment().getTopId(),
                        entity.getVideo().getId(),
                        entity.getComment().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;

            case "reply_activity_comment":
            case "activity_comment_vote":
            case "activity_comment_reply_vote":
                if (view.getId() == R.id.message_original) {
                    context.startActivity(WebActivity.getIntent(context, entity.getActivity().getUrl(), true));
                } else if (view.getId() == R.id.message_item) {
                    context.startActivity(WebActivity.getIntent(context, entity.getActivity().getUrlComment(), true));
                }
                break;

            case "game_list_comment":
                NewLogUtils.logMessageInformClick(
                        "", "", "",
                        entity.getGameList().getId(),
                        "普通消息"
                );
                intent = GameCollectionDetailActivity.Companion.getSpecifiedCommentIntent(
                        context,
                        entity.getGameList().getId(),
                        entity.getComment().getId()
                );
                context.startActivity(intent);
                break;
            case "game_list_comment_vote":
                NewLogUtils.logMessageInformClick(
                        "", "", "",
                        entity.getGameList().getId(),
                        "赞同"
                );
                if (TextUtils.isEmpty(entity.getComment().getTopId())) {
                    intent = GameCollectionDetailActivity.Companion.getSpecifiedCommentIntent(
                            context,
                            entity.getGameList().getId(),
                            entity.getComment().getId()
                    );
                } else {
                    intent = NewCommentDetailActivity.Companion.getGameCollectionCommentIntent(
                            context,
                            entity.getComment().getTopId(),
                            entity.getGameList().getId(),
                            entity.getComment().getId(),
                            entrance,
                            path
                    );
                }
                context.startActivity(intent);
                break;
            case "game_list_comment_reply":
                NewLogUtils.logMessageInformClick(
                        "", "", "",
                        entity.getGameList().getId(),
                        "普通消息"
                );
                intent = NewCommentDetailActivity.Companion.getGameCollectionCommentIntent(
                        context,
                        entity.getComment().getTopId(),
                        entity.getGameList().getId(),
                        entity.getComment().getId(),
                        entrance,
                        path
                );
                context.startActivity(intent);
                break;
            case "game_list_vote":
                NewLogUtils.logMessageInformClick(
                        "", "", "",
                        entity.getGameList().getId(),
                        "赞同"
                );
                intent = GameCollectionDetailActivity.getIntent(
                        context,
                        entity.getGameList().getId(),
                        false
                );
                context.startActivity(intent);
                break;
        }
    }
}