package com.gh.gamecenter

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.gh.gamecenter.common.base.activity.BaseActivity
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.common.constant.EntranceConsts
import com.halo.assistant.fragment.WebFragment

class FullScreenWebActivity : BaseActivity() {

    private var mWebFragment: WebFragment? = null

    override fun getLayoutId() = R.layout.activity_amway

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

        DisplayUtils.transparentStatusBar(this)

        mWebFragment = supportFragmentManager.findFragmentByTag("webFragment") as? WebFragment
            ?: WebFragment().apply { with(intent.extras) }
        supportFragmentManager.beginTransaction().replace(R.id.placeholder, mWebFragment!!, "webFragment")
            .commitAllowingStateLoss()
    }

    override fun handleBackPressed(): Boolean {
        return mWebFragment?.onBackPressed() ?: super.handleBackPressed()
    }

    companion object {
        fun getIntent(
            context: Context,
            url: String,
            webViewHandleBackPressed: Boolean = false,
            entrance: String? = null
        ): Intent {
            val intent = Intent(context, FullScreenWebActivity::class.java)
            if (entrance != null) intent.putExtra(EntranceConsts.KEY_ENTRANCE, entrance)
            intent.putExtra(EntranceConsts.KEY_URL, url)
            intent.putExtra(WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_BACK_PRESSED, webViewHandleBackPressed)
            return intent
        }
    }

}