package com.zswc.creativity.activity

import android.graphics.Typeface
import android.text.method.HideReturnsTransformationMethod
import android.text.method.PasswordTransformationMethod
import com.qmuiteam.qmui.kotlin.onClick
import com.zswc.creativity.R
import com.zswc.creativity.base.MBActivity
import com.zswc.creativity.databinding.ActivityLoginBinding
import com.zswc.creativity.vmodel.LoginVModel


class LoginActivity : MBActivity<LoginVModel, ActivityLoginBinding>() {

    //测试 15801075991 密码 123456

    override fun title(): String? {
        return null
    }

    override fun binding(): ActivityLoginBinding {
        return ActivityLoginBinding.inflate(layoutInflater)
    }

    override fun vmClass(): Class<LoginVModel> {
        return LoginVModel::class.java
    }

    override fun listeners() {
        super.listeners()
        binding.imgEyes.onClick {

            binding.etPassword.typeface = Typeface.DEFAULT
            binding.etPassword.transformationMethod = PasswordTransformationMethod()

            if (vm.eyes.value == 1) {//闭眼
                binding.etPassword.transformationMethod = PasswordTransformationMethod.getInstance()

                if (binding.etPassword.text.toString().trim().isNotEmpty()) {
                    val textLength: Int = binding.etPassword.text?.length!!
                    binding.etPassword.setSelection(textLength, textLength)
                }
                binding.imgEyes.setImageResource(R.drawable.ct_close_eyes)
                vm.eyes.value = 0

            } else {
                //睁眼
                binding.etPassword.transformationMethod = HideReturnsTransformationMethod.getInstance()
                if (binding.etPassword.text.toString().trim().isNotEmpty()) {
                    val textLength: Int = binding.etPassword.text?.length!!
                    binding.etPassword.setSelection(textLength, textLength)
                }
                binding.imgEyes.setImageResource(R.drawable.ct_open_eyes)
                vm.eyes.value = 1
            }
        }

        binding.imgSure.onClick {
            if (vm.isRead.value == 0) {//去勾选
                binding.imgSure.setImageResource(R.drawable.ct_select_on)
                vm.isRead.value = 1
            } else {
                binding.imgSure.setImageResource(R.drawable.ct_select_off)
                vm.isRead.value = 0

            }
        }
    }


//全屏
//    override fun transluent(): Boolean {
//        return true
//    }

    override val isRxbus: Boolean
        get() = true


}
