package com.gh.gamecenter.qa.answer.detail

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import com.ethanhua.skeleton.Skeleton
import com.ethanhua.skeleton.SkeletonScreen
import com.facebook.drawee.view.SimpleDraweeView
import com.gh.common.history.HistoryHelper
import com.gh.common.util.*
import com.gh.common.util.LogUtils
import com.gh.common.view.RichEditor
import com.gh.gamecenter.ImageViewerActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.activity.ToolBarActivity
import com.gh.gamecenter.common.base.fragment.BaseFragment
import com.gh.gamecenter.common.base.fragment.ToolbarFragment
import com.gh.gamecenter.common.callback.ConfirmListener
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.entity.NormalShareEntity
import com.gh.gamecenter.common.entity.SuggestType
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.view.DrawableView
import com.gh.gamecenter.core.AppExecutor
import com.gh.gamecenter.core.utils.*
import com.gh.gamecenter.databinding.FragmentAnswerDetailBinding
import com.gh.gamecenter.databinding.PieceQuestionContentBinding
import com.gh.gamecenter.entity.*
import com.gh.gamecenter.feature.entity.MeEntity
import com.gh.gamecenter.feature.entity.Permissions
import com.gh.gamecenter.feature.entity.Questions
import com.gh.gamecenter.feature.entity.UserEntity
import com.gh.gamecenter.help.HelpAndFeedbackBridge
import com.gh.gamecenter.login.user.UserManager
import com.gh.gamecenter.qa.comment.CommentActivity
import com.gh.gamecenter.qa.dialog.MoreFunctionPanelDialog
import com.gh.gamecenter.qa.editor.OnLinkClickListener
import com.gh.gamecenter.qa.entity.AnswerDetailEntity
import com.gh.gamecenter.qa.entity.QuestionsDetailEntity
import com.gh.gamecenter.qa.questions.newdetail.NewQuestionDetailActivity
import com.gh.gamecenter.video.VideoVerifyItemViewHolder
import com.gh.gamecenter.video.detail.VideoDetailContainerViewModel
import com.halo.assistant.HaloApp
import com.lightgame.utils.Utils
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.io.IOException

open class AnswerDetailFragment : ToolbarFragment() {
    private var mPath: String? = ""
    private var mAnswerId: String = ""

    private var mAnswerStatus = ANSWER_STATUS_UNKNOWN

    private var mIsVisibleToUser: Boolean = false   // 判定当前 fragment 是否可见
    private var mIsRecommendsAnswer: Boolean = false // 是否跳转自问答精选
    private var mIsShowCommentManager: Boolean = false // 是否需要弹起评论对话框

    private var mViewedImageSet = hashSetOf<Int>()
    private val mAnswersImages: ArrayList<String> = arrayListOf()

    private var mSpecialColumn: SpecialColumn? = null
    private var mElapsedHelper: TimeElapsedHelper? = null
    private var mRefreshHeader: AnswerDetailRefreshHeader? = null
    private var mRefreshFooter: AnswerDetailRefreshFooter? = null
    private var mSkeletonScreen: SkeletonScreen? = null

    protected lateinit var mBinding: FragmentAnswerDetailBinding
    private lateinit var mQuestionBinding: PieceQuestionContentBinding
    lateinit var mViewModel: AnswerDetailViewModel
    private lateinit var mContainerViewModel: AnswerDetailContainerViewModel

    private var mImageViewList: ArrayList<SimpleDraweeView>? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mViewModel = viewModelProvider()
        mContainerViewModel = viewModelProviderFromParent()

        initObserver()
        onClickView()

        arguments?.let {
            mAnswerId = it.getString(EntranceConsts.KEY_ANSWER_ID) ?: ""

            mIsShowCommentManager = it.getBoolean(EntranceConsts.KEY_SHOW_ANSWER_COMMENT, false)
            mIsRecommendsAnswer = it.getBoolean(EntranceConsts.KEY_RECOMMENDS_CONTENTS, false)
            mPath = it.getString(EntranceConsts.KEY_PATH)
            mSpecialColumn = it.getParcelable(EntranceConsts.KEY_DATA)
            mViewModel.getAnswerDetail(mAnswerId)
        }
        mBinding.richEditor.enableForceDark(DarkModeUtils.isDarkModeOn(requireContext()))
        mBinding.richEditor.setTransparentBackground()
        mBinding.richEditor.setInputEnabled(false)
        mBinding.richEditor.setPadding(20, 15, 20, 15)
        mBinding.bottomController.replyTv.text = "说点什么吧"
        mBinding.bottomController.replyTv.setRoundedColorBackground(com.gh.gamecenter.common.R.color.ui_container_2, 19F)

        mElapsedHelper = TimeElapsedHelper(this)
        // 只对显示在屏幕上的 fragment 计时
        mElapsedHelper?.pauseCounting()

        initDrag()
    }

    @SuppressLint("AddJavascriptInterface")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        mBinding.richEditor.setImageListener(ImageListener())
        mBinding.richEditor.setOnLinkClickListener(
            OnLinkClickListener(requireContext(), "", "", mEntrance, "回答详情")
        )
        mSkeletonScreen =
            Skeleton.bind(mBinding.skeletonMask).load(R.layout.fragment_answer_detail_skeleton).shimmer(false).show()
        mImageViewList = arrayListOf(
            view.findViewById(R.id.questionsdetail_item_pic1),
            view.findViewById(R.id.questionsdetail_item_pic2),
            view.findViewById(R.id.questionsdetail_item_pic3)
        )
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        setNavigationTitle(getString(R.string.answer_detail_title))
    }

    override fun onStart() {
        super.onStart()
        // 返回时把点过的图片变为大图
        if (mAnswersImages != null && mAnswersImages.size > 0) {
            if (mViewedImageSet.size == mAnswersImages.size) {
                mBinding.richEditor.replaceAllDfImage()
            } else {
                for (i in mViewedImageSet) {
                    val url = mAnswersImages[i]
                    mBinding.richEditor.replaceDfImageByUrl(url)
                }
            }
            mViewedImageSet.clear()
        }
    }

    override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)
        mIsVisibleToUser = isVisibleToUser
        if (!isVisibleToUser && isResumed) {
            mElapsedHelper?.pauseCounting()
        } else if (isVisibleToUser && isResumed) {
            mElapsedHelper?.resumeCounting()
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        trackReadEvent()
    }

    override fun getLayoutId(): Int {
        return 0
    }

    override fun getInflatedLayout(): View? {
        mBinding = FragmentAnswerDetailBinding.inflate(layoutInflater, null, false)
        mQuestionBinding = mBinding.pieceQuestionContent
        return mBinding.root
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (data == null || activity == null) return

        if (resultCode == Activity.RESULT_OK &&
            (requestCode == ANSWER_PATCH_REQUEST || requestCode == ANSWER_POST_REQUEST)
        ) {
            if (mViewModel.answerDetail != null && requestCode == ANSWER_PATCH_REQUEST) {
                if (mAnswerId == data.getStringExtra(EntranceConsts.KEY_ANSWER_ID)) {
                    mViewModel.answerDetail?.content = data.getStringExtra(EntranceConsts.KEY_ANSWER_CONTENT) ?: ""
                    bindView(mViewModel.answerDetail)
                }
            }
            activity?.setResult(Activity.RESULT_OK, data)
        } else if (requestCode == ImageViewerActivity.REQUEST_FOR_VIEWED_IMAGE && resultCode == Activity.RESULT_OK) {
            mViewedImageSet = data.extras?.get(ImageViewerActivity.VIEWED_IMAGE) as HashSet<Int>
        } else if (requestCode == CommentActivity.REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            val count = data.getIntExtra(CommentActivity.COMMENT_COUNT, 0)
            if (count != 0) {
                mViewModel.answerDetail?.commentCount = count
                mBinding.bottomController.bottomCommentTv.text = NumberUtils.transSimpleCount(
                    mViewModel.answerDetail?.commentCount
                        ?: 0
                )

                if (EntranceConsts.ENTRANCE_WELCOME == mEntrance) {
                    LogUtils.uploadCommentFromWelcomeDialog()
                }
            }
        } else if (requestCode == QUESTION_DETAIL && resultCode == Activity.RESULT_OK) {
            val resultData =
                data.getParcelableExtra<QuestionsDetailEntity>(QuestionsDetailEntity::class.java.simpleName)
            mViewModel.answerDetail?.question?.title = resultData?.title ?: ""
            mViewModel.answerDetail?.question?.description = resultData?.description ?: ""
            bindView(mViewModel.answerDetail)
            mViewModel.answerDetail?.let {
                updateView(it)
            }
        } else if (requestCode == MoreFunctionPanelDialog.REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            mViewModel.answerDetail?.run {
                getItemClickCallback(this).invoke(data.getParcelableExtra(EntranceConsts.KEY_DATA))
            }
        }
    }

    private fun bindView(detail: AnswerDetailEntity?) {
        mBinding.titleTv.text = detail?.question?.title
        setContent(mBinding.richEditor, detail)
    }

    private fun setContent(richEditor: RichEditor, content: AnswerDetailEntity?) {
        if (TextUtils.isEmpty(content?.content)) {
            richEditor.visibility = View.GONE
        } else {
            richEditor.setContentOwner(content?.me?.isContentOwner ?: false)
            richEditor.setHtml(content?.content, true)
            richEditor.visibility = View.VISIBLE
        }
    }

    private fun initObserver() {
        mViewModel.answerLiveData.observe(this, Observer { apiResponse ->
            mBinding.scrollView.visibility = View.VISIBLE
            apiResponse?.let {
                if (apiResponse.data != null) {

                    val answerDetail = apiResponse.data

                    val nextAnswerId = answerDetail.nextId
                    if (nextAnswerId.isNotEmpty() && !mContainerViewModel.answerIdList.contains(nextAnswerId)) {
                        mContainerViewModel.appendAnswer(nextAnswerId)
                    }

                    bindView(answerDetail)

                    // 延迟不在屏幕上的页面的加载，缓解滑动切换答案卡顿
                    AppExecutor.uiExecutor.executeWithDelay(Runnable {
                        if (activity != null && !requireActivity().isFinishing) {
                            updateView(answerDetail)
                            updateDragHintAndListener()
                            mSkeletonScreen?.hide()
                        }
                    }, if (fragmentIsVisible()) 0 else 1000L)
                } else if (apiResponse.httpException != null) {
                    val e = apiResponse.httpException
                    mSkeletonScreen?.hide()
                    try {
                        if (e != null && e.code() == 404 && e.response().errorBody()!!.string().isNotEmpty()) {
                            HistoryHelper.deleteAnswerEntity(mAnswerId)

                            mBinding.bottomController.root.visibility = View.GONE
                            mBinding.reuseNoneData.reuseNoneDataTv.setText(com.gh.gamecenter.common.R.string.content_delete_hint)
                            mBinding.reuseNoneData.root.visibility = View.GONE
                            mBinding.reuseNoConnection.root.visibility = View.GONE
                            mBinding.reuseDataException.root.visibility = View.VISIBLE
                            mBinding.scrollView.visibility = View.GONE
                            mBinding.bottomDividerView.visibility = View.GONE
                            mBinding.bottomShadowView.visibility = View.GONE
                            if (mIsRecommendsAnswer) {
                                val activity = activity
                                if (activity != null) {
                                    val data = Intent()
                                    data.putExtra(EntranceConsts.KEY_ANSWER_ID, mAnswerId)
                                    activity.setResult(Activity.RESULT_OK, data)
                                    DialogHelper.showDialog(
                                        requireContext(),
                                        "提示",
                                        "很抱歉，内容可能已被删除",
                                        "关闭",
                                        "",
                                        { activity.finish() },
                                        extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true)
                                    )
                                }
                            } else {
                                Utils.toast(context, com.gh.gamecenter.common.R.string.content_delete_toast)
                            }
                        } else {
                            mBinding.reuseNoConnection.root.visibility = View.VISIBLE
                            mBinding.scrollView.visibility = View.GONE
                            mBinding.bottomController.root.visibility = View.GONE
                            mBinding.bottomDividerView.visibility = View.GONE
                            mBinding.bottomShadowView.visibility = View.GONE
                        }

                        if (activity is ToolBarActivity && mIsVisibleToUser) {
                            val menu = (activity as ToolBarActivity).menu
                            if (menu != null) {
                                for (i in 0 until menu.size()) {
                                    menu.getItem(i).isVisible = false
                                }
                            }
                        }
                    } catch (e1: IOException) {
                        e1.printStackTrace()
                    }
                }
            }
        })

        mViewModel.commentable.observeNonNull(this) {
            mViewModel.answerDetail?.let { answerDetail ->
                toggleComment(answerDetail.commentable, answerDetail.commentCount)
            }
        }

        mViewModel.collect.observeNonNull(this) {
            if (it) {
                toast(R.string.collection_success)
            } else {
                toast(R.string.collection_cancel)
            }
            updateCollectView(it)
        }

        mViewModel.voteLiveData.observe(this, Observer { apiResponse ->
            apiResponse?.let {
                if (mViewModel.answerDetail == null) return@Observer

                val answerDetail = mViewModel.answerDetail!!

                if (apiResponse.data != null) {
                    if (answerDetail.me.isAnswerVoted) {
                        ToastUtils.showToast("已赞同")
                        updateDislikeView(false)
                    } else {
                        ToastUtils.showToast("取消赞同")
                    }

                    updateLikeView(answerDetail.me.isAnswerVoted, answerDetail.vote)
                    if (apiResponse.data.isGuideFollow) {
                        showFollowHint()
                    }
                } else if (apiResponse.httpException != null) {
                    ErrorHelper.handleErrorWithCustomizedHandler(
                        requireContext(),
                        apiResponse.httpException.response().errorBody()?.string(),
                        false
                    ) {
                        when (it) {
                            403008 -> consume {
                                toast(R.string.ask_vote_hint)
                                answerDetail.me.isAnswerVoted = true
                                updateLikeView(answerDetail.me.isAnswerVoted, answerDetail.vote)
                            }
                            403036 -> consume { toast(R.string.ask_vote_limit_hint) }
                            else -> false
                        }
                    }
                }
            }
        })

        mViewModel.followLiveData.observe(this, Observer { isFollowed ->
            isFollowed?.let {
                if (isFollowed) {
                    toast(com.gh.gamecenter.feature.R.string.concern_success)
                    updateFollowBtn(true)
                    mBinding.followHintTv.visibility = View.GONE
                } else {
                    updateFollowBtn(false)
                }
            }
        })

        mViewModel.fold.observeNonNull(this) { isFold ->
            if (isFold) {
                if (mViewModel.answerDetail!!.me.moderatorPermissions.foldAnswer == Permissions.REPORTER) {
                    toast("提交成功")
                } else {
                    toast("操作成功")
                    requireActivity().setResult(BaseFragment.RESULT_REFRESH, null)
                    requireActivity().finish()
                }
            }
        }

        mViewModel.hide.observeNonNull(this) { isHidden ->
            if (isHidden) {
                if (mViewModel.answerDetail!!.me.moderatorPermissions.hideAnswer == Permissions.REPORTER) {
                    toast("提交成功")
                } else {
                    toast("操作成功")
                    mViewModel.getAnswerDetail(mAnswerId)
                    requireActivity().setResult(BaseFragment.RESULT_REFRESH, null)
                }
                requireActivity().finish()
            }
        }

        mViewModel.highlight.observeNonNull(this) { isHighlighted ->
            if (isHighlighted) {
                if (mViewModel.answerDetail!!.me.moderatorPermissions.highlightAnswer == Permissions.REPORTER) {
                    toast("提交成功")
                } else {
                    toast("操作成功")
                    requireActivity().finish()
                }
            }
        }

        mViewModel.dislike.observeNonNull(this) { disliked ->
            if (disliked) {
                toast("已反对")
                updateLikeView(false, mViewModel.answerDetail!!.vote)
            } else {
                toast("取消反对")
            }
            updateDislikeView(disliked)
        }
    }

    // 更新回答状态
    private fun updateAnswerStatus(me: MeEntity) {
        mAnswerStatus = if (!TextUtils.isEmpty(mViewModel.answerDetail!!.me.myAnswerId)) {
            if (mViewModel.answerDetail!!.me.isContentOwner) {
                ANSWERED_MY_ANSWER
            } else {
                ANSWERED_NOT_MY_ANSWER
            }
        } else if (mViewModel.answerDetail!!.me.hasDraft) {
            NOT_ANSWERED_BUT_HAVE_DRAFT
        } else {
            NOT_ANSWERED_YET
        }

        // 是否已回答
        when (mAnswerStatus) {
            ANSWERED_MY_ANSWER -> {
                mBinding.statusTv.setTextColor(com.gh.gamecenter.common.R.color.text_theme.toColor(mBinding.statusTv.context))
                DrawableView.setTextDrawable(
                    mBinding.statusTv,
                    R.drawable.community_question_edit_my_answer,
                    "修改回答"
                )
            }
            ANSWERED_NOT_MY_ANSWER -> {
                mBinding.statusTv.setTextColor(com.gh.gamecenter.common.R.color.text_tertiary.toColor(mBinding.statusTv.context))
                DrawableView.setTextDrawable(
                    mBinding.statusTv,
                    R.drawable.question_detail_myanswer_icon,
                    "我的回答"
                )
            }
            NOT_ANSWERED_BUT_HAVE_DRAFT -> {
                mBinding.statusTv.setTextColor(com.gh.gamecenter.common.R.color.text_theme.toColor(mBinding.statusTv.context))
                DrawableView.setTextDrawable(
                    mBinding.statusTv,
                    R.drawable.community_question_edit_icon,
                    "继续回答"
                )
            }
            NOT_ANSWERED_YET -> {
                mBinding.statusTv.setTextColor(com.gh.gamecenter.common.R.color.text_theme.toColor(mBinding.statusTv.context))
                DrawableView.setTextDrawable(
                    mBinding.statusTv,
                    R.drawable.community_question_edit_icon,
                    "我来回答"
                )
            }
        }

        if (me.isContentOwner) {
            mBinding.followTv.visibility = View.GONE
        } else {
            mBinding.followTv.isEnabled = true
            updateFollowBtn(me.isFollower)
        }
    }

    private fun toggleComment(enable: Boolean, commentCount: Int) {
        if (enable) {
            mBinding.bottomController.bottomCommentIv.setImageResource(R.drawable.ic_article_detail_comment_bottom_bar)
            mBinding.bottomController.bottomCommentTv.setTextColor(
                ContextCompat.getColor(
                    requireContext(),
                    com.gh.gamecenter.common.R.color.text_secondary
                )
            )
            mBinding.bottomController.bottomCommentTv.text = if (commentCount > 0) commentCount.toString() else "评论"
        } else {
            mBinding.bottomController.bottomCommentIv.setImageResource(R.drawable.community_content_detail_comment_close)
            mBinding.bottomController.bottomCommentTv.setTextColor(
                ContextCompat.getColor(
                    requireContext(),
                    com.gh.gamecenter.common.R.color.text_b3b3b3
                )
            )
            mBinding.bottomController.bottomCommentTv.text = "评论已关闭"
        }
    }

    /**
     * 初始化上下拉切换回答
     */
    private fun initDrag() {
        mRefreshHeader = AnswerDetailRefreshHeader(requireContext())
        mRefreshFooter = AnswerDetailRefreshFooter(requireContext())

        mBinding.refreshLayout.setRefreshHeader(mRefreshHeader!!)
        mBinding.refreshLayout.setRefreshFooter(mRefreshFooter!!)
        mBinding.refreshLayout.setReboundDuration(0)
        mBinding.refreshLayout.setEnableAutoLoadMore(false)
        mBinding.refreshLayout.setDragRate(.6f)

        updateDragHintAndListener()
    }

    private fun updateDragHintAndListener() {
        if (mContainerViewModel.answerIdList.isEmpty()
            || mContainerViewModel.answerIdList.first() == mAnswerId
        ) {
            mRefreshHeader?.REFRESH_HEADER_PULLING = "不能向上翻页了"
            mRefreshHeader?.REFRESH_HEADER_RELEASE = "不能向上翻页了"
            mRefreshHeader?.setArrowDrawable(null)
            mBinding.refreshLayout.setOnRefreshListener { mBinding.refreshLayout.finishRefresh(0) }
        } else {
            mRefreshHeader?.REFRESH_HEADER_PULLING = "下拉查看上一个回答"
            mRefreshHeader?.REFRESH_HEADER_RELEASE = "松开查看上一个回答"
            mBinding.refreshLayout.setOnRefreshListener {
                trackReadEvent()
                mBinding.refreshLayout.finishRefresh(0)
                mContainerViewModel.showPreviousAnswer()
            }
        }

        if (mContainerViewModel.answerIdList.isEmpty()
            || mContainerViewModel.answerIdList.last() == mAnswerId
        ) {
            mRefreshFooter?.REFRESH_FOOTER_PULLING = "不能向下翻页了"
            mRefreshFooter?.REFRESH_FOOTER_RELEASE = "不能向下翻页了"
            mRefreshFooter?.setArrowDrawable(null)
            mBinding.refreshLayout.setOnLoadMoreListener { mBinding.refreshLayout.finishLoadMore(0) }
        } else {
            showDragHintDialog()
            mRefreshFooter?.REFRESH_FOOTER_PULLING = "上拉查看下一个回答"
            mRefreshFooter?.REFRESH_FOOTER_RELEASE = "松开查看下一个回答"
            mRefreshFooter?.restoreArrow()
            mBinding.refreshLayout.setOnLoadMoreListener {
                trackReadEvent()
                mContainerViewModel.showNextAnswer()
                mBinding.refreshLayout.finishLoadMore(0)
                // 进入下一个回答后把上一个答案的滚动距离重置
                AppExecutor.uiExecutor.executeWithDelay(Runnable {
                    if (activity != null && !requireActivity().isFinishing) {
                        mBinding.scrollView.scrollTo(0, 0)
                    }
                }, 300L)
            }
        }
    }

    private fun trackReadEvent() {
        mViewModel.answerDetail?.let {
            // 在外部有 ViewPager 包裹时可能触发多次阅读事件，所以这里过滤掉时长为 0 的事件不发
            if (mElapsedHelper?.elapsedTime != 0) {
                mViewModel.trackReadEvent(
                    mAnswerId,
                    it,
                    mElapsedHelper?.elapsedTime ?: 0,
                    mEntrance,
                    mPath ?: "",
                    mSpecialColumn
                )
            }
            mElapsedHelper?.resetCounting()
        }
    }

    override fun onMenuItemClick(menuItem: MenuItem) {
        when (menuItem.itemId) {
            R.id.menu_more -> mViewModel.answerDetail?.let { showMoreItemDialog(it) }
            R.id.menu_question_and_answer -> {
                val community = mViewModel.answerDetail?.community
                MtaHelper.onEvent(
                    "进入问答",
                    "回答详情",
                    community?.name + "+" + StringUtils.combineTwoString(
                        mViewModel.answerDetail?.content,
                        mViewModel.answerDetail?.id
                    )
                )
                LogUtils.qaAccess("回答详情-进入问答", community)
                DirectUtils.directToCommunity(requireContext(), community)
            }
        }
    }

    private fun showFollowHint() {
        if (mBinding.followTv.visibility == View.VISIBLE && !mViewModel.answerDetail!!.me.isContentOwner) {
            mBinding.followHintTv.visibility = View.VISIBLE
            mBinding.followHintTv.alpha = 0.0f
            mBinding.followHintTv.animate().alpha(1.0f).setDuration(750L).start()
            AppExecutor.uiExecutor.executeWithDelay(Runnable {
                if (activity != null && !requireActivity().isFinishing) {
                    mBinding.followHintTv.visibility = View.GONE
                }
            }, 3000L)
        }
    }

    private fun showMoreItemDialog(answer: AnswerDetailEntity) {
        if (fragmentIsVisible()) {
            val entities = ArrayList<MenuItemEntity>()
            if (answer.user.id != UserManager.getInstance().userId) {
                entities.add(MenuItemEntity("投诉", R.drawable.icon_gamedetail_copyright))
            }
            if (answer.me.isModerator) {
                val isEnable = answer.isHighlighted || answer.user.id == UserManager.getInstance().userId
                entities.add(
                    MenuItemEntity(
                        "加精", if (isEnable)
                            R.drawable.icon_more_panel_essence_unenable else R.drawable.icon_more_panel_essence,
                        isEnable = !isEnable
                    )
                )

                entities.add(MenuItemEntity("折叠", R.drawable.icon_more_panel_fold))
            }
            if (answer.user.id == UserManager.getInstance().userId) {
                entities.add(
                    MenuItemEntity(
                        if (answer.commentable) "关闭评论" else "恢复评论",
                        if (answer.commentable) R.drawable.icon_more_panel_close_comment_enable
                        else R.drawable.icon_more_panel_close_comment_unenable
                    )
                )
            }
            if (answer.me.isModerator || answer.user.id == UserManager.getInstance().userId) {
                entities.add(MenuItemEntity("删除", R.drawable.icon_more_panel_delete))
            }

            MoreFunctionPanelDialog.showMoreDialog(
                requireActivity() as AppCompatActivity, entities, answer.question.title
                    ?: "", getShareEntity(answer), "", tag ?: ""
            )

        }
    }

    private fun getShareEntity(answer: AnswerDetailEntity): NormalShareEntity {
        return NormalShareEntity(
            id = mAnswerId,
            shareUrl = if (isPublishEnv()) {
                getString(R.string.share_answers_url, mAnswerId)
            } else {
                getString(R.string.share_answers_url_dev, answer.question.id, mAnswerId)
            },
            shareIcon = if (mAnswersImages!!.size > 0) {
                mAnswersImages[0]
            } else {
                getString(R.string.share_ghzs_logo)
            },
            shareTitle = getString(
                R.string.ask_share_answers_title,
                answer.user.name,
                answer.question.title,
                answer.vote
            ),
            shareSummary = if (TextUtils.isEmpty(mBinding.richEditor.text)) {
                getString(R.string.ask_share_default_summary)
            } else {
                mBinding.richEditor.text
            },
            shareEntrance = ShareUtils.ShareEntrance.answerNormal
        )
    }

    private fun getItemClickCallback(answer: AnswerDetailEntity): (menuItem: MenuItemEntity?) -> Unit {
        return {
            when (it?.text) {
                "投诉" -> {
                    HelpAndFeedbackBridge.startSuggestionActivity(
                        context,
                        SuggestType.APP,
                        "report",
                        "回答投诉（$mAnswerId）："
                    )
                }
                "加精" -> {
                    addEssenceForum(answer)
                }
                "折叠" -> {
                    foldForum(answer)
                }
                "关闭评论", "恢复评论" -> {
                    if (mViewModel.answerDetail?.commentable!!) {
                        DialogHelper.showDialog(
                            requireContext(), "提示", "关闭评论之后，该回答将无法查看和发表评论，确定关闭吗？",
                            "确定", "取消", { mViewModel.toggleComment(mAnswerId, false) },
                            extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true)
                        )
                    } else {
                        DialogHelper.showDialog(
                            requireContext(), "提示", "确定恢复评论吗？",
                            "确定", "取消", { mViewModel.toggleComment(mAnswerId, true) },
                            extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true)
                        )
                    }
                }
                "删除" -> {
                    DialogHelper.showDialog(requireContext(), "提示", "删除回答后，其中的所有回复都将被删除", "删除", "取消", {
                        mViewModel.doHideThisAnswer(mAnswerId)
                    }, extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true))
                }
            }
        }
    }

    private fun addEssenceForum(answer: AnswerDetailEntity) {
        val reporterHint = "你的操作将提交给小编审核，确定提交吗？"
        val adminHint = "你的操作将立即生效，确定提交吗？（你的管理权限为：高级）"
        when {
            answer.me.isContentOwner -> toast("不能加精自己的回答")
            answer.isHighlighted -> toast("回答已经加精")
            else -> DialogHelper.showDialog(
                requireContext(),
                "加精回答",
                if (answer.me.moderatorPermissions.highlightAnswer == Permissions.REPORTER) reporterHint else adminHint,
                "确定", "取消",
                { mViewModel.doHighlightThisAnswer(mAnswerId) },
                extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true)
            )
        }
    }

    private fun foldForum(answer: AnswerDetailEntity) {
        val reporterHint = "你的操作将提交给小编审核，确定提交吗？"
        val adminHint = "你的操作将立即生效，确定提交吗？（你的管理权限为：高级）"
        if (answer.fold == true) {
            Utils.toast(requireContext(), "回答已经折叠")
        } else {
            DialogHelper.showDialog(
                requireContext(),
                "折叠回答",
                if (answer.me.moderatorPermissions.foldAnswer == Permissions.REPORTER) reporterHint else adminHint,
                "确定", "取消",
                { mViewModel.doFoldThisAnswer(mAnswerId) },
                extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true)
            )
        }
    }

    private fun createMenuItem(index: Int, item: MenuItemEntity): View {
        val view = LayoutInflater.from(requireContext()).inflate(R.layout.item_detail_more_menu, null, false)
        val iconIv = view.findViewById<ImageView>(R.id.iconIv)
        val actionNameTv = view.findViewById<TextView>(R.id.actionNameTv)
        iconIv.setImageDrawable(
            ContextCompat.getDrawable(
                requireContext(),
                if (item.disableIcon > 0) item.disableIcon else item.normalIcon
            )
        )
        actionNameTv.setTextColor(
            ContextCompat.getColor(
                requireContext(),
                if (item.disableIcon > 0) com.gh.gamecenter.common.R.color.text_tertiary else com.gh.gamecenter.common.R.color.text_primary
            )
        )
        view.isEnabled = item.disableIcon == 0
        actionNameTv.text = item.text
        if (index > 0) {
            val params = LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
            )
            params.topMargin = 1f.dip2px()
            view.layoutParams = params
        }
        return view
    }

    private fun onClickView() {
        val videoSize = if (!mViewModel.answerDetail?.question?.videos.isNullOrEmpty()) 1 else 0

        mBinding.reuseNoConnection.root.setOnClickListener {
            mBinding.reuseNoConnection.root.visibility = View.GONE
            mSkeletonScreen?.show()
            mViewModel.getAnswerDetail(mAnswerId)
        }
        mBinding.bottomController.bottomStarIv.setOnClickListener {
            ifLogin("回答详情-收藏") {
                mViewModel.answerDetail?.let {
                    if (!it.me.isAnswerFavorite) {
                        mViewModel.collectAnswer(mAnswerId)
                    } else {
                        mViewModel.cancelCollectAnswer(mAnswerId)
                    }
                }
            }
        }
        mBinding.answerCountContainer.setOnClickListener {
            if (mViewModel.answerDetail != null) {
                startActivity(
                    NewQuestionDetailActivity.getIntent(
                        requireContext(),
                        mViewModel.answerDetail!!.question.id,
                        mEntrance,
                        "回答详情"
                    )
                )
            }
        }
        mBinding.bottomController.bottomLikeIv.setOnClickListener {
            debounceActionWithInterval(R.id.container_like, 1000) {
                ifLogin("回答详情-赞同") {
                    if (mViewModel.answerDetail != null && !mViewModel.answerDetail!!.me.isAnswerVoted) {
                        mViewModel.like(mAnswerId)

                        if (EntranceConsts.ENTRANCE_WELCOME == mEntrance) {
                            LogUtils.uploadLikeFromWelcomeDialog()
                        }
                    } else {
                        mViewModel.cancelLike(mAnswerId)
                    }
                }
            }
        }

        mBinding.bottomController.bottomCommentIv.setOnClickListener {
            showCommentDialog(false)
        }
        mBinding.bottomController.replyTv.setOnClickListener {
            mViewModel.answerDetail?.run {
                if (commentable) {
                    showCommentDialog(true)
                } else {
                    toast("作者已关闭评论")
                }
            }
        }
        mBinding.userIconIv.setOnClickListener {
            DirectUtils.directToHomeActivity(requireContext(), mViewModel.answerDetail!!.user.id, mEntrance, "回答详情")
        }
        mBinding.followTv.setOnClickListener {
            SensorsBridge.trackUserFollowClick(
                userId = mViewModel.answerDetail?.user?.id ?: "",
                userName = mViewModel.answerDetail?.user?.name ?: "",
                buttonName = mBinding.followTv.text.toString()
            )
            ifLogin("回答详情-[关注]用户") {
                if (mBinding.followTv.text == "关注") {
                    mViewModel.follow(mViewModel.answerDetail!!.user.id!!)
                } else {
                    mViewModel.unfollow(mViewModel.answerDetail!!.user.id!!)
                }
            }
        }
        mBinding.pieceQuestionContent.questionsdetailItemPic1.setOnClickListener {
            val question = mViewModel.answerDetail?.question!!
            if (!question.videos.isNullOrEmpty()) {
                val videoEntity = question.videos[0]
                if (videoEntity.status == "pass") {
                    DirectUtils.directToVideoDetail(
                        requireContext(),
                        videoEntity.id,
                        VideoDetailContainerViewModel.Location.SINGLE_VIDEO.value,
                        path = "回答详情"
                    )
                } else if (videoEntity.status == "pending" ||
                    (!question.me.isContentOwner
                            && !question.me.isModerator
                            && videoEntity.status == "fail")
                ) {
                    toast("视频正在审核中")
                } else if (videoEntity.status == "fail") {
                    toast("视频审核未通过")
                }
            } else {
                showQuestionImageDetail(0)
            }
        }
        mBinding.pieceQuestionContent.questionsdetailItemPic2.setOnClickListener {
            showQuestionImageDetail(1 - videoSize)
        }
        mBinding.pieceQuestionContent.questionsdetailItemPic3.setOnClickListener {
            showQuestionImageDetail(2 - videoSize)
        }
    }

    private fun shareAnswer() {
        val shareIcon: String = if (mAnswersImages!!.size > 0) {
            mAnswersImages[0]
        } else {
            getString(R.string.share_ghzs_logo)
        }
        var shareSummary = mBinding.richEditor.text
        if (TextUtils.isEmpty(shareSummary)) {
            shareSummary = getString(R.string.ask_share_default_summary)
        }

        val answer = mViewModel.answerDetail

        if (answer != null) {
            val shareUrl = if (isPublishEnv()) {
                getString(R.string.share_answers_url, mAnswerId)
            } else {
                getString(R.string.share_answers_url_dev, answer.question.id, mAnswerId)
            }
            ShareUtils.getInstance(context).showShareWindows(
                activity,
                view,
                shareUrl,
                shareIcon,
                getString(R.string.ask_share_answers_title, answer.user.name, answer.question.title, answer.vote),
                shareSummary,
                ShareUtils.ShareEntrance.answerNormal, mAnswerId
            )
        }
    }

    private fun updateCollectView(isCollected: Boolean) {
        if (isCollected) {
            mBinding.bottomController.bottomStarIv.setImageResource(R.drawable.ic_article_detail_stared_bottom_bar)
            mBinding.bottomController.bottomStarTv.text = "已收藏"
            mBinding.bottomController.bottomStarTv.setTextColor(
                ContextCompat.getColor(
                    requireContext(),
                    com.gh.gamecenter.common.R.color.text_theme
                )
            )
        } else {
            mBinding.bottomController.bottomStarIv.setImageResource(R.drawable.ic_article_detail_star_bottom_bar)
            mBinding.bottomController.bottomStarTv.text = "收藏"
            mBinding.bottomController.bottomStarTv.setTextColor(
                ContextCompat.getColor(
                    requireContext(),
                    com.gh.gamecenter.common.R.color.text_secondary
                )
            )
        }
    }

    private fun showQuestionImageDetail(position: Int) {
        val images = ArrayList(mViewModel.answerDetail?.question?.images)

        if (position <= images.size) {
            val intent =
                ImageViewerActivity.getIntent(requireContext(), images, position, mImageViewList, "$mEntrance+(回答详情)")
            startActivity(intent)
        }
    }

    private fun showCommentDialog(showInputOnly: Boolean) {
        val intent = CommentActivity.getAnswerCommentIntent(
            requireContext(),
            mAnswerId,
            mViewModel.answerDetail?.commentCount ?: 0,
            showInputOnly, showInputOnly
        )
        requireActivity().startActivityForResult(intent, CommentActivity.REQUEST_CODE)
    }

    @SuppressLint("DefaultLocale", "SetTextI18n")
    private fun updateView(answerDetail: AnswerDetailEntity) {
        initMenu()
        hideLoadingViewAndShowContent()
        updateUserView(answerDetail.user)
        updateAnswerStatus(answerDetail.me)
        updateQuestionView(answerDetail.question)
        updateDislikeView(answerDetail.me.isAnswerOpposed)
        updateCollectView(answerDetail.me.isAnswerFavorite)
        updateLikeView(answerDetail.me.isAnswerVoted, answerDetail.vote)
        toggleComment(answerDetail.commentable, answerDetail.commentCount)

        if (answerDetail.publishTime == answerDetail.updateTime) {
            mBinding.timeTv.text = String.format("发布于 %s", NewsUtils.getFormattedTime(answerDetail.publishTime))
        } else {
            mBinding.timeTv.text = String.format("修改于 %s", NewsUtils.getFormattedTime(answerDetail.updateTime))
        }

        if (mIsShowCommentManager) {
            mIsShowCommentManager = false
            mBinding.bottomController.bottomCommentIv.performClick()
        }

        mBinding.richEditor.clearFocus()

        mBinding.scrollView.viewTreeObserver.addOnScrollChangedListener {
            try {
                if (mBinding.scrollView.scrollY > mBinding.titleContainer.top) {
                    var title = answerDetail.question.title
                    if (title != null && title.length > 10) {
                        title = title.substring(0, 10) + "..."
                    }
                    setNavigationTitle(title)
                } else {
                    setNavigationTitle(getString(R.string.answer_detail_title))
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }

    private fun hideLoadingViewAndShowContent() {
        mBinding.reuseNoConnection.root.visibility = View.GONE
        mBinding.bottomController.root.visibility = if (shouldShowBottomController()) View.VISIBLE else View.GONE
        mBinding.scrollView.visibility = View.VISIBLE
    }

    open fun shouldShowBottomController(): Boolean {
        return true
    }

    open fun shouldShowDragHint(): Boolean {
        return true
    }

    @SuppressLint("SetTextI18n")
    private fun updateQuestionView(question: Questions) {
        val video = if (!question.videos.isNullOrEmpty()) question.videos[0] else null
        val videoSize = if (video != null) 1 else 0
        mQuestionBinding.videoPlay.visibleIf(video != null)
        mQuestionBinding.videoStatus.visibleIf(video != null && video.status != "pass")
        mQuestionBinding.videoDuration.visibleIf(video?.status == "pass")
        if (video?.status == "pass") {
            mQuestionBinding.videoDuration.background = DrawableView.getOvalDrawable(com.gh.gamecenter.common.R.color.black_alpha_50, 999f)
            mQuestionBinding.videoDuration.text = video.duration
        } else {
            val status = if (!question.me.isContentOwner && !question.me.isModerator && video?.status == "fail") {
                "pending"
            } else video?.status ?: ""
            VideoVerifyItemViewHolder.setVideoStatus(mQuestionBinding.videoStatus, status)
        }

        if (video != null) {
            if (video.status == "pass") {
                mQuestionBinding.questionsdetailItemPic1.display(video.poster)
            } else {
                mQuestionBinding.questionsdetailItemPic1.setImageResource(R.drawable.community_video_default_poster)
            }
        }

        question.images.let { images ->
            for (i in images.indices) {
                val index = i + videoSize // view index
                val position = index - videoSize // data index
                if (images.size > position) {
                    when (index) {
                        0 -> ImageUtils.display(mQuestionBinding.questionsdetailItemPic1, images[position])
                        1 -> ImageUtils.display(mQuestionBinding.questionsdetailItemPic2, images[position])
                        2 -> {
                            ImageUtils.display(mQuestionBinding.questionsdetailItemPic3, images[position])
                            if (images.size + videoSize > 3) {
                                mQuestionBinding.questiondetailItemPic3Mask.visibility = View.VISIBLE
                                mQuestionBinding.questiondetailItemPic3Desc.visibility = View.VISIBLE
                                mQuestionBinding.questiondetailItemPic3Desc.text = "+${images.size + videoSize - 3}"
                            }
                        }
                    }
                }
            }

            if (images.size + videoSize > 0) {
                mQuestionBinding.questionsdetailItemPicll.visibility = View.VISIBLE
            } else {
                mQuestionBinding.questionsdetailItemPicll.visibility = View.GONE
            }
        }

        mQuestionBinding.questionsdetailItemDes.visibility = if (question.description.isNullOrEmpty()) {
            View.GONE
        } else {
            mQuestionBinding.questionsdetailItemDes.initWidth(resources.displayMetrics.widthPixels - 40F.dip2px())
            mQuestionBinding.questionsdetailItemDes.maxLines = 3
            mQuestionBinding.questionsdetailItemDes.setOriginalText(question.description)
            View.VISIBLE
        }

        mBinding.answerCountTv.text = String.format("查看全部%d个回答", question.answerCount)

        // 作为 viewpager 里的第一个回答时隐藏问题内容
        if (mContainerViewModel.answerIdList.isNotEmpty() && mAnswerId == mContainerViewModel.answerIdList.first()) {
            mBinding.questionContainer.visibility = View.VISIBLE
        } else {
            mBinding.questionContainer.visibility = View.GONE
        }
    }

    private fun updateUserView(user: UserEntity) {
        mBinding.usernameTv.text = user.name
        mBinding.userIconIv.display(user.border, user.icon, user.auth?.icon)

        if (user.badge != null) {
            mBinding.sdvUserBadge.visibility = View.VISIBLE
            mBinding.tvBadgeName.visibility = View.VISIBLE
            ImageUtils.display(mBinding.sdvUserBadge, user.badge?.icon)
            mBinding.tvBadgeName.text = user.badge?.name
        } else {
            mBinding.sdvUserBadge.visibility = View.GONE
            mBinding.tvBadgeName.visibility = View.GONE
        }
        mBinding.sdvUserBadge.setOnClickListener {
            DialogUtils.showViewBadgeDialog(requireContext(), user.badge, object : ConfirmListener {
                override fun onConfirm() {
                    MtaHelper.onEvent("进入徽章墙_用户记录", "回答详情", "${user.name}（${user.id}）")
                    MtaHelper.onEvent("徽章中心", "进入徽章中心", "回答详情")
                    DirectUtils.directToBadgeWall(requireContext(), user.id, user.name, user.icon)
                }
            })
        }
        mBinding.tvBadgeName.setOnClickListener { mBinding.sdvUserBadge.performClick() }
    }

    private fun initMenu() {
        if (fragmentIsVisible()) {
            (requireActivity() as ToolBarActivity).clearMenu()

            initMenu(R.menu.menu_answer)
        }
    }

    private fun fragmentIsVisible(): Boolean {
        return isResumed && mIsVisibleToUser
    }

    private fun updateFollowBtn(isFollowed: Boolean) {
        mBinding.followTv.visibility = View.VISIBLE
        if (isFollowed) {
            DrawableView.setTextDrawable(mBinding.followTv, null, "已关注")
            mBinding.followTv.setTextColor(com.gh.gamecenter.common.R.color.text_tertiary.toColor(mBinding.followTv.context))
        } else {
            mBinding.followTv.background = DrawableView.getOvalDrawable(com.gh.gamecenter.common.R.color.ui_background, 2F)
            mBinding.followTv.setTextColor(com.gh.gamecenter.common.R.color.text_theme.toColor(mBinding.followTv.context))
            DrawableView.setTextDrawable(
                mBinding.followTv,
                R.drawable.answer_detail_follow_icon,
                com.gh.gamecenter.feature.R.string.concern.toResString()
            )
        }
    }

    @SuppressLint("SetTextI18n")
    private fun updateLikeView(alreadyVoted: Boolean, voteCount: Int) {
//        mBinding.bottomController.bottomLikeTv.text = "赞同 ${NumberUtils.transSimpleCount(voteCount)}"
        if (alreadyVoted) {
            mBinding.bottomController.bottomLikeIv.setImageResource(R.drawable.ic_article_detail_liked_bottom_bar)
            mBinding.bottomController.bottomLikeTv.text = NumberUtils.transSimpleCount(voteCount)
            mBinding.bottomController.bottomLikeTv.setTextColor(
                ContextCompat.getColor(
                    requireContext(),
                    com.gh.gamecenter.common.R.color.text_theme
                )
            )
        } else {
            mBinding.bottomController.bottomLikeIv.setImageResource(R.drawable.ic_article_detail_like_bottom_bar)
            mBinding.bottomController.bottomLikeTv.text = "赞同"
            mBinding.bottomController.bottomLikeTv.setTextColor(
                ContextCompat.getColor(
                    requireContext(),
                    com.gh.gamecenter.common.R.color.text_secondary
                )
            )
        }
    }

    private fun updateDislikeView(disliked: Boolean) {
//        if (disliked) {
//            mBinding.bottomController.ivDislike.setImageResource(R.drawable.community_content_detail_oppose_select)
//        } else {
//            mBinding.bottomController.ivDislike.setImageResource(R.drawable.community_content_detail_oppose_unselect)
//        }
    }

    private fun showDragHintDialog() {
        if (!shouldShowDragHint()) return
        val hasShownDragHint = SPUtils.getBoolean(SHOWN_DRAG_HINT, false)
        if (hasShownDragHint) {
            return
        }

        SPUtils.setBoolean(SHOWN_DRAG_HINT, true)
        val dialog = Dialog(requireContext(), com.gh.gamecenter.common.R.style.DialogWindowTransparent)
        dialog.setCancelable(false)
        val window = dialog.window
        window?.setGravity(Gravity.BOTTOM)
        dialog.show()
        val viewDialog = LayoutInflater.from(context).inflate(R.layout.dialog_answer_drag_hint, null)
        viewDialog.findViewById<View>(R.id.tv_ok).setOnClickListener { dialog.dismiss() }
        dialog.setContentView(viewDialog)
    }

    inner class ImageListener : RichEditor.ImageListener {

        override fun onImageClick(url: String) {
            when {
                url.contains("web_load_dfimg_icon.png") -> mBaseHandler.post { mBinding.richEditor.replaceAllDfImageExcludeGif() }
                //url.contains(RichEditor.IMAGE_FLAG_THUMBNAIL) -> mBaseHandler.post { mBinding.richEditor.replaceDfImageByUrl(url) }
                else -> {
                    var current = 0
                    var i = 0
                    val size = mAnswersImages!!.size
                    while (i < size) {
                        if (url.contains(mAnswersImages[i])) {
                            current = i
                        }
                        i++
                    }
                    val intent = ImageViewerActivity.getIntent(
                        requireContext(), mAnswersImages, current,
                        mEntrance + "+(回答详情[" + mBinding.titleTv.text.toString() + "])"
                    )
                    startActivityForResult(intent, ImageViewerActivity.REQUEST_FOR_VIEWED_IMAGE)
                }
            }
        }


        override fun onImageLoad(url: String) {
            val defUrl = url.split("\\?".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0]
            if (!mAnswersImages!!.contains(defUrl) && !url.contains("web_load_dfimg_icon.png")) {
                mAnswersImages.add(defUrl)
            }
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onEventMainThread(reuse: EBReuse) {
        if (reuse.type == Constants.LOGIN_TAG && !TextUtils.isEmpty(mAnswerId)) { // 登入
            mViewModel.getAnswerDetail(mAnswerId)
        }
    }

    companion object {
        private const val ANSWER_STATUS_UNKNOWN = 0
        private const val ANSWERED_MY_ANSWER = 1
        private const val ANSWERED_NOT_MY_ANSWER = 2
        private const val NOT_ANSWERED_YET = 3
        private const val NOT_ANSWERED_BUT_HAVE_DRAFT = 4

        private const val ANSWER_PATCH_REQUEST = 100
        private const val ANSWER_POST_REQUEST = 101
        private const val QUESTION_DETAIL = 102

        private const val SHOWN_DRAG_HINT = "shown_drag_hint"
        const val TAG = "ask.AnswerDetailFragment"
    }
}

