package com.sunzee.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.sunzee.model.message.ApiMessageEvent;
import com.sunzee.utils.AlarmManagerUtil;

import org.greenrobot.eventbus.EventBus;

/**
 * 监听并启动定时清洗任务广播.
 */
public class TimedCleaningTaskAlarmReceiver extends BroadcastReceiver {
    private static final String TAG = "TimedCleaningTaskAlarmR";
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        String msg = intent.getStringExtra("msg");
        long intervalMillis = intent.getLongExtra("intervalMillis", 0);
        if (intervalMillis != 0) {
            AlarmManagerUtil.setAlarmTime(context, System.currentTimeMillis() + intervalMillis,
                    intent);
        }
        // todo 定时清洗的逻辑
        Log.d(TAG, "onReceive: "+msg);
        EventBus.getDefault().post(new ApiMessageEvent("startClean", "闹钟响了26"));
    }


}
