package com.breadwallet.tools.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by byfieldj on 2/15/18.
 * <p>
 * <p>
 * Reusable class to quick check whether user is connect to Wifi or mobile data
 */

public class BRConnectivityStatus {


    private Context mContext;


    public BRConnectivityStatus(Context context) {
        this.mContext = context;
    }


    // Returns true if connected to wifi, false if connected to mobile data
    public boolean isWifiOrMobileDataConntected() {
        ConnectivityManager cm = (ConnectivityManager)
                mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netinfo = cm.getActiveNetworkInfo();

        if (netinfo != null && netinfo.isConnectedOrConnecting()) {
            android.net.NetworkInfo wifi =
                    cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            android.net.NetworkInfo mobile =
                    cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

            if ((mobile != null && mobile.isConnectedOrConnecting()) || (wifi != null &&
                    wifi.isConnectedOrConnecting())) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }


}

@@ -341,16 +341,192 @@
 ontext;%0A
+    public static final int NO_NETWORK = 0;%0A    public static final int WIFI_ON = 1;%0A    public static final int MOBILE_ON = 2;%0A    public static final int MOBILE_WIFI_ON = 3;%0A
 %0A%0A    pu
@@ -702,24 +702,14 @@
 lic 
-boolean isWifiOr
+int is
 Mobi
@@ -718,13 +718,18 @@
 Data
+OrWifi
 Conn
-t
 ecte
@@ -1215,24 +1215,62 @@
 E_MOBILE);%0A%0A
+            // Mobile Data is on only%0A
             
@@ -1330,27 +1330,27 @@
 ()) 
-%7C%7C
+&&
  (wifi 
-!
+=
 = null 
-&&
+%7C%7C
 %0A   
@@ -1366,16 +1366,17 @@
         
+!
 wifi.isC
@@ -1429,87 +1429,275 @@
 urn 
-true;%0A            %7D else %7B%0A                return false;%0A            %7D%0A
+MOBILE_ON;%0A%0A                // Wifi is on only%0A            %7D else if (wifi != null && wifi.isConnectedOrConnecting() && (mobile == null %7C%7C !mobile.isConnectedOrConnecting())) %7B%0A                return WIFI_ON;%0A%0A                // Both mobile and wifi is on%0A   
         
 %7D el
@@ -1696,16 +1696,124 @@
     
+ 
 %7D else 
-%7B
+if (mobile != null && wifi != null && mobile.isConnectedOrConnecting() && wifi.isConnectedOrConnecting()) %7B%0A
 %0A   
@@ -1825,37 +1825,94 @@
     
+    
 return 
-false;%0A        %7D%0A    %7D
+MOBILE_WIFI_ON;%0A            %7D%0A        %7D%0A%0A        return NO_NETWORK;%0A    %7D%0A%0A
 %0A%0A%0A%7D

Fix mobile and wifi check logic