package ch.epfl.sweng.project;

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


public class NetworkHandler {

    private Context mContext = null;
    private ConnectivityManager mConnManager = null;


    public NetworkHandler(Context context) {
        mContext = context;
        mConnManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    }

    /**
     * Check whether the internet connection is available or not. If the connection isn't available
     * inform the user with a "Toast message".
     *
     * @return true if connected, false otherwise
     */
    public boolean isConnected() {
        NetworkInfo networkInfo = mConnManager.getActiveNetworkInfo();

        if(networkInfo != null && networkInfo.isConnected()) {
            return true;
        }

        Toast.makeText(mContext, "No Internet connection", Toast.LENGTH_LONG).show();
        return false;
    }
}

@@ -159,16 +159,93 @@
 Toast;%0A%0A
+/**%0A * This class allows to check if the device is connected to internet.%0A */
 %0Apublic 
@@ -288,18 +288,17 @@
 Context 
-mC
+c
 ontext =
@@ -336,21 +336,28 @@
 Manager 
-mC
+c
 onn
+ectivity
 Manager 
@@ -369,64 +369,319 @@
 l;%0A%0A
-%0A    public NetworkHandler(Context context) %7B%0A        mC
+    /**%0A     * The constructor of the class.%0A     *%0A     * @param context the context where to show the toast message if no internet connection is available%0A     */%0A    public NetworkHandler(Context context) %7B%0A        if (context == null) %7B%0A            throw new NullPointerException();%0A        %7D%0A        this.c
 onte
@@ -702,21 +702,28 @@
         
-mC
+c
 onn
+ectivity
 Manager 
@@ -951,10 +951,9 @@
 h a 
-%22T
+t
 oast
@@ -960,17 +960,16 @@
  message
-%22
 .%0A     *
@@ -1100,13 +1100,20 @@
 o = 
-mC
+c
 onn
+ectivity
 Mana
@@ -1151,16 +1151,17 @@
       if
+ 
 (network
@@ -1268,10 +1268,9 @@
 ext(
-mC
+c
 onte

refactor + comments