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.BaseActivity
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.feature.entity.GameEntity

class VSpaceLoadingActivity : BaseActivity() {

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

        DisplayUtils.transparentStatusBar(this)
        DisplayUtils.setLightStatusBar(this, true)

        if (savedInstanceState == null) {
            resetFragment()
        }
    }

    override fun getLayoutId() = R.layout.activity_shell

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

        resetFragment()
    }

    private fun resetFragment() {
        val fragment = VSpaceLoadingFragment().apply { arguments = intent?.extras }
        supportFragmentManager.beginTransaction()
            .replace(R.id.placeholder, fragment, VSpaceLoadingFragment::class.java.name)
            .commitAllowingStateLoss()
    }

    companion object {
        const val IS_INSTALLATION = "is_installation"

        @JvmStatic
        fun getIntent(context: Context, game: GameEntity, isInstall: Boolean): Intent {
            val intent = Intent(context, VSpaceLoadingActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_DATA, game)
            intent.putExtra(IS_INSTALLATION, isInstall)
            return intent
        }
    }

}