package com.gh.gamecenter.personalhome.background

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.core.view.ViewCompat
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.login.entity.BackgroundImageEntity

class BackgroundPreviewActivity : BaseActivity() {

    override fun getLayoutId(): Int = R.layout.activity_amway

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

        DisplayUtils.transparentStatusBar(this)
        ViewCompat.getWindowInsetsController(window.decorView)?.isAppearanceLightStatusBars = true

        val containerFragment = supportFragmentManager.findFragmentByTag(BackgroundPreviewFragment::class.java.name)
            ?: BackgroundPreviewFragment().with(intent.extras)
        // 若 placeholder 外层为 RelativeLayout 的话，会出现莫名的偏移
        supportFragmentManager.beginTransaction()
            .replace(R.id.placeholder, containerFragment, BackgroundPreviewFragment::class.java.name)
            .commitAllowingStateLoss()
    }

    override fun isAutoResetViewBackgroundEnabled(): Boolean = true

    companion object {
        fun getIntent(context: Context, localPath: String, entity: BackgroundImageEntity?): Intent {
            val intent = Intent(context, BackgroundPreviewActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_LOCAL_PATH, localPath)
            if (entity != null) {
                intent.putExtra(BackgroundImageEntity::class.java.simpleName, entity)
            }
            return intent
        }
    }
}