package com.zj365.mime.act

import android.text.Editable
import android.text.TextWatcher
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.IBaseAct
import com.xty.common.arouter.ARouterUrl
import com.xty.common.util.CommonToastUtils
import com.zj365.mime.databinding.ActNickNameBinding

/**
 * 昵称修改
 */
@Route(path = ARouterUrl.NICK_INFO)
class NickNameAct: IBaseAct() {
    val binding by lazy{ActNickNameBinding.inflate(layoutInflater)}
    val textWatch by lazy{
       object: TextWatcher{
           override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
           }
           override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
           }
           override fun afterTextChanged(s: Editable?) {
               binding.mEdit.removeTextChangedListener(this)
              var size= s.toString().length
               binding.mSize.text="$size/15"
               binding.mEdit.addTextChangedListener(this)
           }

       }
    }
    override fun setLayout()=binding.root
    override fun initData() {
        super.initData()
        isDarkBar=true
    }

    override fun initView() {
        super.initView()
        statusBar(binding.mView)
        binding.mIvBack.setOnClickListener {
            finish()
        }
        binding.mTvComplete.setOnClickListener {
            var name=binding.mEdit.text.toString().trim()
            if(name.isEmpty()){
                CommonToastUtils.showToast("昵称不能为空")
                return@setOnClickListener
            }
            MyInfoAct.nameLive.value=name
            finish()
        }
        binding.mEdit.addTextChangedListener(textWatch)
    }
}