package cn.org.bjca.trust.pushdemo

import android.content.Intent
import android.os.Bundle
import cn.org.bjca.trust.push.PushSdk
import cn.org.bjca.trust.pushdemo.databinding.ActivityLoginBinding
import com.xuqm.base.dialog.loading.LoadingDialog
import com.xuqm.base.extensions.showMessage
import com.xuqm.base.ui.BaseActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class LoginActivity : BaseActivity<ActivityLoginBinding>() {
    override fun showStatus(): Int = R.color.purple_700
    override fun getLayoutId(): Int = R.layout.activity_login
    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        binding.button.setOnClickListener {

            if (binding.username.text.isNotEmpty()) {
                LoadingDialog.showDialog("正在登录，请稍候···")
                CoroutineScope(Dispatchers.IO).launch {
                    delay(2000L)
                    LoadingDialog.dismissDialog()
                    PushSdk.instance.register(binding.username.text.toString())
                    startActivity(Intent(mContext, MainActivity::class.java))
                }
            }
            else "请输入用户名".showMessage()

        }
    }
}