package com.gh.common.util

import android.annotation.SuppressLint
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import com.gh.ad.AdPluginDownloadHelper
import com.gh.common.constant.Config
import com.gh.common.exposure.ExposureManager.log
import com.gh.common.exposure.ExposureTraceUtils.appendTrace
import com.gh.common.util.EntranceUtils.jumpActivity
import com.gh.common.util.EntranceUtils.jumpActivityCompat
import com.gh.gamecenter.*
import com.gh.gamecenter.ShellActivity.Type
import com.gh.gamecenter.amway.AmwayActivity
import com.gh.gamecenter.category2.CategoryV2Activity
import com.gh.gamecenter.common.base.activity.BaseActivity
import com.gh.gamecenter.common.base.activity.BaseActivity_TabLayout
import com.gh.gamecenter.common.base.activity.ToolBarActivity
import com.gh.gamecenter.common.base.fragment.BaseFragment_TabLayout
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.constant.EntranceConsts.*
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.entity.*
import com.gh.gamecenter.common.retrofit.Response
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.core.provider.IQGameProvider
import com.gh.gamecenter.core.utils.ToastUtils
import com.gh.gamecenter.discovery.DiscoveryActivity
import com.gh.gamecenter.download.DownloadFragment.Companion.INDEX_UPDATE
import com.gh.gamecenter.entity.*
import com.gh.gamecenter.feature.entity.GameDetailServer
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.feature.entity.MeEntity
import com.gh.gamecenter.feature.exposure.ExposureEvent
import com.gh.gamecenter.feature.exposure.ExposureEvent.Companion.createEvent
import com.gh.gamecenter.feature.exposure.ExposureType
import com.gh.gamecenter.feature.minigame.MiniGameItemHelper
import com.gh.gamecenter.feature.provider.IConcernInfoProvider
import com.gh.gamecenter.forum.detail.ForumDetailActivity
import com.gh.gamecenter.forum.home.CommunityActivity
import com.gh.gamecenter.forum.search.ForumOrUserSearchActivity
import com.gh.gamecenter.game.columncollection.detail.ColumnCollectionDetailActivity
import com.gh.gamecenter.game.columncollection.detail.ColumnCollectionDetailFragment
import com.gh.gamecenter.game.commoncollection.detail.CustomCommonCollectionDetailActivity
import com.gh.gamecenter.game.upload.GameSubmissionActivity
import com.gh.gamecenter.gamecollection.detail.GameCollectionDetailActivity
import com.gh.gamecenter.gamecollection.hotlist.GameCollectionHotListActivity
import com.gh.gamecenter.gamecollection.hotlist.GameCollectionListDetailActivity
import com.gh.gamecenter.gamecollection.square.GameCollectionSquareActivity
import com.gh.gamecenter.gamedetail.entity.GameDetailTabEntity
import com.gh.gamecenter.gamedetail.fuli.kaifu.ServersCalendarActivity
import com.gh.gamecenter.gamedetail.fuli.kaifu.ServersSubscribedGameListActivity
import com.gh.gamecenter.gamedetail.history.HistoryApkListActivity
import com.gh.gamecenter.gamedetail.rating.RatingReplyActivity
import com.gh.gamecenter.help.HelpAndFeedbackBridge
import com.gh.gamecenter.libao.LibaoDetailActivity
import com.gh.gamecenter.login.user.UserManager
import com.gh.gamecenter.minigame.MiniGameRecentlyPlayUseCase
import com.gh.gamecenter.minigame.MiniGameSearchActivity
import com.gh.gamecenter.minigame.qq.QGameHomeWrapperActivity
import com.gh.gamecenter.newsdetail.NewsDetailActivity
import com.gh.gamecenter.personalhome.background.PersonalityBackgroundActivity
import com.gh.gamecenter.personalhome.border.AvatarBorderActivity
import com.gh.gamecenter.personalhome.home.UserHistoryViewModel
import com.gh.gamecenter.qa.answer.detail.SimpleAnswerDetailActivity
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
import com.gh.gamecenter.qa.questions.newdetail.NewQuestionDetailActivity
import com.gh.gamecenter.qa.subject.CommunitySubjectActivity
import com.gh.gamecenter.qa.video.detail.ForumVideoDetailActivity
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.gamecenter.servers.GameServerTestActivity
import com.gh.gamecenter.servers.GameServersActivity
import com.gh.gamecenter.servers.gametest2.GameServerTestV2Activity
import com.gh.gamecenter.setting.SettingBridge
import com.gh.gamecenter.subject.SubjectActivity
import com.gh.gamecenter.tag.TagsActivity
import com.gh.gamecenter.toolbox.ToolBoxActivity
import com.gh.gamecenter.video.data.VideoDataActivity
import com.gh.gamecenter.video.detail.VideoDetailActivity
import com.gh.gamecenter.video.detail.VideoDetailContainerViewModel
import com.gh.gamecenter.video.game.GameVideoActivity
import com.gh.gamecenter.video.videomanager.VideoManagerActivity
import com.gh.gamecenter.wrapper.MainWrapperRepository
import com.gh.gamecenter.wrapper.ToolbarWrapperActivity
import com.gh.vspace.VDownloadManagerActivity
import com.halo.assistant.HaloApp
import com.halo.assistant.fragment.WebFragment
import com.lightgame.utils.Utils
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import com.therouter.TheRouter
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import retrofit2.HttpException
import java.net.URLEncoder
import java.util.*
import kotlin.math.roundToInt

/**
 * 跳转用的方法
 */
object DirectUtils {

    @JvmStatic
    fun directToLinkPage(
        context: Context,
        linkEntity: LinkEntity,
        entrance: String,
        path: String,
        sourceEntrance: String = ""
    ) {
        directToLinkPage(context, linkEntity, entrance, path, null, sourceEntrance)
    }

    @JvmStatic
    fun directToLinkPage(
        context: Context,
        linkEntity: LinkEntity,
        entrance: String,
        path: String,
        exposureEvent: ExposureEvent? = null,
        sourceEntrance: String = ""
    ) {
        directToLinkPage(context, linkEntity, entrance, path, exposureEvent, null, sourceEntrance)
    }

    // 用于判断是否已经对接相关类型
    var directLinkTypes = arrayOf(
        "article", "news",
        "game",
        "column",
        "question",
        "answer",
        "community",
        "community_article",
        "community_column",
        "community_special_column",
        "web", "inurl",
        "qq", "QQ",
        "qqqun",
        "tag",
        "all_community_article",
        "block",
        "column_collection",
        "server",
        "top_game_comment",
        "wechat_bind",
        "video",
        "category_v2",
        "common_collection",
        "game_list",
        "game_list_detail",
        "bbs_video",
        "explore_column",
        "game_explore",
        "column_test_v2",
        "game_list_collection",
        "multi_tab_nav",
        "custom_page",
        "bottom_tab",
        "qq_mini_game_column_detail",
        "game_hot_list",
        "libao_center",
        "article_center",
        "video_stream",
        "libao",
        "community_home",
        "bbs_section",
        "qa",
        "feedback",
        "toolkit",
        "float_window_game",
        "my_halo",
        "my_game",
        "server_manager",
        "receiving_information",
        "game_archive",
        "game_dynamics",
        "game_upload",
        "certification",
        "wechat_reminder",
        "apk_clean",
        "personal_center",
        "video_upload",
        "account_security",
        "simulator",
        "teen_mode",
        "message_center",
        "archive",
        "my_assets",
    )

    fun directToLinkPage(
        context: Context,
        linkEntity: LinkEntity,
        entrance: String,
        path: String,
        exposureEvent: ExposureEvent? = null,
        unknownCallback: (() -> Unit)?,
        sourceEntrance: String = ""
    ) {
        when (linkEntity.type) {
            "article", "news", "文章" -> {
                NewsUtils.statNewsViews(linkEntity.link) // 统计阅读量
                directToArticle(
                    context, linkEntity.link
                        ?: "", BaseActivity.mergeEntranceAndPath(entrance, path)
                )
            }

            "game", "游戏" -> {
                if (exposureEvent != null) {
                    directToGameDetail(
                        context, linkEntity.link
                            ?: "", linkEntity.text
                            ?: "", BaseActivity.mergeEntranceAndPath(entrance, path), traceEvent = exposureEvent
                    )
                } else {
                    directToGameDetail(
                        context,
                        linkEntity.link ?: "",
                        entrance = BaseActivity.mergeEntranceAndPath(entrance, path)
                    )
                }
            }

            "game_server_calendar" -> directToGameServerCalendar(context, linkEntity.link)

            "column", "游戏专题" -> directToSubject(
                context, linkEntity.link
                    ?: "", linkEntity.text, BaseActivity.mergeEntranceAndPath(entrance, path), exposureEvent
            )

            "question", "社区问题" -> directToQuestionDetail(
                context, linkEntity.link
                    ?: "", entrance, path, sourceEntrance
            )

            "answer", "社区回答" -> directToAnswerDetail(context, linkEntity.link ?: "", entrance, path)

            "community", "问答社区" -> {
                if (linkEntity.link.isNullOrEmpty()) return
                directToCommunity(context, CommunityEntity(linkEntity.link!!, linkEntity.text!!))
            }

            "community_article", "社区文章" -> directToCommunityArticle(
                context,
                linkEntity.community!!,
                linkEntity.link!!,
                entrance,
                path,
                sourceEntrance,
            )

            "community_column", "社区专题" -> directToCommunityColumn(
                context,
                linkEntity.community,
                linkEntity.link!!,
                entrance,
                path
            )

            HOST_WEB, HOST_WEB_INURL, HOST_WEB_AL, HOST_QA_CONTENT -> {
                when {
                    linkEntity.link!!.contains("v.douyin") && PackageHelper.localPackageNameSet.contains("com.ss.android.ugc.aweme") -> {
                        directDouyin(context, "1402577827140941")
                    }

                    else -> directToWebView(
                        context,
                        url = linkEntity.link!!,
                        entrance = BaseActivity.mergeEntranceAndPath(entrance, path)
                    )
                }
            }

            "qq", "QQ" -> directToQqConversation(context, linkEntity.link)

            "outurl" -> directToExternalBrowser(context, linkEntity.link!!)

            "qqqun", "QQ群" -> directToQqGroup(context, linkEntity.link!!)

            "tag" -> context.startActivity(
                TagsActivity.getIntent(
                    context,
                    linkEntity.text!!,
                    linkEntity.title,
                    entrance,
                    path,
                    exposureEvent?.source
                )
            )

            "category_v2" -> directCategoryV2(
                context,
                linkEntity.link!!,
                linkEntity.text!!,
                entrance,
                path,
                exposureEvent
            )

            "block", "版块" -> {
                if (linkEntity.link.isNullOrEmpty()) return
                directToBlock(
                    context,
                    SubjectRecommendEntity(
                        link = linkEntity.link,
                        text = linkEntity.text,
                        name = linkEntity.name,
                        display = linkEntity.display ?: Display()
                    ),
                    entrance,
                    exposureEvent
                )
            }

            "column_collection", "专题合集" -> directToColumnCollection(
                context,
                linkEntity.link!!,
                -1,
                entrance,
                "",
                linkEntity.blockId,
                linkEntity.blockName,
                "",
                exposureEvent
            )

            "server", "game_server", "开服表" -> directToGameServers(context, entrance, path, exposureEvent)

            "top_game_comment" -> directToAmway(context, null, entrance, path)

            "wechat_bind" -> context.startActivity(WebActivity.getBindWechatIntent(context))

            "video", "bbs_video", "视频" -> directToVideoDetail(
                context,
                videoId = linkEntity.link!!,
                fromLocation = VideoDetailContainerViewModel.Location.VIDEO_CHOICENESS.value,
                entrance = entrance,
                path = path,
                sourceEntrance = sourceEntrance
            )

            "video_stream" -> directToLegacyVideoDetail(
                context,
                "",
                VideoDetailContainerViewModel.Location.VIDEO_ACTIVITY.value,
                referer = "视频流-$entrance",
                isHomeVideo = true
            )

            "game_video" -> directToGameVideo(context, linkEntity.link ?: "", entrance, path)

            "libao", "礼包" -> directToGiftDetail(context, linkEntity.link ?: "", entrance)

            "feedback" -> directToFeedback(context, linkEntity.name, false, "", false, false, entrance)

            "qa", "Q&A" -> directToQa(context, linkEntity.text ?: "", linkEntity.link ?: "")

            "qa_list" -> directToHelpAndFeedback(context, bundleOf(KEY_ENTRANCE to entrance))

            "qa_collection", "Q&A合集" -> directToQaCollection(
                context, linkEntity.text
                    ?: "", linkEntity.link
                    ?: ""
            )

            "anliwall", "安利墙" -> directToAmway(
                context,
                fixedTopAmwayCommentId = null,
                entrance = entrance,
                path = path
            )

            "game_detail_comment" -> directToGameDetail(context, linkEntity.link ?: "", entrance)

            "game_upload", "游戏投稿" -> directGameUpload(context, entrance, path)

            "bbs_detail" -> directForumDetail(context, linkEntity.link ?: "", entrance)

            "bbs_section" -> directForumDetailSection(
                context,
                linkEntity.community?.id,
                linkEntity.link ?: "",
                entrance
            )

            "mobile_bind" -> {
                CheckLoginUtils.checkLogin(context, entrance) {
                    context.startActivity(SettingBridge.getBindPhoneNormalIntent(context, false))
                }
            }

            "authentication", "certification" -> {
                directToRealName(context)
            }

            "user_background" -> {
                CheckLoginUtils.checkLogin(context, entrance) {
                    context.startActivity(PersonalityBackgroundActivity.getIntent(context))
                }
            }

            "avatar_frame" -> {
                CheckLoginUtils.checkLogin(context, entrance) {
                    context.startActivity(AvatarBorderActivity.getIntent(context))
                }
            }

            "badge" -> {
                CheckLoginUtils.checkLogin(context, entrance) {
                    UserManager.getInstance().userInfoEntity?.run {
                        directToBadgeWall(context, userId, name, icon)
                    }
                }
            }

            "etiquette_exam" -> directToRegulationTestPage(context)

            "setting" -> context.startActivity(SettingBridge.getSettingIntent(context, false, entrance))

            "index_page" -> directToHomeDefaultTab(context)

            "video_upload" -> context.startActivity(VideoManagerActivity.getIntent(context, "", entrance))

            "bbs", "community_home" -> directToHomeCommunityTab(context)

            "user_page" -> directToHomeActivity(context, UserManager.getInstance().userId, "", entrance)

            "video_tab" -> directToHomeVideoTab(context)

            "toolkit" -> context.startActivity(ToolBoxActivity.getIntent(context, entrance))

            "column_test" -> context.startActivity(
                GameServerTestActivity.getIntent(
                    context, linkEntity.link
                        ?: "", linkEntity.text ?: "", entrance, exposureEvent
                )
            )

            "toolkit_detail" -> {
                linkEntity.toolkit?.run {
                    if (url != null && url!!.contains(Config.URL_ARTICLE)) {
                        val newsId = url!!.substring(url!!.lastIndexOf("/") + 1, url!!.length - 5) // 5: ".html"
                        val intent = NewsDetailActivity.getIntentById(context, newsId, entrance)
                        context.startActivity(intent)
                    } else {
                        context.startActivity(WebActivity.getWebByCollectionTools(context, this, false))
                    }
                } ?: ""
            }

            "my_halo", "halo_tab" -> directToHomeMyHaloTab(context)

            "common_collection" -> directToCommonCollectionDetail(
                context,
                linkEntity.link ?: "",
                linkEntity.blockId,
                linkEntity.blockName,
                entrance
            )

            //"h5_game_center" -> directLetoGameCenter(context)

            "game_list" -> directToGameCollectionSquare(context, entrance, traceEvent = exposureEvent)

            "game_list_detail" -> directToGameCollectionDetail(
                context,
                linkEntity.link ?: "",
                entrance,
                traceEvent = exposureEvent
            )

            "explore_column", "game_explore" -> context.startActivity(
                DiscoveryActivity.getIntent(
                    context,
                    entrance,
                    exposureEvent
                )
            )

            "column_test_v2" -> context.startActivity(
                GameServerTestV2Activity.getIntent(
                    context,
                    linkEntity.link ?: "none",
                    entrance,
                    exposureEvent
                )
            )

            ColumnCollectionDetailFragment.TYPE_QQ_MINI_GAME_COLUMN -> directToQGameHome(context)

            // QQ游戏专题详情页
            ViewPagerFragmentHelper.TYPE_QQ_MINI_GAME_COLUMN,
            ViewPagerFragmentHelper.TYPE_WECHAT_GAME_COLUMN,
            ViewPagerFragmentHelper.TYPE_WECHAT_GAME_CPM_COLUMN -> {
                val subjectType = when (linkEntity.type) {
                    ViewPagerFragmentHelper.TYPE_QQ_MINI_GAME_COLUMN -> SubjectData.SubjectType.QQ_GAME
                    ViewPagerFragmentHelper.TYPE_WECHAT_GAME_CPM_COLUMN -> SubjectData.SubjectType.WECHAT_GAME_CPM
                    else -> SubjectData.SubjectType.WECHAT_GAME
                }
                directToSubject(
                    context = context,
                    id = linkEntity.link ?: "",
                    subjectName = linkEntity.text,
                    entrance = BaseActivity.mergeEntranceAndPath(entrance, path),
                    exposureEvent = exposureEvent,
                    subjectType = subjectType
                )
            }

            // 资讯中心
            "article_center" -> {
                context.startActivity(InfoActivity.getIntent(context))
            }
            // 礼包中心
            "libao_center" -> {
                directToGift(context, entrance)
            }

            "game_hot_list" -> directToGameCollectionHotList(context, entrance)

            "game_list_collection" -> directToGameCollectionListDetail(
                context,
                linkEntity.link ?: "",
                linkEntity.text ?: "",
                linkEntity.explain,
                entrance
            )

            "multi_tab_nav" -> context.startActivity(
                ToolbarWrapperActivity.getMultiTabNavIntent(
                    context,
                    linkEntity.link ?: "",
                    linkEntity.text ?: "",
                    entrance
                )
            )

            "custom_page" -> context.startActivity(
                ToolbarWrapperActivity.getCustomPageIntent(
                    context,
                    linkEntity.link ?: "",
                    linkEntity.text ?: "",
                    entrance
                )
            )

            // 选中首页底部 tab
            "bottom_tab" -> {
                if (HaloApp.getInstance().isRunningForeground) {
                    val intent = Intent(context, MainActivity::class.java)
                    intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
                    context.startActivity(intent)
                } else {
                    jumpActivity(context, Bundle())
                }

                if (linkEntity is LaunchRedirect) {
                    MainWrapperRepository.getInstance().sendSelectTabEvent(linkEntity)
                }
            }

            "wechat_game" -> linkEntity.link?.let {
                MiniGameItemHelper.launchMiniGame(it, Constants.WECHAT_MINI_GAME)
            }

            "float_window_game" -> linkEntity.link?.let { link ->
                if (PackageUtils.isInstalled(context, Constants.TOOL_MAP_PACKAGE_NAME)) {
                    val intent = Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse("ghtoolmap://floatWindow")
                    ).also {
                        it.addCategory(Intent.CATEGORY_DEFAULT)
                        it.addCategory(Intent.CATEGORY_BROWSABLE)
                        it.putExtra("gameId", linkEntity.link)
                    }
                    context.startActivity(intent)
                } else {
                    directToGameDetail(context, Config.getFloatWindowSettingEntity()?.gameId ?: "")
                }
            }

            "my_game" -> directToMyGame(0, entrance)

            "server_manager" -> directToServersCalendarManagement(entrance)

            "receiving_information" -> directToDeliveryInfo(entrance)

            "game_archive" -> directToGameArchive(entrance)

            "game_dynamics" -> directToConcernInfo(context, entrance)

            "wechat_reminder" -> CheckLoginUtils.checkLogin(context, entrance) {
                context.startActivity(WebActivity.getBindWechatIntent(context))
            }

            "apk_clean" -> directToCleanApk(context, entrance)

            "personal_center" -> directToUserInfo(entrance)

            "simulator" -> directToSimulatorGame(entrance)

            "account_security" -> directToAccountSecurity(entrance)

            "teen_mode" -> directToTeenMode(entrance)

            "message_center" -> directToMessageCenter(0, entrance)

            "archive" -> directToCloudArchive(context, linkEntity.link ?: "", linkEntity.text ?: "", "", entrance)

            "my_assets" -> navigateToMyAssetsPage(context, entrance)

            "" -> {
                // do nothing
            }

            else -> {
                if (unknownCallback != null) {
                    unknownCallback.invoke()
                } else {
                    DialogHelper.showUpgradeDialog(context)
                }
            }
        }
    }

    /**
     * 跳转至QA，请不要随意修改方法名
     */
    @JvmStatic
    fun directToQa(context: Context, text: String? = "", id: String) {
        if (id.isEmpty()) return

        val bundle = Bundle()
        bundle.putString(KEY_NAVIGATION_TITLE, text)
        bundle.putString(KEY_QA_ID, id)

        TheRouter.build(RouteConsts.activity.qaActivity)
            .fillParams {
                it.putAll(bundle)
            }
            .navigation(context)
    }

    /**
     * 跳转至QA合集，请不要随意修改方法名
     */
    @JvmStatic
    fun directToQaCollection(context: Context, text: String, id: String) {
        if (id.isEmpty()) return

        val bundle = Bundle()
        bundle.putString(KEY_NAVIGATION_TITLE, text)
        bundle.putString(KEY_QA_COLLECTION_ID, id)

        TheRouter.build(RouteConsts.activity.qaActivity)
            .fillParams {
                it.putAll(bundle)
            }
            .navigation(context)
    }

    /**
     * 跳转至专题合集
     */
    @JvmStatic
    fun directToColumnCollection(
        context: Context,
        id: String,
        position: Int = -1,
        entrance: String,
        columnName: String = "",
        blockId: String = "",
        blockName: String = "",
        style: String = "",
        exposureEvent: ExposureEvent? = null,
        showSubjectTab: Boolean = false
    ) {
        if (id.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_TO, ColumnCollectionDetailActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putString(KEY_COLLECTION_ID, id)
        bundle.putString(KEY_COLUMNNAME, columnName)
        bundle.putString(KEY_BLOCK_ID, blockId)
        bundle.putString(KEY_BLOCK_NAME, blockName)
        bundle.putString(KEY_COLUMN_COLLECTION_STYLE, style)
        bundle.putInt(KEY_POSITION, position)
        bundle.putBoolean(KEY_SHOW_SUBJECT_TAB, showSubjectTab)
        if (exposureEvent != null) {
            bundle.putParcelableArrayList(EntranceConsts.KEY_EXPOSURE_SOURCE_LIST, ArrayList(exposureEvent.source))
        }
        jumpActivity(context, bundle)
    }

    /**
     * 跳转至资讯文章列表
     */
    @JvmStatic
    fun directToGameNews(context: Context, gameId: String?, gameName: String?, entrance: String?) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, GameNewsActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putString(KEY_GAMEID, gameId)
        bundle.putString(KEY_GAMENAME, gameName)
        jumpActivity(context, bundle)
    }

    /**
     * 跳转至游戏日历表
     */
    @JvmStatic
    fun directToGameServerCalendar(context: Context, gameId: String?, kaifuTime: Long = 0) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, ServersCalendarActivity::class.java.name)
        bundle.putParcelable(GameEntity::class.java.simpleName, GameEntity().apply {
            id = gameId ?: ""
        })
        bundle.putLong(KEY_KAIFU_TIME, kaifuTime)
        bundle.putParcelable(GameDetailServer::class.java.simpleName, GameDetailServer())
        bundle.putParcelable(MeEntity::class.java.simpleName, MeEntity())
        jumpActivity(context, bundle)
    }

    /**
     * 跳转至游戏历史版本页面
     */
    @JvmStatic
    fun directToHistoryApk(context: Context, gameId: String?) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, HistoryApkListActivity::class.java.name)
        bundle.putString(KEY_GAMEID, gameId)
        jumpActivity(context, bundle)
    }

    /**
     * 跳转到新闻详情
     */
    @JvmStatic
    fun directToArticle(context: Context, id: String, entrance: String? = null) {
        if (id.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_TO, NewsDetailActivity::class.java.name)
        bundle.putString(KEY_NEWSID, id)
        if (entrance?.contains("隐私政策") == true) {
            bundle.putBoolean(KEY_HIDE_USELESS_INFO, true)
        }
        jumpActivity(context, bundle)
    }

    /**
     * 跳转到新闻详情
     */
    @JvmStatic
    fun directToArticle(context: Context, id: String, hideUselessInfo: Boolean, entrance: String? = null) {
        if (id.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_TO, NewsDetailActivity::class.java.name)
        bundle.putString(KEY_NEWSID, id)
        bundle.putBoolean(KEY_HIDE_USELESS_INFO, hideUselessInfo)
        jumpActivity(context, bundle)
    }

    /**
     * 跳转至个人主页
     */
    @JvmStatic
    fun directToHomeActivity(context: Context, userId: String?, entrance: String? = null, path: String? = null) {
        directToHomeActivity(context, userId, entrance, path, 0)
    }

    @JvmStatic
    fun directToRealName(context: Context) {
        context.startActivity(ShellActivity.getIntent(context, ShellActivity.Type.REAL_NAME_INFO, null))
    }

    /**
     * 跳转至个人主页
     * @param position 定位到某个tab 0游戏 1发布
     */
    @JvmStatic
    fun directToHomeActivity(
        context: Context,
        userId: String?,
        position: Int,
        entrance: String? = null,
        path: String? = null
    ) {
        directToHomeActivity(context, userId, "", "", position, entrance, path)
    }

    /**
     * 跳转至个人主页
     * @param position 定位到某个tab 0游戏 1发布
     * @param type 类型 (发布)
     * @param gameType 类型 (游戏)
     */
    @JvmStatic
    fun directToHomeActivity(
        context: Context,
        userId: String? = "",
        type: String? = "",
        gameType: String? = "",
        position: Int? = 0,
        entrance: String? = null,
        path: String? = null
    ) {
        IntegralLogHelper.log("view_homepage", "个人主页")

        val uri = Uri.Builder()
            .path(RouteConsts.activity.userHomeActivity)
            .appendQueryParameter(KEY_USER_ID, userId)
            .appendQueryParameter(KEY_TAB_INDEX, position.toString())
            .appendQueryParameter(KEY_PATH, BaseActivity.mergeEntranceAndPath(entrance, path))
            .appendQueryParameter(KEY_COMMUNITY_TYPE, UserHistoryViewModel.TYPE.fromValue(type).value)
            .appendQueryParameter(KEY_GAME_TYPE, gameType)
            .build()

        TheRouter
            .build(uri.toString())
            .navigation(context)
    }


    /**
     * 回到首页
     */
    fun directToMainActivity(context: Context) {
        val intent = Intent(context, MainActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP }
        context.startActivity(intent)
    }

    /**
     * 跳转到游戏详情
     */
    @JvmStatic
    fun directToGameDetail(
        context: Context,
        id: String,
        name: String = "",
        entrance: String? = null,
        autoDownload: Boolean? = null,
        tab: String? = "",
        traceEvent: ExposureEvent? = null,
        from: String? = null
    ) {
        if (id.isEmpty()) return

        val uri = Uri.Builder()
            .path(RouteConsts.activity.gameDetailActivity)
            .appendQueryParameter(KEY_ENTRANCE, entrance)
            .appendQueryParameter(KEY_GAME_ID, id)
            .appendQueryParameter(KEY_FROM, from)
            .build()

        TheRouter
            .build(uri.toString())
            .fillParams { bundle ->
                if (!TextUtils.isEmpty(tab)) {
                    when (tab) {
                        "comment" -> bundle.putString(KEY_TARGET, GameDetailTabEntity.TYPE_COMMENT)
                        "desc" -> bundle.putString(KEY_TARGET, GameDetailTabEntity.TYPE_DETAIL)
                        "forum" -> bundle.putString(KEY_TARGET, GameDetailTabEntity.TYPE_BBS)
                        "zone" -> bundle.putString(KEY_TARGET, GameDetailTabEntity.TYPE_ZONE)
                    }
                }
                if (traceEvent != null) {
                    val clickEvent = createEvent(
                        GameEntity(id = id, name = name),
                        traceEvent.source,
                        appendTrace(traceEvent),
                        ExposureType.CLICK
                    )
                    log(clickEvent)
                    bundle.putParcelable(KEY_TRACE_EVENT, clickEvent)
                }
                bundle.putBoolean(KEY_AUTO_DOWNLOAD, autoDownload ?: false)
            }
            .navigation(context)
    }

    /**
     *  跳转到游戏评分详情
     */
    @JvmStatic
    fun directToGameRatingDetail(
        context: Context,
        gameId: String? = "",
        commentId: String? = "",
        entrance: String? = null
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_GAMEID, gameId)
        bundle.putString(KEY_COMMENTID, commentId)
        bundle.putString(KEY_TO, RatingReplyActivity::class.java.name)
        jumpActivity(context, bundle)
    }

    /**
     * 跳转视频流-游戏介绍进入
     */
    @JvmStatic
    fun directToGameDetailVideoStreaming(context: Context, id: String, entrance: String? = null) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, GameVideoActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putString(KEY_GAMEID, id)
        bundle.putBoolean(KEY_OPEN_VIDEO_STREAMING, true)
        bundle.putString(KEY_TARGET, GameDetailTabEntity.TYPE_DETAIL)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToGameDetail(
        context: Context,
        id: String,
        defaultTab: String = GameDetailTabEntity.TYPE_DETAIL,
        entrance: String? = null
    ) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.gameDetailActivity)
            .appendQueryParameter(KEY_ENTRANCE, entrance)
            .appendQueryParameter(KEY_GAME_ID, id)
            .build()

        TheRouter
            .build(uri.toString())
            .fillParams { bundle ->
                bundle.putString(KEY_TARGET, defaultTab)
            }
            .navigation(context)
    }

    // 专栏
    @JvmStatic
    fun directToSubject(
        context: Context,
        id: String,
        subjectName: String? = "",
        entrance: String? = null,
        exposureEvent: ExposureEvent? = null,
        subjectType: SubjectData.SubjectType = SubjectData.SubjectType.NORMAL
    ) {
        if (id.isEmpty()) return
        val bundle = Bundle()
        val subjectData =
            SubjectData(subjectId = id, subjectName = subjectName, isOrder = false, subjectType = subjectType)
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_TO, SubjectActivity::class.java.name)
        bundle.putParcelable(EntranceConsts.KEY_SUBJECT_DATA, subjectData)
        if (exposureEvent != null) bundle.putParcelableArrayList(
            KEY_EXPOSURE_SOURCE_LIST,
            ArrayList(exposureEvent.source)
        )
        jumpActivity(context, bundle)
    }

    // 反馈
    @JvmStatic
    fun directToFeedback(context: Context, content: String? = null, entrance: String? = null) {
        directToFeedback(context, content, false, "", false, false, entrance)
    }

    @JvmStatic
    fun directToFeedback(
        context: Context,
        content: String? = null,
        isQaFeedback: Boolean = false,
        qaContentId: String? = "",
        isPlugin: Boolean = false,
        isSmoothGame: Boolean = false,
        entrance: String? = null
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putBoolean(KEY_PLUGIN, isPlugin)
        bundle.putBoolean(KEY_SMOOTH_GAME, isSmoothGame)
        if (isPlugin) {
            bundle.putString(KEY_HIDE_SUGGEST_HINT, "【插件问题】")
        }
        if (isSmoothGame) {
            bundle.putString(KEY_HIDE_SUGGEST_HINT, "【畅玩问题】")
        }
        if (isQaFeedback) {
            bundle.putBoolean(KEY_IS_QA_FEEDBACK, true)
            bundle.putString(KEY_QA_CONTENT_ID, qaContentId)
        } else {
            bundle.putString(KEY_CONTENT, content)
        }
        context.startActivity(HelpAndFeedbackBridge.getSuggestionCategoryIntent(context, bundle))
    }

    /**
     * 跳转至使用帮助与反馈，请不要随意修改方法名
     */
    @JvmStatic
    fun directToHelpAndFeedback(
        context: Context,
        content: String? = null,
        isQaFeedback: Boolean = false,
        qaContentId: String? = "",
        isPlugin: Boolean = false,
        isSmoothGame: Boolean = false,
        gameId: String? = "",
        gameName: String? = "",
        entrance: String? = null
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putBoolean(KEY_PLUGIN, isPlugin)
        bundle.putBoolean(KEY_SMOOTH_GAME, isSmoothGame)
        bundle.putString(KEY_GAME_ID, gameId)
        bundle.putString(KEY_GAME_NAME, gameName)
        if (isPlugin) {
            bundle.putString(KEY_HIDE_SUGGEST_HINT, "【插件问题】")
        }
        if (isSmoothGame) {
            bundle.putString(KEY_HIDE_SUGGEST_HINT, "【畅玩问题】")
        }
        if (isQaFeedback) {
            bundle.putBoolean(KEY_IS_QA_FEEDBACK, true)
            bundle.putString(KEY_QA_CONTENT_ID, qaContentId)
        } else {
            bundle.putString(KEY_CONTENT, content)
        }
        directToHelpAndFeedback(context, bundle)
    }

    @JvmStatic
    fun directToDownloadManager(context: Context, entrance: String? = null) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_TO, DownloadManagerActivity.TAG)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToDownloadManager(
        context: Context,
        entrance: String = "",
        bottomTab: String = "",
        gameColumnId: String = "",
        gameColumnName: String = "",
        customPageId: String = "",
        customPageName: String = "",
        multiTabId: String = "",
        multiTabName: String = ""
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putString(KEY_TO, DownloadManagerActivity.TAG)
        bundle.putString(KEY_BOTTOM_TAB_NAME, bottomTab)
        bundle.putString(KEY_GAME_COLUMN_ID, gameColumnId)
        bundle.putString(KEY_GAME_COLUMN_NAME, gameColumnName)
        bundle.putString(KEY_CUSTOM_PAGE_ID, customPageId)
        bundle.putString(KEY_CUSTOM_PAGE_NAME, customPageName)
        bundle.putString(KEY_MULTI_TAB_NAV_ID, multiTabId)
        bundle.putString(KEY_MULTI_TAB_NAV_NAME, multiTabName)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToDownloadManagerAndStartUpdate(
        context: Context,
        gameId: String? = "",
        packageName: String? = "",
        entrance: String? = null
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_TO, DownloadManagerActivity.TAG)
        bundle.putString(KEY_GAMEID, gameId)
        bundle.putString(KEY_PACKAGENAME, packageName)
        bundle.putInt(BaseFragment_TabLayout.PAGE_INDEX, INDEX_UPDATE)
        jumpActivityCompat(context, bundle)
    }

    @JvmStatic
    fun directToToolbox(context: Context, gameId: String, toolboxUrl: String, entrance: String = ENTRANCE_BROWSER) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putString(KEY_TO, ToolBoxActivity::class.java.name)
        bundle.putString(KEY_GAMEID, gameId)
        bundle.putString(KEY_URL, toolboxUrl)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToAnswerDetail(context: Context, id: String, entrance: String? = null, path: String? = null) {
        if (id.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_TO, SimpleAnswerDetailActivity::class.java.name)
        bundle.putString(KEY_PATH, path)
        bundle.putString(KEY_ANSWER_ID, id)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToQuestionDetail(
        context: Context,
        id: String,
        entrance: String? = null,
        path: String? = null,
        sourceEntrance: String = ""
    ) {
        if (id.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_TO, NewQuestionDetailActivity::class.java.name)
        bundle.putString(KEY_PATH, path)
        bundle.putString(KEY_QUESTIONS_ID, id)
        bundle.putString(KEY_SOURCE_ENTRANCE, sourceEntrance)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToWebView(context: Context, url: String, entrance: String? = null) {
        directToWebView(context, url, entrance, null)
    }

    @JvmStatic
    fun directToWebView(context: Context, url: String, entrance: String? = null, title: String? = null) {
        if (url.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(EntranceConsts.KEY_GAMENAME, title)
        if (url.contains("android_page_type=singleton")) {
            bundle.putString(KEY_TO, SingletonWebActivity::class.java.simpleName)
        } else {
            bundle.putString(KEY_TO, WebActivity::class.java.simpleName)
        }
        if (url.contains("leave_web_page_handle_back_pressed=true")) {
            bundle.putBoolean(WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_BACK_PRESSED, true)
        }
        bundle.putString(EntranceConsts.KEY_URL, url)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToExternalBrowser(context: Context, url: String) {
        try {
            if (url.isEmpty()) return
            val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Uri.decode(url)))
            if (context !is AppCompatActivity) {
                browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
            context.startActivity(browserIntent)
        } catch (e: Exception) {
            e.printStackTrace()
            url.copyTextAndToast(context.getString(R.string.direct_to_external_browser_failed_toast))
        }
    }

    // 跳转 QQ，qqNumber 为空选择默认客服 QQ
    @JvmStatic
    fun directToQqConversation(context: Context, qqNumber: String? = null) {
        var qq = qqNumber

        if (TextUtils.isEmpty(qq)) {
            qq = Config.getSettings()?.support?.qq ?: "3509629529"
        }
        if (ShareUtils.isQQClientAvailable(context)) {
            // 安装了 QQ 直接调用QQ，打开手机QQ进行会话 默认 QQ 号：3509629529
            val chatType: String
            if (qq!!.startsWith("400") || qq.startsWith("800")) {
                chatType = "crm"
            } else {
                chatType = "wpa"
            }
            val str = "mqqwpa://im/chat?chat_type=$chatType&uin=$qq&version=1&src_type=web"
            val intent = Intent(Intent.ACTION_VIEW, Uri.parse(str))
            if (context !is AppCompatActivity) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
            try {
                context.startActivity(intent)
            } catch (e: ActivityNotFoundException) {
                ToastUtils.toast("无法跳转至QQ，请稍后再试")
            }
        } else {
            // 没有安装QQ 复制账号
            qq?.copyTextAndToast("已复制 QQ $qq")
        }
    }

    // 跳转 QQ 群
    @JvmStatic
    fun directToQqGroup(context: Context, groupNumber: String? = null): Boolean {
        if (groupNumber.isNullOrEmpty()) return false
        if (ShareUtils.isQQClientAvailable(context)) {
            val intent = Intent()
            intent.data =
                Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D$groupNumber")
            // 此Flag可根据具体产品需要自定义，如设置，则在加群界面按返回，返回手Q主界面，不设置，按返回会返回到呼起产品界面    //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            return try {
                if (context !is AppCompatActivity) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                }
                context.startActivity(intent)
                true
            } catch (e: Exception) {
                false
            }
        } else {
            Utils.toast(context, "请安装QQ客户端")
            return false
        }

    }

    /**
     * 跳转到 礼包详情
     */
    @JvmStatic
    fun directToGiftDetail(context: Context, giftId: String, entrance: String? = null) {
        if (giftId.isEmpty()) return
        context.startActivity(LibaoDetailActivity.getIntentById(context, giftId, entrance))
    }

    /**
     * 跳转到礼包中心，请不要随意修改方法名
     */
    @JvmStatic
    fun directToGift(context: Context, entrance: String) {
        val intent = LibaoActivity.getIntent(context, entrance)
        context.startActivity(intent)
    }

    /**
     * 切换到社区页面（旧社区页面已经没有了，处理为跳转到论坛详情）
     */
    @JvmStatic
    fun directToCommunity(context: Context, community: CommunityEntity?) {
        directForumDetail(context, community?.id)
    }

    @JvmStatic
    fun directToCommunityArticle(
        context: Context,
        articleId: String?,
        communityId: String?,
        entrance: String?,
        path: String?,
        sourceEntrance: String = ""
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_PATH, path)
        bundle.putString(KEY_TO, ArticleDetailActivity::class.java.name)
        bundle.putString(KEY_COMMUNITY_ARTICLE_ID, articleId)
        bundle.putString(KEY_SOURCE_ENTRANCE, sourceEntrance)
        bundle.putParcelable(KEY_COMMUNITY_DATA, CommunityEntity(id = communityId!!))
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToCommunityArticle(
        context: Context,
        community: CommunityEntity?,
        articleId: String?,
        entrance: String?,
        path: String?,
        sourceEntrance: String = "",
    ) {
        if (articleId.isNullOrEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_PATH, path)
        bundle.putString(KEY_TO, ArticleDetailActivity::class.java.name)
        bundle.putString(KEY_COMMUNITY_ARTICLE_ID, articleId)
        bundle.putString(KEY_SOURCE_ENTRANCE, sourceEntrance)
        bundle.putParcelable(KEY_COMMUNITY_DATA, community)
        jumpActivity(context, bundle)
    }

    /**
     * 跳转到社区专题
     */
    @JvmStatic
    fun directToCommunityColumn(
        context: Context,
        community: CommunityEntity?,
        subjectId: String,
        entrance: String?,
        path: String?
    ) {
        if (subjectId.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_PATH, path)
        bundle.putString(KEY_TO, CommunitySubjectActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, BaseActivity.mergeEntranceAndPath(entrance, path))
        bundle.putString(KEY_COLUMN_ID, subjectId)
        bundle.putParcelable(KEY_COMMUNITY_DATA, community)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToVideoDetail(
        context: Context, videoId: String,
        entrance: String? = null,
        path: String? = "",
        sourceEntrance: String = ""
    ) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            val bundle = Bundle()
            bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
            bundle.putString(KEY_TO, ForumVideoDetailActivity::class.java.name)
            bundle.putString(KEY_VIDEO_ID, videoId);
            bundle.putString(KEY_PATH, path)
            bundle.putString(KEY_SOURCE_ENTRANCE, sourceEntrance)
            jumpActivity(context, bundle)
        } else {
            DialogHelper.showVideoUnsupportedDialog(context)
        }
    }

    /**
     * 跳转到旧视频页面
     * @param fromLocation 可见 [VideoDetailContainerViewModel.Location]
     */
    @JvmStatic
    fun directToLegacyVideoDetail(
        context: Context,
        videoId: String,
        fromLocation: String,
        showComment: Boolean = false,
        gameId: String = "",
        entrance: String? = null,
        path: String? = "",
        referer: String = "",
        type: String = "",
        act: String = "",
        paginationType: String = "",
        fieldId: String = "",
        sectionName: String = "",
        isHomeVideo: Boolean = false,
        sourceEntrance: String = ""
    ) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            val bundle = Bundle()
            bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
            bundle.putString(KEY_TO, VideoDetailActivity::class.java.name)
            bundle.putString(KEY_VIDEO_ID, videoId);
            bundle.putString(KEY_PATH, path)
            bundle.putString(KEY_ID, videoId)
            bundle.putString(KEY_GAMEID, gameId)
            bundle.putString(KEY_LOCATION, fromLocation)
            bundle.putBoolean(KEY_SHOW_COMMENT, showComment)
            bundle.putString(KEY_REFERER, referer)
            bundle.putString(KEY_TYPE, type)
            bundle.putString(KEY_ACTIVITY_NAME, act)
            bundle.putString(KEY_PAGINATION_TYPE, paginationType)
            bundle.putString(KEY_FIELD_ID, fieldId)
            bundle.putString(KEY_SECTION_NAME, sectionName)
            bundle.putBoolean(KEY_IS_HOME_VIDEO, isHomeVideo)
            SensorsBridge.trackAccessVideoStreaming(sourceEntrance)
            jumpActivity(context, bundle)
        } else {
            DialogHelper.showVideoUnsupportedDialog(context)
        }
    }

    @JvmStatic
    fun directToVideoDetail(
        context: Context,
        videoId: String,
        fromLocation: String,
        showComment: Boolean = false,
        gameId: String = "",
        entrance: String? = null,
        path: String? = "",
        referer: String = "",
        sourceEntrance: String = ""
    ) {
        directToVideoDetail(context, videoId, entrance, path, sourceEntrance)
    }

    /**
     * 跳转至安利墙
     * @param fixedTopAmwayCommentId 需要置顶的安利Id
     */
    @JvmStatic
    fun directToAmway(
        context: Context,
        fixedTopAmwayCommentId: String? = null,
        entrance: String? = null,
        path: String? = ""
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_TO, AmwayActivity::class.java.name)
        bundle.putString(KEY_ID, fixedTopAmwayCommentId)
        bundle.putString(KEY_PATH, path)
        jumpActivity(context, bundle)
    }

    /**
     * 跳转至徽章墙
     */
    @JvmStatic
    fun directToBadgeWall(context: Context, userId: String?, name: String?, icon: String?) {
        var url: String = if (EnvHelper.isDevEnv) {
            Constants.BADGE_ADDRESS_DEV
        } else {
            Constants.BADGE_ADDRESS
        }

        url = String.format(
            Locale.CHINA,
            "%s?user_id=%s&name=%s&icon=%s&timestamp=%d",
            url,
            userId,
            name,
            URLEncoder.encode(icon),
            (Date().time / 1000 / 1000.toFloat()).roundToInt()
        )
        directToFullScreenWebPage(context, url, true)
    }

    /**
     * 跳转至徽章详情
     */
    @JvmStatic
    fun directToBadgeDetail(context: Context, userId: String?, badgeId: String?) {
        var url: String = if (EnvHelper.isDevEnv) {
            Constants.BADGE_DETAIL_ADDRESS_DEV
        } else {
            Constants.BADGE_DETAIL_ADDRESS
        }

        url = String.format(
            Locale.CHINA,
            "%s?user_id=%s&badge_id=%s&timestamp=%d",
            url,
            userId,
            badgeId,
            (Date().time / 1000 / 1000.toFloat()).roundToInt()
        )
        directToFullScreenWebPage(context, url, true)
    }

    /**
     * 跳转至上传视频
     */
    @JvmStatic
    fun directToVideoManager(
        context: Context,
        linkEntity: VideoLinkEntity,
        simpleGameEntity: SimpleGameEntity,
        entrance: String? = null,
        path: String? = ""
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_PATH, path)
        bundle.putParcelable(VideoLinkEntity::class.java.simpleName, linkEntity)
        bundle.putParcelable(SimpleGameEntity::class.java.simpleName, simpleGameEntity)
        bundle.putString(KEY_TO, VideoManagerActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, BaseActivity.mergeEntranceAndPath(entrance, path))
        jumpActivity(context, bundle)
    }

    @JvmStatic
    @JvmOverloads
    fun directToFullScreenWebPage(
        context: Context,
        url: String,
        webViewHandleBackPressed: Boolean = false,
        entrance: String? = null
    ) {
        context.startActivity(FullScreenWebActivity.getIntent(context, url, webViewHandleBackPressed, entrance))
    }

    @JvmStatic
    fun directToRegulationTestPage(context: Context) {
        val url = if (EnvHelper.isDevEnv) {
            Constants.REGULATION_TEST_ADDRESS_DEV
        } else {
            Constants.REGULATION_TEST_ADDRESS
        }
        directToFullScreenWebPage(context, url, true)
    }

    /**
     * 跳转视频合集
     */
    @JvmStatic
    fun directToGameVideo(context: Context, gameId: String, entrance: String? = null, path: String? = "") {
        if (gameId.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_PATH, path)
        bundle.putString(KEY_TO, GameVideoActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, BaseActivity.mergeEntranceAndPath(entrance, path))
        bundle.putString(KEY_GAMEID, gameId)
//        context.startActivity(GameVideoActivity.getIntent(context, gameId, entrance, path))
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directDouyin(context: Context, userId: String) {
        if (PackageHelper.localPackageNameSet.contains("com.ss.android.ugc.aweme")) {
            val intent = Intent(Intent.ACTION_VIEW, Uri.parse("snssdk1128://user/profile/$userId"))
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
        }
    }

    /**
     * 跳转新分类2.0
     */
    @JvmStatic
    fun directCategoryV2(
        context: Context,
        categoryId: String,
        categoryTitle: String,
        entrance: String? = null,
        path: String? = "",
        exposureEvent: ExposureEvent? = null,
    ) {
        if (categoryId.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_TO, CategoryV2Activity::class.java.name)
        bundle.putString(KEY_PAGE_ID, categoryId)
        bundle.putString(KEY_PAGE_NAME, categoryTitle)
        bundle.putString(KEY_ENTRANCE, BaseActivity.mergeEntranceAndPath(entrance, path))
        if (exposureEvent != null) bundle.putParcelableArrayList(
            KEY_EXPOSURE_SOURCE_LIST,
            ArrayList(exposureEvent.source)
        )
        jumpActivity(context, bundle)
    }

    /**
     * 跳转到板块
     */
    @JvmStatic
    fun directToBlock(
        context: Context,
        blockData: SubjectRecommendEntity,
        entrance: String,
        exposureEvent: ExposureEvent? = null
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, BlockActivity::class.java.name)
        bundle.putParcelable(KEY_BLOCK_DATA, blockData)
        bundle.putString(KEY_ENTRANCE, entrance)
        exposureEvent?.let { bundle.putParcelableArrayList(KEY_EXPOSURE_SOURCE_LIST, ArrayList(exposureEvent.source)) }
        jumpActivity(context, bundle)
    }

    /**
     * 跳转到开服表
     */
    @JvmStatic
    fun directToGameServers(context: Context, entrance: String, path: String, exposureEvent: ExposureEvent? = null) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, GameServersActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, ToolBarActivity.mergeEntranceAndPath(entrance, path))
        exposureEvent?.let { bundle.putParcelableArrayList(KEY_EXPOSURE_SOURCE_LIST, ArrayList(exposureEvent.source)) }
        jumpActivity(context, bundle)
    }

    /**
     * 跳转到游戏上传
     */
    @JvmStatic
    fun directGameUpload(context: Context, entrance: String? = null, path: String? = "") {
        val bundle = Bundle()
        bundle.putString(KEY_TO, GameSubmissionActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_PATH, path)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directGameZone(context: Context, gameId: String, url: String, entrance: String? = null) {
        RetrofitManager.getInstance()
            .api
            .getGameDigest(gameId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Response<GameEntity>() {
                override fun onResponse(response: GameEntity?) {
                    response?.apply {
                        if (zone.status == "on") {
                            if (zone.style == "link") {
                                directToGameDetail(context, gameId, GameDetailTabEntity.TYPE_ZONE, entrance)
                            } else {
                                directToWebView(context, url, entrance)
                            }
                        } else {
                            directToWebView(context, url, entrance)
                        }
                    }
                }

                override fun onFailure(e: HttpException?) {

                }
            })
    }

    @JvmStatic
    fun directVideoData(context: Context, entrance: String? = null) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, VideoDataActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, entrance)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directForumDetail(context: Context, bbsId: String? = "", entrance: String? = null) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, ForumDetailActivity::class.java.name)
        bundle.putString(KEY_BBS_ID, bbsId)
        bundle.putString(KEY_ENTRANCE, entrance)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directForumDetailSection(
        context: Context,
        bbsId: String? = "",
        sectionId: String? = "",
        entrance: String? = null
    ) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, ForumDetailActivity::class.java.name)
        bundle.putString(KEY_BBS_ID, bbsId)
        bundle.putString(KEY_BBS_SECTION_ID, sectionId)
        bundle.putString(KEY_ENTRANCE, entrance)
        jumpActivity(context, bundle)
    }

    /**
     * 到首页-默认选中的 tab
     */
    @JvmStatic
    fun directToHomeDefaultTab(context: Context) {
        if (HaloApp.getInstance().isRunningForeground) {
            val intent = Intent(context, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
            context.startActivity(intent)

            MainWrapperRepository.getInstance().sendReSelectDefaultTabEvent()
        } else {
            jumpActivity(context, Bundle())
        }
    }

    /**
     * 到首页-社区 tab
     * @param position 社区子 tab 位置
     */
    @JvmStatic
    fun directToHomeCommunityTab(context: Context) {
        val bundle = Bundle()
        bundle.putString(KEY_TO, CommunityActivity::class.java.name)
        jumpActivity(context, bundle)
    }

    /**
     * 到首页-视频 tab
     */
    @JvmStatic
    fun directToHomeVideoTab(context: Context) {
        if (HaloApp.getInstance().isRunningForeground) {
            val intent = Intent(context, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
            context.startActivity(intent)
        } else {
            jumpActivity(context, Bundle())
        }

        MainWrapperRepository.getInstance().sendSelectTabEvent(ViewPagerFragmentHelper.TYPE_VIDEO_STREAM)
    }

    /**
     * 到首页-我的光环 tab
     */
    fun directToHomeMyHaloTab(context: Context) {
        if (HaloApp.getInstance().isRunningForeground) {
            val intent = Intent(context, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
            context.startActivity(intent)
        } else {
            jumpActivity(context, Bundle())
        }

        MainWrapperRepository.getInstance().sendSelectTabEvent(ViewPagerFragmentHelper.TYPE_MY_HALO)
    }

    /**
     * 跳转至使用帮助与反馈，请不要随意修改方法名
     */
    @JvmStatic
    fun directToHelpAndFeedback(context: Context, bundle: Bundle? = null) {
        TheRouter.build(RouteConsts.activity.helpAndFeedbackActivity)
            .fillParams {
                bundle?.run { it.putAll(this) }
            }
            .navigation(context)
    }


    /**
     * 跳转至地址信息
     */
    @JvmStatic
    fun directToAddressInfo(context: Context) {
        var url: String = if (isPublishEnv()) {
            Constants.ADDRESS_INFO_ADDRESS
        } else {
            Constants.ADDRESS_INFO_ADDRESS_DEV
        }

        url = String.format(Locale.CHINA, "%s&timestamp=%d", url, (Date().time / 1000 / 1000.toFloat()).roundToInt())
        directToFullScreenWebPage(context, url, true)
    }

    /**
     * 跳转至领奖信息
     */
    @JvmStatic
    fun directToPrizeInfo(context: Context) {
        var url: String = if (isPublishEnv()) {
            Constants.PRIZE_INFO_ADDRESS
        } else {
            Constants.PRIZE_INFO_ADDRESS_DEV
        }

        url = String.format(Locale.CHINA, "%s&timestamp=%d", url, (Date().time / 1000 / 1000.toFloat()).roundToInt())
        directToFullScreenWebPage(context, url, true)
    }

    /**
     * 跳转至提现信息
     */
    @JvmStatic
    fun directToWithdrawInfo(context: Context) {
        var url: String = if (isPublishEnv()) {
            Constants.WITHDRAW_INFO_ADDRESS
        } else {
            Constants.WITHDRAW_INFO_ADDRESS_DEV
        }

        url = String.format(Locale.CHINA, "%s&timestamp=%d", url, (Date().time / 1000 / 1000.toFloat()).roundToInt())
        directToFullScreenWebPage(context, url, true)
    }

    /**
     * 跳转至活动详情
     */
    @JvmStatic
    fun directToActivityDetail(context: Context, activityId: String, categoryId: String, entrance: String) {
        var url: String = if (isPublishEnv()) {
            Constants.ACTIVITY_DETAIL_ADDRESS
        } else {
            Constants.ACTIVITY_DETAIL_ADDRESS_DEV
        }

        url = String.format(
            Locale.CHINA,
            "%s?from=ghzs&id=%s&category_id=%s&timestamp=%d",
            url,
            activityId,
            categoryId,
            (Date().time / 1000 / 1000.toFloat()).roundToInt()
        )
        directToWebView(context, url, entrance)
    }

    @JvmStatic
    fun directToCommonCollectionDetail(
        context: Context,
        collectionId: String,
        blockId: String = "",
        blockName: String = "",
        entrance: String = "",
        exposureEvent: ExposureEvent? = null
    ) {
        if (collectionId.isEmpty()) return
        val bundle = Bundle()
        bundle.putString(KEY_TO, CustomCommonCollectionDetailActivity::class.java.name)
        bundle.putString(KEY_BLOCK_ID, blockId)
        bundle.putString(KEY_BLOCK_NAME, blockName)
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putString(KEY_COLLECTION_ID, collectionId)
        exposureEvent?.let { bundle.putParcelableArrayList(KEY_EXPOSURE_SOURCE_LIST, ArrayList(exposureEvent.source)) }
        jumpActivity(context, bundle)
    }

    /**
     * 跳转到游戏动态，请不要随意修改方法名
     */
    @JvmStatic
    fun directToConcernInfo(context: Context, entrance: String) {
        context.startActivity(
            TheRouter.get(IConcernInfoProvider::class.java)?.getIntent(context, entrance)
        )
    }

    /**
     * 跳转至游戏单广场
     */
    @JvmStatic
    fun directToGameCollectionSquare(
        context: Context,
        entrance: String = "",
        forumName: String = "",
        gameCollectionTitle: String = "",
        gameCollectionId: String = "",
        collectionName: String = "",
        collectionId: String = "",
        traceEvent: ExposureEvent? = null
    ) {
        val bundle = Bundle()
        val exposureSourceList = traceEvent?.source
        bundle.putString(KEY_TO, GameCollectionSquareActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putString(KEY_FORUM_NAME, forumName)
        bundle.putString(KEY_GAME_COLLECTION_TITLE, gameCollectionTitle)
        bundle.putString(KEY_GAME_COLLECTION_ID, gameCollectionId)
        bundle.putString(KEY_COLLECTION_ID, collectionId)
        bundle.putString(KEY_COLLECTION_NAME, collectionName)
        if (exposureSourceList is ArrayList) {
            bundle.putParcelableArrayList(KEY_EXPOSURE_SOURCE_LIST, exposureSourceList)
        } else if (exposureSourceList != null) {
            bundle.putParcelableArrayList(KEY_EXPOSURE_SOURCE_LIST, ArrayList(exposureSourceList))
        }
        jumpActivity(context, bundle)
    }

    /**
     * 跳转至游戏单热榜
     */
    @JvmStatic
    fun directToGameCollectionHotList(context: Context, entrance: String = "") {
        val bundle = Bundle()
        bundle.putString(KEY_TO, GameCollectionHotListActivity::class.java.name)
        bundle.putString(KEY_ENTRANCE, entrance)
        jumpActivity(context, bundle)
    }

    /**
     * 跳转至游戏单详情
     */
    @JvmStatic
    fun directToGameCollectionDetail(
        context: Context,
        id: String,
        entrance: String? = null,
        path: String? = null,
        traceEvent: ExposureEvent? = null,
    ) {
        if (id.isEmpty()) return
        val bundle = Bundle()
        val exposureSourceList = traceEvent?.source
        bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
        bundle.putString(KEY_PATH, path)
        bundle.putString(KEY_TO, GameCollectionDetailActivity::class.java.name)
        bundle.putString(KEY_GAME_COLLECTION_ID, id)
        if (exposureSourceList is ArrayList) {
            bundle.putParcelableArrayList(KEY_EXPOSURE_SOURCE_LIST, exposureSourceList)
        } else if (exposureSourceList != null) {
            bundle.putParcelableArrayList(KEY_EXPOSURE_SOURCE_LIST, ArrayList(exposureSourceList))
        }
        jumpActivity(context, bundle)
    }

    /**
     * 跳转至反馈详情, 请不要随意修改方法名
     */
    @JvmStatic
    fun directToSuggestion(
        context: Context,
        type: SuggestType = SuggestType.APP,
        hiddenHint: String = "",
        suggestHintType: String? = null,
        content: String? = null,
        game: SimpleGameEntity? = null,
        isQaFeedback: Boolean = false,
        qaContentId: String = "",
        fromRatingKey: Boolean = false,
        diagnosis: String = "",
        forceLogin: Boolean = true,
        requestCode: Int? = null,
        isSmoothGame: Boolean = false
    ) {
        val intent = HelpAndFeedbackBridge.getIntent(
            context,
            type,
            hiddenHint,
            suggestHintType,
            content,
            game,
            isQaFeedback,
            qaContentId,
            fromRatingKey,
            diagnosis,
            forceLogin,
            isSmoothGame
        )
        if (requestCode != null) {
            (context as Activity).startActivityForResult(intent, requestCode)
        } else {
            context.startActivity(intent)
        }
    }

    /**
     * 跳转到论坛搜索页
     * @param bbsId, 为空时搜索全范围的内容，不为空时搜索该 bbsId 对应的内容
     */
    @JvmStatic
    fun directToForumOrUserSearch(
        context: Context,
        bbsId: String,
        entrance: String,
        sourceEntrance: String,
        forumName: String,
        bottomTab: String = "",
        multiTabId: String = "",
        multiTabName: String = "",
        customPageId: String = "",
        customPageName: String = "",
        searchBoxPattern: String = ""
    ) {
        context.startActivity(
            ForumOrUserSearchActivity.getIntent(
                context,
                bbsId,
                entrance,
                sourceEntrance,
                forumName,
                bottomTab,
                multiTabId,
                multiTabName,
                customPageId,
                customPageName,
                searchBoxPattern
            )
        )
    }

    @JvmStatic
    fun directToVGameDownload(context: Context, entrance: String, switchToDownloadingTab: Boolean = false) {
        val bundle = Bundle()
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putString(KEY_TO, VDownloadManagerActivity::class.java.name)
        bundle.putInt(KEY_POSITION, if (switchToDownloadingTab) 1 else 0)
        jumpActivity(context, bundle)
    }

    @JvmStatic
    fun directToSuggestion(context: Context, type: SuggestType) {
        directToSuggestion(context = context, type = type, requestCode = null)
    }

    @JvmStatic
    fun directToSuggestion(context: Context, type: SuggestType, requestCode: Int?) {
        directToSuggestion(context = context, type = type, hiddenHint = "", requestCode = requestCode)
    }

    @JvmStatic
    fun directToSuggestion(context: Context, type: SuggestType, hiddenHint: String) {
        directToSuggestion(context = context, type = type, hiddenHint = hiddenHint, requestCode = null)
    }

    @JvmStatic
    fun directToSuggestion(
        context: Context,
        type: SuggestType,
        hiddenHint: String,
        forceLogin: Boolean = true,
        requestCode: Int?
    ) {
        directToSuggestion(
            context = context,
            type = type,
            hiddenHint = hiddenHint,
            suggestHintType = null,
            forceLogin = forceLogin,
            requestCode = requestCode,
        )
    }

    @JvmStatic
    fun directToSuggestion(
        context: Context,
        type: SuggestType,
        suggestHintType: String? = null,
        content: String? = null,
        isQaFeedback: Boolean = false,
        qaContentId: String = ""
    ) {
        directToSuggestion(
            context = context,
            type = type,
            hiddenHint = "",
            suggestHintType = suggestHintType,
            content = content,
            isQaFeedback = isQaFeedback,
            qaContentId = qaContentId
        )
    }

    @JvmStatic
    fun directToQGameHome(context: Context) {
        context.startActivity(QGameHomeWrapperActivity.getIntent(context))
    }

    @JvmStatic
    fun directToMiniGameSearch(
        context: Context,
        hint: String,
        sourceEntrance: String,
        bottomTab: String = "",
        multiTabId: String = "",
        multiTabName: String = "",
        customPageId: String = "",
        customPageName: String = "",
        searchBoxPattern: String = ""
    ) {
        context.startActivity(
            MiniGameSearchActivity.getIntent(
                context,
                hint,
                sourceEntrance,
                bottomTab,
                multiTabId,
                multiTabName,
                customPageId,
                customPageName,
                searchBoxPattern
            )
        )
    }

    @SuppressLint("CheckResult")
    @JvmStatic
    fun directToQQGameById(
        activity: Activity,
        qqAppId: String
    ) {
        if (activity !is AppCompatActivity || activity.supportFragmentManager.isDestroyed) {
            ToastUtils.toast("启动QQ小游戏失败，请稍后再试")
            return
        }

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            ToastUtils.toast("该游戏仅支持安卓5.0及以上设备")
            return
        }

        val qGameProvider = TheRouter.get(IQGameProvider::class.java)

        if (qGameProvider == null) return

        // 下载广点通广告插件，供 QQ 小游戏启动使用 （当次启动不保证能用，但是下一次就大概率就能了）
        AdPluginDownloadHelper.downloadPluginIfNeeded(isGdt = true)

        CheckLoginUtils.checkLogin(activity, null, true, "QQ小游戏-秒开") {
            val userToken = UserManager.getInstance().token
            val userId = UserManager.getInstance().userId
            val userName = UserManager.getInstance().userInfoEntity?.name ?: "unknown"

            qGameProvider.setLoginInfo(activity, userId, userName, userToken)
            qGameProvider.launchGame(activity, qqAppId) { _, _ ->
                MiniGameRecentlyPlayUseCase.submitRecentPlayedQGame(qqAppId, userId)
            }
        }
    }

    @SuppressLint("CheckResult")
    fun directToWechatGameById(
        activity: Activity,
        wechatAppId: String,
        wechatAppPath: String = "",
        wechatAppExtData: String = ""
    ) {

        val wxApiProxy = WXAPIFactory.createWXAPI(
            activity,
            Config.WECHAT_APPID
        )
        if (!wxApiProxy.isWXAppInstalled) {
            ToastUtils.toast("请安装微信客户端")
            return
        }

        wxApiProxy.sendReq(
            WXLaunchMiniProgram.Req().apply {
                userName = wechatAppId
                path = wechatAppPath.ifEmpty { Constants.WECHAT_MINI_GAME_PCS }
                extData = wechatAppExtData
                miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE
            }
        )

        MiniGameRecentlyPlayUseCase.submitRecentPlayedWGame(wechatAppId, HaloApp.getInstance().gid)
    }

    @JvmStatic
    fun directToMessageCenter(defaultTabIndex: Int, source: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.messageWrapperActivity)
            .appendQueryParameter(RouteConsts.QueryParams.REQUIRE_LOGIN, "true")
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        TheRouter.build(uri.toString())
            .withInt(BaseActivity_TabLayout.PAGE_INDEX, defaultTabIndex)
            .navigation()
    }

    // 跳转游戏单合集详情
    @JvmStatic
    fun directToGameCollectionListDetail(
        context: Context,
        collectionId: String,
        collectionName: String,
        explain: String,
        entrance: String = ""
    ) {
        context.startActivity(
            GameCollectionListDetailActivity.getIntent(
                context,
                GameCollectionListEntity(id = collectionId, name = collectionName, explain = explain),
                entrance
            )
        )
    }

    /**
     * 跳转到游戏订阅页面
     * @param context 上下文
     */
    @JvmStatic
    fun directToServersSubscribedGameList(context: Context) {
        context.startActivity(ServersSubscribedGameListActivity.getIntent(context))
    }

    /**
     * 跳转到开服订阅页面
     */
    @JvmStatic
    fun directToServersCalendarManagement(entrance: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.serversCalendarManagementActivity)
            .appendQueryParameter(RouteConsts.QueryParams.REQUIRE_LOGIN, "true")
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, entrance)
            .build()

        TheRouter.build(uri.toString())
            .navigation()
    }

    fun directToSearch(
        context: Context,
        searchType: String,
        searchHint: String,
        entrance: String,
        sourceEntrance: String,
        bottomTab: String = "",
        multiTabId: String = "",
        multiTabName: String = "",
        customPageId: String = "",
        customPageName: String = "",
        searchBoxPattern: String = ""
    ) {
        when (searchType) {
            BottomTab.SearchStyle.TYPE_HALO_GAME -> context.startActivity(
                SearchActivity.getIntent(
                    context,
                    false,
                    searchHint,
                    entrance,
                    sourceEntrance,
                    bottomTab,
                    multiTabId,
                    multiTabName,
                    customPageId,
                    customPageName,
                    searchBoxPattern
                )
            )

            BottomTab.SearchStyle.TYPE_MINI_GAME -> directToMiniGameSearch(
                context,
                "请输入小游戏关键词",
                sourceEntrance,
                bottomTab,
                multiTabId,
                multiTabName,
                customPageId,
                customPageName,
                searchBoxPattern
            )

            BottomTab.SearchStyle.TYPE_BBS -> directToForumOrUserSearch(
                context,
                "",
                entrance,
                sourceEntrance,
                "",
                bottomTab,
                multiTabId,
                multiTabName,
                customPageId,
                customPageName,
                searchBoxPattern
            )
        }
    }

    @JvmStatic
    fun directToMyGame(defaultTabIndex: Int, source: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.myGameActivity)
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        TheRouter.build(uri.toString())
            .withInt(BaseActivity_TabLayout.PAGE_INDEX, defaultTabIndex)
            .navigation()
    }

    @JvmStatic
    fun directToDeliveryInfo(source: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.deliveryInfoActivity)
            .appendQueryParameter(RouteConsts.QueryParams.REQUIRE_LOGIN, "true")
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        TheRouter.build(uri.toString())
            .navigation()
    }

    @JvmStatic
    fun directToGameArchive(source: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.gameArchiveListActivity)
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        TheRouter.build(uri.toString())
            .navigation()
    }

    @JvmStatic
    fun directToSimulatorGame(source: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.simulatorGameActivity)
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        TheRouter.build(uri.toString())
            .navigation()
    }

    @JvmStatic
    fun directToTeenMode(source: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.teenagerModeActivity)
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        TheRouter.build(uri.toString())
            .navigation()
    }

    @JvmStatic
    fun directToUserInfo(source: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.userInfoActivity)
            .appendQueryParameter(RouteConsts.QueryParams.REQUIRE_LOGIN, "true")
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        TheRouter.build(uri.toString())
            .navigation()
    }

    @JvmStatic
    fun directToCleanApk(context: Context, source: String) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.cleanApkActivity)
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        PermissionHelper.checkManageAllFilesOrStoragePermissionBeforeAction(context) {
            TheRouter.build(uri.toString())
                .navigation()
        }
    }

    @JvmStatic
    fun directToAccountSecurity(source: String, isLogoutStyle: Boolean = false) {
        val uri = Uri.Builder()
            .path(RouteConsts.activity.securityActivity)
            .appendQueryParameter(RouteConsts.QueryParams.REQUIRE_LOGIN, "true")
            .appendQueryParameter(RouteConsts.QueryParams.SOURCE, source)
            .build()

        TheRouter.build(uri.toString())
            .withString(KEY_ENTRANCE, source)
            .withBoolean(KEY_DISPLAY_TYPE, isLogoutStyle)
            .navigation()
    }

    // 跳转云存档详情页
    @JvmStatic
    fun directToCloudArchive(
        context: Context,
        gameId: String,
        gameName: String,
        configUrl: String = "",
        entrance: String = ""
    ) {
        val bundle = Bundle()
        val gameEntity = GameEntity(id = gameId, name = gameName)
        bundle.putParcelable(KEY_GAME_ENTITY, gameEntity)
        bundle.putString(KEY_ARCHIVE_CONFIG_URL, configUrl)
        bundle.putString(KEY_ENTRANCE, entrance)
        bundle.putBoolean(KEY_USE_ALTERNATIVE_LAYOUT, true)
        context.startActivity(ShellActivity.getIntent(context, Type.CLOUD_ARCHIVE, bundle))
    }

    @JvmStatic
    fun navigateToMyAssetsPage(context: Context, entrance: String?) {
        if (CheckLoginUtils.isLogin()) {
            TheRouter.build(RouteConsts.activity.myAssetsActivity).navigation(context)
        } else {
            CheckLoginUtils.checkLogin(context, entrance, null)
        }

    }
}