package com.gh.vspace

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.activity.ToolBarActivity
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.constant.EntranceConsts.KEY_CUSTOM_PAGE_LOCATION
import com.gh.gamecenter.common.constant.EntranceConsts.KEY_ENTRANCE
import com.gh.gamecenter.common.utils.updateStatusBarColor
import com.gh.gamecenter.feature.entity.PageLocation

/**
 * 畅玩游戏管理
 */
class VDownloadManagerActivity : ToolBarActivity() {

    private var mFragment: VDownloadManagerWrapperFragment? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        updateStatusBarColor(com.gh.gamecenter.common.R.color.ui_surface, com.gh.gamecenter.common.R.color.ui_surface)
        if (savedInstanceState == null) {
            mFragment = VDownloadManagerWrapperFragment()
            mFragment?.arguments = intent.extras
            supportFragmentManager.beginTransaction().replace(R.id.placeholder, mFragment!!).commitAllowingStateLoss()
            updateTargetFragment(mFragment)
        }
    }

    override fun getLayoutId() = R.layout.activity_vdownload_manager

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)

        mFragment?.onNewIntent(intent)
    }

    override fun onDarkModeChanged() {
        super.onDarkModeChanged()
        updateStatusBarColor(com.gh.gamecenter.common.R.color.ui_surface, com.gh.gamecenter.common.R.color.ui_surface)
    }

    companion object {
        @JvmStatic
        @JvmOverloads
        fun getIntent(
            context: Context,
            switchToDownloadingTab: Boolean = false,
            isFromHomeRecent: Boolean = false
        ): Intent {
            val intent = Intent(context, VDownloadManagerActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_POSITION, if (switchToDownloadingTab) 1 else 0)
            intent.putExtra(EntranceConsts.KEY_IS_FROM_HOME_RECENT, isFromHomeRecent)
            return intent
        }

        @JvmStatic
        fun getIntent(
            context: Context,
            entrance: String,
            pageLocation: PageLocation? = null
        ): Intent {
            val intent = Intent(context, VDownloadManagerActivity::class.java)
            intent.putExtra(KEY_ENTRANCE, entrance)
            intent.putExtra(KEY_CUSTOM_PAGE_LOCATION, pageLocation)
            return intent
        }
    }

}