package com.halo.assistant.accelerator

import android.graphics.Color
import android.os.Bundle
import com.gh.gamecenter.common.base.activity.BaseActivity
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts.KEY_URL
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.utils.EnvHelper
import com.gh.gamecenter.core.utils.DisplayUtils
import com.halo.assistant.fragment.WebFragment
import com.therouter.router.Route

@Route(
    path = RouteConsts.activity.myAssetsActivity,
    description = "我的资产"
)
class MyAssetsActivity : BaseActivity() {

    override fun getLayoutId(): Int {
        return com.gh.gamecenter.common.R.layout.activity_member
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        DisplayUtils.setLightStatusBar(this, true)
        setStatusBarColor(Color.TRANSPARENT)

        val url = if (EnvHelper.isDevEnv) {
            Constants.MY_ASSETS_DEV
        } else {
            Constants.MY_ASSETS
        }
        val bundle = Bundle().apply {
            putString(KEY_URL, url)
        }
        val containerFragment = supportFragmentManager.findFragmentByTag(WebFragment::class.java.name)
            ?: WebFragment().with(bundle)
        // 若 placeholder 外层为 RelativeLayout 的话，会出现莫名的偏移
        supportFragmentManager.beginTransaction()
            .replace(
                com.gh.gamecenter.selector.R.id.layout_activity_content,
                containerFragment,
                WebFragment::class.java.name
            )
            .commitAllowingStateLoss()
    }
}