package cl.monsoon.s1next.widget;

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

public final class AppActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {

    /**
     * Forked from http://stackoverflow.com/a/13809991
     */
    private int visibleCount;

    private WifiBroadcastReceiver mWifiBroadcastReceiver;
    private int mNeedMonitorWifiActivityCount;

    public AppActivityLifecycleCallbacks(Context context) {
        mWifiBroadcastReceiver = new WifiBroadcastReceiver(context);
    }

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}

    @Override
    public void onActivityStarted(Activity activity) {
        visibleCount++;
    }

    @Override
    public void onActivityResumed(Activity activity) {
        if (activity instanceof WifiBroadcastReceiver.NeedMonitorWifi) {
            if (mNeedMonitorWifiActivityCount == 0) {
                mWifiBroadcastReceiver.registerIfNeeded();
            }
            mNeedMonitorWifiActivityCount++;
        }
    }

    @Override
    public void onActivityPaused(Activity activity) {
        if (activity instanceof WifiBroadcastReceiver.NeedMonitorWifi) {
            mNeedMonitorWifiActivityCount--;
            if (mNeedMonitorWifiActivityCount == 0) {
                mWifiBroadcastReceiver.unregisterIfNeeded();
            }
        }
    }

    @Override
    public void onActivityStopped(Activity activity) {
        visibleCount--;
    }

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

    @Override
    public void onActivityDestroyed(Activity activity) {}

    public boolean isAppVisible() {
        return visibleCount > 0;
    }
}

@@ -337,17 +337,18 @@
 ate int 
-v
+mV
 isibleCo
@@ -762,33 +762,34 @@
 vity) %7B%0A        
-v
+mV
 isibleCount++;%0A 
@@ -1534,17 +1534,18 @@
         
-v
+mV
 isibleCo
@@ -1780,17 +1780,18 @@
  return 
-v
+mV
 isibleCo

Fix incorrect code style