package com.xxfc.rv.other;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import com.rv.im.CustomerListActivity;

public class RvActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {

    private static int ativiteCount;

    private static boolean isInChatView; // app是否正在聊天模块

    private static boolean isSpecialCases;  // 是否处于特殊情况，例如相机，图片选择

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
        if (CustomerListActivity.class.getSimpleName().equals(activity.getClass().getSimpleName())) {
            isInChatView = true;
        }
    }

    @Override
    public void onActivityStarted(Activity activity) {

    }

    @Override
    public void onActivityResumed(Activity activity) {
        ativiteCount += 1;
    }

    @Override
    public void onActivityPaused(Activity activity) {
        ativiteCount -= 1;
    }

    @Override
    public void onActivityStopped(Activity activity) {

    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {
        if (CustomerListActivity.class.getSimpleName().equals(activity.getClass().getSimpleName())) {
            isInChatView = false;
        }
    }

    public static boolean isAppBackground() {
        return ativiteCount == 0 ? true : false && !isSpecialCases;
    }

    public static boolean isAppInChatView() {
        return isInChatView;
    }

    public static boolean isIsSpecialCases() {
        return isSpecialCases;
    }

    public static void setIsSpecialCases(boolean isSpecialCases) {
        RvActivityLifecycleCallbacks.isSpecialCases = isSpecialCases;
    }
}
