package com.eyuancomm.demo

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import cn.yyxx.support.HostModelUtils
import cn.yyxx.support.hawkeye.ToastUtils

/**
 * @author #Suyghur.
 * Created on 2021/06/17
 */
class EnvActivity : AppCompatActivity(), View.OnClickListener {

    companion object {
        fun start(activity: Activity) {
            activity.startActivity(Intent(activity, EnvActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
        }
    }

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

        with(LinearLayout(this)) {

            orientation = LinearLayout.VERTICAL

            val btnTest = Button(this@EnvActivity)
            btnTest.text = "00 测试环境"
            btnTest.tag = HostModelUtils.ENV_TEST
            btnTest.setOnClickListener(this@EnvActivity)
            addView(btnTest)

            val btnOnline = Button(this@EnvActivity)
            btnOnline.text = "01 线上环境"
            btnOnline.tag = HostModelUtils.ENV_ONLINE
            btnOnline.setOnClickListener(this@EnvActivity)
            addView(btnOnline)
            setContentView(this)
        }
    }

    override fun onClick(v: View?) {
        v?.apply {
            HostModelUtils.setHostModel(this@EnvActivity, tag as Int)
            ToastUtils.toastInfo(this@EnvActivity, "接口环境切换成功，重启应用后生效")
        }
    }
}