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.utils.updateStatusBarColor

class VDownloadManagerActivity : ToolBarActivity() {

    private var mFragment: VDownloadManagerWrapperFragment? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        updateStatusBarColor(R.color.background_white, R.color.background_white)
        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(R.color.background_white, R.color.background_white)
    }

    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
        }
    }

}