package com.gh.gamecenter.forum.home

import android.app.Activity
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Bitmap
import android.graphics.Typeface
import android.os.Build
import android.os.Bundle
import android.view.*
import android.view.animation.AnimationUtils
import android.widget.TextView
import androidx.core.graphics.ColorUtils
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.gh.common.util.NewLogUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.TrackableDialog
import com.gh.gamecenter.common.base.adapter.FragmentAdapter
import com.gh.gamecenter.common.base.fragment.LazyFragment
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.core.utils.MtaHelper
import com.gh.gamecenter.databinding.FragmentCommunityHomeBinding
import com.gh.gamecenter.databinding.TabItemCommunityBinding
import com.gh.gamecenter.eventbus.EBSkip
import com.gh.gamecenter.eventbus.EBTypeChange
import com.gh.gamecenter.eventbus.EBUISwitch
import com.gh.gamecenter.feature.entity.ArticleEntity
import com.gh.gamecenter.feature.entity.ForumVideoEntity
import com.gh.gamecenter.forum.search.ForumOrUserSearchActivity
import com.gh.gamecenter.fragment.MainWrapperFragment
import com.gh.gamecenter.qa.article.edit.ArticleEditActivity
import com.gh.gamecenter.qa.questions.edit.QuestionEditActivity
import com.gh.gamecenter.qa.video.publish.VideoPublishActivity
import com.google.android.material.tabs.TabLayout
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import kotlin.math.abs
import kotlin.math.roundToInt

class CommunityHomeFragment : LazyFragment() {

    private var mBinding: FragmentCommunityHomeBinding? = null
    private var mViewModel: CommunityHomeViewModel? = null
    private var mFragmentList = arrayListOf<Fragment>()
    private var mTitleList = arrayListOf("推荐", "论坛", "活动")
    private var mTabList = arrayListOf<Any>()
    private var mDefaultSelectedTab = -1
    private var mNavigationBitmap: Bitmap? = null

    override fun getRealLayoutId(): Int {
        return R.layout.fragment_community_home
    }

    override fun onRealLayoutInflated(inflatedView: View) {
        mBinding = FragmentCommunityHomeBinding.bind(inflatedView)
    }

    override fun onFragmentFirstVisible() {
        mViewModel = viewModelProvider()

        super.onFragmentFirstVisible()

        initViewPager()
    }

    override fun initRealView() {
        super.initRealView()

        mViewModel?.articleLiveData?.observeNonNull(viewLifecycleOwner) {
            insertDataToRecommendTab(it)
        }

        mBinding?.run {
            topBg.visibleIf(!mIsDarkModeOn)
            searchContainer.setOnClickListener {
                NewLogUtils.logCommunitySearchClick()
                NewLogUtils.logForumSearchEnter("社区搜索栏")
                requireContext().startActivity(ForumOrUserSearchActivity.getIntent(requireContext(), "", "论坛首页"))
            }

            communityEditBtn.setOnClickListener {
                NewLogUtils.logRecommendFeedPublishClick()
                showCommunityEditWindow()
            }

            topBg.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
                override fun onGlobalLayout() {
                    topBg.viewTreeObserver.removeOnGlobalLayoutListener(this)
                    if (topBg.width <= 0 || topBg.height <= 0) return
                    val bitmap = topBg.getBitmapFromView()
                    bitmap?.let {
                        mNavigationBitmap = Bitmap.createBitmap(
                            it,
                            0,
                            0,
                            it.width,
                            DisplayUtils.getStatusBarHeight(resources) + 52F.dip2px()
                        )
                    }
                }
            })
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        savedInstanceState?.let { mDefaultSelectedTab = it.getInt(LAST_SELECTED_POSITION) }
    }

    override fun onSaveInstanceState(outState: Bundle) {
        mBinding?.viewPager?.let { outState.putInt(LAST_SELECTED_POSITION, it.currentItem) }
        super.onSaveInstanceState(outState)
    }

    override fun onFragmentResume() {
        super.onFragmentResume()

        DisplayUtils.setLightStatusBar(requireActivity(), !mIsDarkModeOn)
        NewLogUtils.logCommunityHomeEvent("view_community")
    }

    fun setCurrentItem(index: Int) {
        mBinding?.viewPager?.currentItem = index
    }

    private fun initViewPager() {
        val defaultSelectedPosition =
            if (mDefaultSelectedTab != -1) mDefaultSelectedTab
            else arguments?.getInt(EntranceConsts.KEY_SUB_POSITION) ?: 0

        mBinding?.run {
            mTabList.clear()
            mFragmentList.clear()
            val tag = "android:switcher:${viewPager.id}:"
            val forumArticleListFragment = childFragmentManager.findFragmentByTag("${tag}0")
                ?: ForumArticleListFragment().with(
                    bundleOf(
                        EntranceConsts.KEY_ENTRANCE to "社区",
                        EntranceConsts.KEY_PATH to "推荐"
                    )
                )
            mFragmentList.add(forumArticleListFragment)

            val forumFragment = childFragmentManager.findFragmentByTag("${tag}1")
                ?: ForumFragment().with(bundleOf(EntranceConsts.KEY_ENTRANCE to "社区"))
            mFragmentList.add(forumFragment)

            val activityFragment = childFragmentManager.findFragmentByTag("${tag}2")
                ?: ForumActivityFragment().with(bundleOf(EntranceConsts.KEY_ENTRANCE to "活动"))
            mFragmentList.add(activityFragment)

            viewPager.run {
                offscreenPageLimit = mFragmentList.size
                tryCatchInRelease {
                    val field = ViewPager::class.java.getDeclaredField("mRestoredCurItem")
                    field.isAccessible = true
                    field.set(this, defaultSelectedPosition)
                }
                adapter = FragmentAdapter(childFragmentManager, mFragmentList, mTitleList)
                doOnScroll(
                    onPageSelected = { position ->
                        communityEditBtn.goneIf(position != 0)
                        when (position) {
                            TAB_RECOMMEND_INDEX -> {
                                root.setBackgroundColor(R.color.background.toColor(requireContext()))
                                topBg.translationY = 0F
                                changeNavigationBg()
                                NewLogUtils.logCommunityHomeEvent("click_for_you_tab")
                                SensorsBridge.trackEvent("CommunityTopTabSelected", "tab_type", "推荐")
                            }
                            TAB_FORUM_INDEX -> {
                                root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
                                (mFragmentList[1] as ForumFragment).translationY.run {
                                    topBg.translationY = -this.toFloat()
                                    changeNavigationBg(this)
                                }
                                NewLogUtils.logCommunityHomeEvent("click_forum_tab")
                                SensorsBridge.trackEvent("CommunityTopTabSelected", "tab_type", "论坛")
                            }
                            TAB_ACTIVITY_INDEX -> {
                                root.setBackgroundColor(R.color.background.toColor(requireContext()))
                                (mFragmentList[2] as ForumActivityFragment).translationY.run {
                                    topBg.translationY = -this.toFloat()
                                    changeNavigationBg(this)
                                }
                                NewLogUtils.logCommunityHomeEvent("click_activity_tab")
                                SensorsBridge.trackEvent("CommunityTopTabSelected", "tab_type", "活动")
                            }
                        }
                    },
                    onPageScrolled = { position, positionOffset, _ ->
                        if (position + 1 != mTabList.size) {
                            (mTabList[position] as TextView).run {
                                layoutParams.width =
                                    (DEFAULT_TAB_TEXT_WIDTH + ((1 - positionOffset) * 4F.dip2px())).roundToInt()
                                textSize = (DEFAULT_TAB_TEXT_SIZE + ((1 - positionOffset) * 4)).roundTo(1)
                                setTextColor(
                                    ColorUtils.blendARGB(
                                        TAB_DEFAULT_COLOR.toColor(requireContext()),
                                        TAB_SELECTED_COLOR.toColor(requireContext()),
                                        1 - positionOffset
                                    )
                                )
                            }
                            if (mTabList[position + 1] is TextView) {
                                (mTabList[position + 1] as TextView).run {
                                    layoutParams.width =
                                        (DEFAULT_TAB_TEXT_WIDTH + ((positionOffset) * 4F.dip2px())).roundToInt()
                                    textSize = (DEFAULT_TAB_TEXT_SIZE + ((positionOffset) * 4)).roundTo(1)
                                    setTextColor(
                                        ColorUtils.blendARGB(
                                            TAB_DEFAULT_COLOR.toColor(requireContext()),
                                            TAB_SELECTED_COLOR.toColor(requireContext()),
                                            positionOffset
                                        )
                                    )
                                }
                            } else {
                                (mTabList[position + 1] as TabItemCommunityBinding).run {
                                    tabTitle.layoutParams.width =
                                        (DEFAULT_TAB_TEXT_WIDTH + ((positionOffset) * 4F.dip2px())).roundToInt()
                                    tabTitle.textSize = (DEFAULT_TAB_TEXT_SIZE + ((positionOffset) * 4)).roundTo(1)
                                    tabImg.scaleX =
                                        (DEFAULT_TAB_IMG_WIDTH + ((positionOffset) * 8)).roundTo(1) / DEFAULT_TAB_IMG_WIDTH
                                    tabImg.scaleY =
                                        (DEFAULT_TAB_IMG_HEIGHT + ((positionOffset) * 4)).roundTo(1) / DEFAULT_TAB_IMG_HEIGHT
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        tabImg.imageTintList =
                                            ColorStateList.valueOf(
                                                ColorUtils.blendARGB(
                                                    TAB_DEFAULT_COLOR.toColor(requireContext()),
                                                    TAB_SELECTED_COLOR.toColor(requireContext()),
                                                    positionOffset
                                                )
                                            )
                                    }
                                }
                            }

                            // 多 tab 切换的时候可能会出现某些 tab 的文字没有回归到原始大小的问题的问题 (positionOffset 不保证连续)
                            for ((index, tabTv) in mTabList.withIndex()) {
                                val isNeedReset =
                                    abs(index - position) >= 2 && tabTv is TextView && tabTv.textSize != DEFAULT_TAB_TEXT_SIZE
                                if (isNeedReset) {
                                    (tabTv as TextView).textSize = DEFAULT_TAB_TEXT_SIZE
                                    tabTv.setTextColor(TAB_DEFAULT_COLOR.toColor(requireContext()))
                                }
                            }
                        }

                        updateTabStyle(position, positionOffset)
                    }
                )
            }

            tabLayout.setupWithViewPager(viewPager)
            indicatorView.run {
                setupWithTabLayout(tabLayout)
                setupWithViewPager(viewPager)
                setIndicatorWidth(18)
            }
            for (i in 0 until tabLayout.tabCount) {
                val tab = tabLayout.getTabAt(i) ?: continue
                val tabTitle = if (tab.text != null) tab.text.toString() else ""
                val tabViewBinding = generateTabView(tabTitle, i)
                tab.customView = tabViewBinding.root
                tab.view.setPadding(0, 0, 0, 0)
            }
        }
    }

    private fun updateTabStyle(selectedPosition: Int, positionOffset: Float) {
        for ((index, titleView) in mTabList.withIndex()) {
            if (titleView is TextView) {
                updateTabText(titleView, index, selectedPosition, positionOffset)
            } else {
                updateTabImage(titleView as TabItemCommunityBinding, index, selectedPosition, positionOffset)
            }
        }
    }

    private fun updateTabText(
        titleView: TextView,
        index: Int,
        selectedPosition: Int,
        positionOffset: Float
    ) {
        if (index == selectedPosition) {
            if (positionOffset == 0F) {
                titleView.setTextColor(TAB_SELECTED_COLOR.toColor(requireContext()))
                titleView.setTypeface(null, Typeface.NORMAL)
                titleView.setTypeface(titleView.typeface, Typeface.BOLD)
            } else if (positionOffset > 0F) {
                titleView.setTypeface(null, Typeface.NORMAL)
            }
        } else {
            titleView.setTypeface(null, Typeface.NORMAL)
            if (positionOffset == 0F) {
                titleView.setTextColor(TAB_DEFAULT_COLOR.toColor(requireContext()))
            }
        }
    }

    private fun updateTabImage(
        binding: TabItemCommunityBinding,
        index: Int,
        selectedPosition: Int,
        positionOffset: Float
    ) {
        if (index == selectedPosition) {
            updateTabImageIfSelected(binding, positionOffset)
        } else {
            updateTabImageIfUnSelected(binding, positionOffset)
        }
    }

    private fun updateTabImageIfSelected(binding: TabItemCommunityBinding, positionOffset: Float) {
        binding.run {
            if (positionOffset == 0F) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    tabImg.imageTintList = ColorStateList.valueOf(TAB_SELECTED_COLOR.toColor(requireContext()))
                } else {
                    tabImg.setImageResource(R.drawable.ic_tab_activity_active)
                }
                tabTitle.layoutParams.width = 64F.dip2px()
                tabImg.scaleX = SCALE_TAB_IMG_WIDTH / DEFAULT_TAB_IMG_WIDTH
                tabImg.scaleY = SCALE_TAB_IMG_HEIGHT / DEFAULT_TAB_IMG_HEIGHT
            }
        }
    }

    private fun updateTabImageIfUnSelected(binding: TabItemCommunityBinding, positionOffset: Float) {
        binding.run {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                tabImg.setImageResource(R.drawable.ic_tab_activity_default)
            }
            if (positionOffset == 0F) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    tabImg.imageTintList = ColorStateList.valueOf(TAB_DEFAULT_COLOR.toColor(requireContext()))
                }
                tabTitle.layoutParams.width = DEFAULT_TAB_TEXT_WIDTH
                tabImg.scaleX = 1F
                tabImg.scaleY = 1F
            }
        }
    }

    private fun generateTabView(title: String, index: Int): TabItemCommunityBinding {
        val binding = TabItemCommunityBinding.inflate(LayoutInflater.from(requireContext()))
        binding.run {
            if (index == TAB_ACTIVITY_INDEX) {
                mTabList.add(binding)
                tabTitle.visibility = View.INVISIBLE
                tabImg.visibility = View.VISIBLE
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    tabImg.setImageResource(R.drawable.ic_tab_activity_svg)
                } else {
                    tabImg.setImageResource(R.drawable.ic_tab_activity_default)
                }
                tabTitle.run {
                    text = title
//                    textSize = DEFAULT_TAB_TEXT_SIZE
//                    setTextColor(TAB_DEFAULT_COLOR.toColor(requireContext()))
                }
            } else {
                mTabList.add(tabTitle)
                tabTitle.visibility = View.VISIBLE
                tabImg.visibility = View.GONE
                tabTitle.run {
                    text = title
                    textSize = DEFAULT_TAB_TEXT_SIZE
                    setTextColor(TAB_DEFAULT_COLOR.toColor(requireContext()))
                }
            }
        }
//        binding.invisibleTabTitle.run {
//            text = title
//            textSize = DEFAULT_TAB_TEXT_SIZE
//        }
        return binding
    }

    private fun showCommunityEditWindow() {
        val contentView = LayoutInflater.from(context).inflate(R.layout.community_edit_window, null)
        val params = ViewGroup.LayoutParams(resources.displayMetrics.widthPixels, ViewGroup.LayoutParams.WRAP_CONTENT)
        val dialog = TrackableDialog(
            requireContext(),
            R.style.DialogWindowTransparent,
            "社区",
            "社区-发布弹窗",
            null,
            "发布-空白",
            "发布-返回",
            false
        )
        val window = dialog.window
        window?.setGravity(Gravity.BOTTOM)
        window?.setWindowAnimations(R.style.community_publication_animation)
        dialog.setContentView(contentView, params)
        dialog.show()
        NewLogUtils.logBbsPostPanelClick("推荐信息流", "", "")
        contentView.findViewById<View>(R.id.community_edit_article_container).setOnClickListener {
            context?.ifLogin("论坛首页-发布-发帖子", action = {
                checkStoragePermissionBeforeAction {
                    showRegulationTestDialogIfNeeded {
                        MtaHelper.onEvent("论坛首页", "发布", "发帖子")
                        NewLogUtils.logArticleEditEnter("推荐信息流", "", "")
                        startActivityForResult(
                            ArticleEditActivity.getIntent(requireContext(), null, entrance = "社区推荐Tab"),
                            ARTICLE_REQUEST_CODE
                        )
                        dialog.dismiss()
                    }
                }
            })
        }
        contentView.findViewById<View>(R.id.community_edit_question_container).setOnClickListener {
            context?.ifLogin("论坛首页-发布-提问", action = {
                checkStoragePermissionBeforeAction {
                    showRegulationTestDialogIfNeeded {
                        MtaHelper.onEvent("论坛首页", "发布", "提问")
                        NewLogUtils.logQuestionEditEnter("推荐信息流", "", "")
                        startActivityForResult(
                            QuestionEditActivity.getIntent(requireContext(), entrance = "社区推荐Tab"),
                            QUESTION_REQUEST_CODE
                        )
                        dialog.dismiss()
                    }
                }
            })
        }
        contentView.findViewById<View>(R.id.community_edit_video_container).setOnClickListener {
            context?.ifLogin("论坛首页-发布-视频", action = {
                checkStoragePermissionBeforeAction {
                    showRegulationTestDialogIfNeeded {
                        MtaHelper.onEvent("论坛首页", "发布", "发视频")
                        NewLogUtils.logPublishVideoEnter("推荐信息流", "", "")
                        startActivityForResult(
                            VideoPublishActivity.getIntent(
                                context = requireContext(),
                                type = "",
                                entrance = mEntrance,
                                path = "论坛首页"
                            ),
                            VIDEO_REQUEST_CODE
                        )
                        dialog.dismiss()
                    }
                }
            })
        }
        contentView.findViewById<View>(R.id.community_edit_close).setOnClickListener {
            NewLogUtils.logBbsPostPanelCloseClick()
            dialog.dismiss()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK) {
            when (requestCode) {
                ARTICLE_REQUEST_CODE -> {
                    val articleId = data?.getStringExtra("article_id") ?: return
//                    val communityId = data?.getStringExtra("community_id") ?: return
                    mViewModel?.getArticleData(articleId)
                }

                QUESTION_REQUEST_CODE -> {
                    val questionId = data?.getStringExtra("question_id") ?: return
                    mViewModel?.getQuestionDetail(questionId)
                }

                VIDEO_REQUEST_CODE -> {
                    val forumVideoEntity =
                        data?.getParcelableExtra<ForumVideoEntity>(ForumVideoEntity::class.java.simpleName)
                            ?: return
                    mViewModel?.getVideoDetail(forumVideoEntity.id)
                }
            }
        }
    }

    private fun insertDataToRecommendTab(entity: ArticleEntity) {
        (mFragmentList[0] as? ForumArticleListFragment)?.insertDataToFirstIndex(entity)
    }

    override fun onBackPressed(): Boolean {
        mBinding?.viewPager?.run {
            if (currentItem == 0) {
                return (mFragmentList[0] as ForumArticleListFragment).onBackPressed()
            }
        }
        return super.onBackPressed()
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onEventMainThread(status: EBTypeChange) {
        if (mBinding?.viewPager?.currentItem != 0) return

        if (status.type == EB_SHOW_QUESTION_BUTTON) {
            setPutQuestionButtonStatus(View.VISIBLE)
        } else if (status.type == EB_HIDE_QUESTION_BUTTON) {
            setPutQuestionButtonStatus(View.GONE)
        }
    }

    private fun setPutQuestionButtonStatus(visibility: Int) {
        mBinding?.run {
            if (communityEditBtn.visibility == visibility) return

            if (visibility == View.GONE) {
                val animation = AnimationUtils.loadAnimation(context, R.anim.button_anim_exit)
                communityEditBtn.startAnimation(animation)
            } else {
                val animation = AnimationUtils.loadAnimation(context, R.anim.button_anim_enter)
                communityEditBtn.startAnimation(animation)
            }
            communityEditBtn.visibility = visibility
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onEventMainThread(busNine: EBUISwitch) {
        if (busNine.position == MainWrapperFragment.INDEX_BBS) {
            if (mFragmentList.isEmpty()) return
            (mFragmentList[0] as ForumArticleListFragment).scrollToTop()
            setPutQuestionButtonStatus(View.VISIBLE)
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onEventMainThread(skip: EBSkip) {
        if (skip.type == EB_TAB) {
            val tabPosition = skip.currentItem
            mBinding?.viewPager?.currentItem = tabPosition
        }
    }

    fun translateTopBg(y: Int) {
        mBinding?.run {
            if (viewPager.currentItem != TAB_RECOMMEND_INDEX) topBg.translationY = -y.toFloat()
            changeNavigationBg(y)
        }
    }

    private fun changeNavigationBg(y: Int = 0) {
        mBinding?.run {
            if (!mIsDarkModeOn && viewPager.currentItem != TAB_RECOMMEND_INDEX && y != 0) {
                if (navigationBg.drawable == null) {
                    navigationBg.setBackgroundColor(
                        if (viewPager.currentItem == TAB_FORUM_INDEX) {
                            R.color.background_white.toColor(requireContext())
                        } else {
                            R.color.background.toColor(requireContext())
                        }
                    )
                    navigationBg.setImageBitmap(mNavigationBitmap)
                }
            } else if (!mIsDarkModeOn && navigationBg.drawable != null) {
                navigationBg.setBackgroundColor(R.color.transparent.toColor(requireContext()))
                navigationBg.setImageDrawable(null)
            } else if (viewPager.currentItem == TAB_RECOMMEND_INDEX) {
                navigationBg.setBackgroundColor(
                    if (mIsDarkModeOn && y > 0) R.color.background_white.toColor(requireContext()) else if (mIsDarkModeOn && y == 0) R.color.background.toColor(
                        requireContext()
                    ) else R.color.transparent.toColor(requireContext())
                )
                navigationBg.setImageDrawable(null)
            } else if (mIsDarkModeOn) {
                navigationBg.setBackgroundColor(R.color.background_white.toColor(requireContext()))
                navigationBg.setImageDrawable(null)
            }
        }
    }

    override fun onDarkModeChanged() {
        super.onDarkModeChanged()
        if (isSupportVisible) DisplayUtils.setLightStatusBar(requireActivity(), !mIsDarkModeOn)
        mBinding?.tabLayout?.run {
            for (i in 0 until tabCount) {
                val tab: TabLayout.Tab? = getTabAt(i)
                if (tab != null) {
                    updateTabStyle(mBinding?.viewPager?.currentItem ?: 0, 0f)
                }
            }
        }
        mBinding?.run {
            root.setBackgroundColor(
                if (viewPager.currentItem == TAB_FORUM_INDEX) R.color.background_white.toColor(requireContext()) else R.color.background.toColor(
                    requireContext()
                )
            )
            topBg.run {
                visibleIf(!mIsDarkModeOn)
                post {
                    val bitmap = getBitmapFromView()
                    bitmap?.let {
                        mNavigationBitmap = Bitmap.createBitmap(
                            it,
                            0,
                            0,
                            it.width,
                            DisplayUtils.getStatusBarHeight(resources) + 52f.dip2px()
                        )
                    }
                }
            }
            searchTv.setHintTextColor(R.color.text_body.toColor(requireContext()))
            searchTv.setTextColor(R.color.text_body.toColor(requireContext()))
        }
    }

    fun getTopBgView() = mBinding?.topBg

    companion object {
        var TAB_SELECTED_COLOR: Int = R.color.text_title
        var TAB_DEFAULT_COLOR: Int = R.color.community_forum_more
        var DEFAULT_TAB_TEXT_SIZE = 18F
        var DEFAULT_TAB_TEXT_WIDTH = 60F.dip2px()
        var DEFAULT_TAB_IMG_WIDTH = 34F
        var DEFAULT_TAB_IMG_HEIGHT = 18F
        var SCALE_TAB_IMG_WIDTH = 42F
        var SCALE_TAB_IMG_HEIGHT = 22F
        const val EB_TAB = "forum_tab"
        const val TAB_RECOMMEND_INDEX = 0
        const val TAB_FORUM_INDEX = 1
        const val TAB_ACTIVITY_INDEX = 2
        const val ARTICLE_REQUEST_CODE = 200
        const val QUESTION_REQUEST_CODE = 201
        const val VIDEO_REQUEST_CODE = 202
        const val LAST_SELECTED_POSITION = "last_selected_position"
        const val EB_SHOW_QUESTION_BUTTON = "EB_SHOW_QUESTION_BUTTON"
        const val EB_HIDE_QUESTION_BUTTON = "EB_HIDE_QUESTION_BUTTON"
    }
}