package com.ym.userinfo.module.utils;

import android.os.CountDownTimer;

import com.ym.library.utils.DateUtils;

/**
 * Craeted by ${junqi.li}
 * Craeted by 2020/8/27
 */
public class TimeTaskUtils {
    private static final String FORMAT = "mm:ss";

    //开启计时器
    public static CountDownTimer startTimeTask(int time, final ITimeCallback callback) {
        return new CountDownTimer(time, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                callback.onTick(millisUntilFinished,
                        DateUtils.getStringByFormat(millisUntilFinished, FORMAT));
            }

            @Override
            public void onFinish() {
                callback.onFinish();
            }
        }.start();
    }

    public interface ITimeCallback {
        void onTick(Long millisUntilFinished, String time);

        void onFinish();
    }
}
