package com.quyunshuo.module.home.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.format.DateFormat;
import android.util.Log;

import com.quyunshuo.androidbaseframemvvm.common.constant.MqName;
import com.quyunshuo.androidbaseframemvvm.common.constant.event.ApiMessageEvent;
import com.quyunshuo.androidbaseframemvvm.common.enums.AlarmClockEnum;
import com.quyunshuo.androidbaseframemvvm.common.util.XLogUtil;

import org.greenrobot.eventbus.EventBus;

/**
 * 监听并启动定时清洗任务广播.
 */
public class TimedCleaningTaskAlarmReceiver extends BroadcastReceiver {
    private static final String TAG = "TimedCleaningTaskAlarmR";

    @Override
    public void onReceive(Context context, Intent intent) {
        String msg = intent.getStringExtra("msg");
        //获取系统时间
        long sysTime = System.currentTimeMillis();
        //时间显示格式
        CharSequence sysTimeStr = DateFormat.format("yyyy-MM-dd HH:mm:ss", sysTime);
        Log.d(TAG, "AlarmManagerUtil parseWeekTim onReceivetime: " + msg + ":" + sysTimeStr);
        XLogUtil.INSTANCE.d("AlarmManagerUtil:" + msg);
        //LogUtils.logWrite("parseWeekTim onReceivetime: "+msg);
        if ("0".equals(msg)) {
            //开机了则不能开机了。
            //LogUtils.logWrite("定时开机："+open);
            EventBus.getDefault().post(new ApiMessageEvent(AlarmClockEnum.OPEN_DEV.getCode(), "开机"));
        } else if ("1".equals(msg)) {
            //开启一个定时闹钟，1.弹窗。2.倒计时。3.关机 4.结束弹窗
            EventBus.getDefault().post(new ApiMessageEvent(AlarmClockEnum.CLOSE_DEV.getCode(), "关机"));
        } else if ("1show".equals(msg)) {
            EventBus.getDefault().post(new ApiMessageEvent(AlarmClockEnum.CLOSE_DEV.getCode() + "show", "关机"));
        } else if ("2".equals(msg)) {
            //LogUtils.logWrite("休眠2？："+msg);
            //睡眠
            EventBus.getDefault().post(new ApiMessageEvent(MqName.INSTANCE.getIS_SLEEP(), "1"));
        } else if ("3".equals(msg)) {
            //LogUtils.logWrite("休眠3？："+msg);
            //唤醒。
            EventBus.getDefault().post(new ApiMessageEvent(MqName.INSTANCE.getIS_SLEEP(), "0"));
        }
    }
}
