package com.unis.sxzcl.ui.user;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.unis.model.DataCallback;
import com.unis.model.UserModel;
import com.unis.sxzcl.R;
import com.unis.sxzcl.base.BaseFragment;
import com.unis.sxzcl.databinding.FragmentVerifyPwdBinding;
import com.xyxsbj.mylibrary.tool.ETTool;
import com.xyxsbj.mylibrary.tool.StringTool;
import com.xyxsbj.mylibrary.tool.ToastTool;

/**
 * 验证密码
 * 创建人: mQ
 * 时间: 2021/3/18 10:34
 */
public class VerifyPwdFragment extends BaseFragment<FragmentVerifyPwdBinding> {


    @Override
    protected FragmentVerifyPwdBinding getViewBinding(LayoutInflater inflater, ViewGroup container) {
        return FragmentVerifyPwdBinding.inflate(inflater, container, false);
    }

    @Override
    protected void init() {
        mBinding.bar.setTitle("验证密码")
                .setLeftClickListener(v -> onBack());
        mBinding.btnVerify.setOnClickListener(v -> onVerify());
    }

    @Override
    protected void onFirstShow() {

    }

    /**
     * 验证密码
     */
    private void onVerify() {
        String pwd = ETTool.getData(mBinding.etCurrentPwd);
        if (StringTool.isEmpty(pwd)) {
            ToastTool.showLong("请输入密码");
            return;
        }

        showProgress("正在验证密码...");
        UserModel.get().verifyPwd(pwd, new DataCallback<String>() {
            @Override
            public void onSuccess(String data) {
                hideProgress();
                if (!data.equals("1")) {
                    ToastTool.showLong("密码错误");
                    return;
                }
                ETTool.closeSoftKeybord(mBinding.etCurrentPwd);
                navigation(R.id.changePwdFragment);
            }

            @Override
            public void onError(String error) {
                super.onError(error);
                hideProgress();
            }
        });

    }
}
