package com.gem.media;

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

import com.gem.media.splash.base.utils.ALog;
import com.gem.media.util.SplashWindowViewManger;
import com.live.KpUtil;

import java.util.Objects;

public class ScreenBroadcastReceiver  extends BroadcastReceiver {
    long time = 0;
    private static final int T = 1000;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (null != intent) {
            if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_OFF)
                    || Objects.equals(intent.getAction(), Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
                if (System.currentTimeMillis() - time > T) {
                    SplashWindowViewManger.getInstance().removeSplashWindowView(1);
                    time = System.currentTimeMillis();
                }
                if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_OFF)) {
                    KpUtil.getInstance().setIsScreenOn(false);
                }
            } else if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_ON)) {
                KpUtil.getInstance().setIsScreenOn(true);
                KpUtil.getInstance().startLive(context);
            }
        }
    }
}
