package com.quansu.heifengwuliu.activity

import android.os.Bundle
import android.os.Handler
import com.quansu.heifengwuliu.R
import com.quansu.heifengwuliu.base.MBActivity
import com.quansu.heifengwuliu.databinding.ActivityPasswordBinding
import com.quansu.heifengwuliu.view.PasswordView
import com.quansu.heifengwuliu.view.PasswordView.PasswordListener
import com.quansu.heifengwuliu.vmodel.PasswordVModel
import java.util.*

class PasswordActivity : MBActivity<PasswordVModel, ActivityPasswordBinding>() {


    var type=1//1：登录密码 2支付密码
    var oldPassword=""
    var newPassword=""

    override fun __before() {
        super.__before()

        type= intent?.extras?.getInt("type", 1)!!

    }

    override fun initCreate(savedInstanceState: Bundle?) {
        super.initCreate(savedInstanceState)
        vm.type.value= type
        if(type==2){
            //初始化密码输入框
            initPassword()
        }
    }



   private fun initPassword(){


       binding.ppetOldPassword.setPasswordListener(object :PasswordListener{
           override fun keyEnterPress(password: String?, isComplete: Boolean) {

               oldPassword= password!!
           }

           override fun passwordChange(changeText: String?) {
           }

           override fun passwordComplete() {

           }

       })

       binding.ppetNewPassword.setPasswordListener(object :PasswordListener{
           override fun keyEnterPress(password: String?, isComplete: Boolean) {

               newPassword= password!!
           }

           override fun passwordChange(changeText: String?) {
           }

           override fun passwordComplete() {

           }

       })

       binding.btnPaySubmit.setOnClickListener {
           vm.toPaySubmit(oldPassword,newPassword)
       }


   }




    override fun title(): String? {
        return if(type==1) {
            "设置登录密码"
        }else{
            "设置支付密码"
        }
    }
    override fun binding(): ActivityPasswordBinding {
        return ActivityPasswordBinding.inflate(layoutInflater)
    }

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



}
