Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Connection Status: Added Network Broadcast Receiver
Browse files Browse the repository at this point in the history
Fixes #312
  • Loading branch information
nitish1211 committed Jan 21, 2017
1 parent a4374c1 commit 47521cd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/src/main/java/com/zulip/android/activities/ZulipActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -553,6 +554,7 @@ public Cursor runQuery(CharSequence charSequence) {
handleOnFragmentChange();
calendar = Calendar.getInstance();
setupSnackBar();
setupNetworkBroadcastReceiver();
}

/**
Expand Down Expand Up @@ -2141,4 +2143,32 @@ public void onClick(View view) {
public enum Flag {
RESET_DATABASE,
}
public void setupNetworkBroadcastReceiver()
{
BroadcastReceiver networkStateReceiver = new BroadcastReceiver() {
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Network Listener", "Network Type Changed");
boolean isConnected = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if(isConnected){
//Disable fab when there is no connectivity
fab.setEnabled(false);
fab.setVisibility(View.INVISIBLE);
Snackbar.make(coordinatorLayout,"No Connection!",Snackbar.LENGTH_INDEFINITE).show();
Log.d("Network Listener", "No Internet");
}
else{
//Enabling fab when connection is reestablished
fab.setEnabled(true);
fab.setVisibility(View.VISIBLE);
Snackbar.make(coordinatorLayout,"Connection Established",Snackbar.LENGTH_SHORT).show();
Log.d("Network Listener", "Internet");
}
}
};

IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkStateReceiver, filter);
}
}

0 comments on commit 47521cd

Please sign in to comment.