package com.ez.ertc.meeting.presenter;

import android.annotation.SuppressLint;

import com.ez.baselib.utils.LogUtil;
import com.ez.ertc.meeting.ErtcEzmHelper;
import com.ez.ertc.meeting.EzmLifecycleCallback;
import com.ez.ertc.meeting.ui.AirActivity;

import java.lang.ref.WeakReference;

/**
 * @author xiezuoyuan
 * @time 2020/7/13 19:38
 */
public class EzmLifecycleCallbackImpl implements EzmLifecycleCallback {
    private WeakReference<ErtcRoomPresenter> mReference;

    public EzmLifecycleCallbackImpl(ErtcRoomPresenter roomPresenter) {
        this.mReference = new WeakReference<>(roomPresenter);
    }

    @SuppressLint("NewApi")
    @Override
    public void onBackground(boolean background) {
        ErtcRoomPresenter roomPresenter = mReference.get();
        if (roomPresenter != null){
            if (ErtcEzmHelper.ertcEngine == null){
                return;
            }
            if (!background){
                //回到会议activity所在task
                if (roomPresenter.mPInPIntent == null){
                    /**
                     * android系统限制：
                     * 如果回到桌面，5秒钟之内又立即点击APP图标唤起APP，那么APP内的task切换不会立即生效
                     * APP还是在主task内（与5秒内点击悬浮窗不会立即回到app的情况一样）
                     * 如果此时主task存在activity切换，则task切换会立即生效
                     * ps：
                     * 华为mate30pro手机在这种情况下也不会立即生效，但是在“5秒内点击悬浮窗”的情况下能立即回到app
                     */
                    LogUtil.i("EZRTCImpl", "roomPresenter====moveTaskToFront");
                    AirActivity.start(roomPresenter.mView.getActivity());
                }
            }
        }
    }
}
