package com.quansu.heifengwuliu.utils;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.quansu.heifengwuliu.inte.ChoiceData;
import com.ysnows.base.utils.TimeUtil;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by shihuiyun
 * on 2020/9/13
 */
public class PopupUtils {

    /**
     * 有回调
     * 选择时间
     */
    public static void setChoseTime(Context context, TextView tv, ChoiceData choiceData) {
        Calendar startDate = Calendar.getInstance();
        startDate.set(1980, 0, 23);

        Calendar endDate = Calendar.getInstance();
        endDate.set(2020, 12, 31);

//        Calendar endDate = Calendar.getInstance();//当前时间

        TimePickerView timePickerView = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                tv.setText(TimeUtil.getTime(date));
                if(null!=choiceData){
                    choiceData.onRestuse(TimeUtil.getTime(date));
                }

            }
        }).setRangDate(startDate, endDate)
                .setDate(endDate)
                .setType(new boolean[]{true, true, true, true, true, true})
                .build();

        timePickerView.setDate(Calendar.getInstance());
        timePickerView.show();
    }

    public static void setChoseTime(Context context,ChoiceData choiceData) {
        Calendar startDate = Calendar.getInstance();
        startDate.set(1980, 0, 23);

        Calendar endDate = Calendar.getInstance();
        endDate.set(2020, 12, 31);


        TimePickerView timePickerView = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {

                if(null!=choiceData){
                    choiceData.onRestuse(TimeUtil.getTime(date));
                }

            }
        }).setRangDate(startDate, endDate)
                .setDate(endDate)
                .setType(new boolean[]{true, true, true, true, true, true})
                .build();

        timePickerView.setDate(Calendar.getInstance());
        timePickerView.show();
    }

}
