package com.android.chmo.utils;

import android.os.CountDownTimer;
import android.widget.TextView;

/**
 * 获取验证码计数器
 */
public class VerifyCodeCounter extends CountDownTimer {
    private TextView tv;

    private boolean isFinish = true;

    public VerifyCodeCounter(long millisInFuture, long countDownInterval,
                             TextView tv) {
        super(millisInFuture, countDownInterval);
        this.tv = tv;
    }

    @Override
    public void onFinish() {
        isFinish = true;
        tv.setText("获取验证码");
        tv.setEnabled(true);
    }

    @Override
    public void onTick(long millisUntilFinished) {
        isFinish = false;
        tv.setEnabled(false);
        tv.setText((millisUntilFinished / 1000 - 1) + "s");
    }

    public boolean isFinish() {
        return isFinish;
    }

}
