From 437d0f69383cfb13a5ceac61d64755ffa49f8ed7 Mon Sep 17 00:00:00 2001 From: Anubhav Mittal Date: Fri, 12 Jun 2020 00:47:45 +0530 Subject: [PATCH] fix: Added network change register --- .../fineract/ui/online/DashboardActivity.java | 10 ++++++++ .../fineract/utils/NetworkChangeReceiver.java | 23 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 34 insertions(+) create mode 100644 app/src/main/java/org/apache/fineract/utils/NetworkChangeReceiver.java diff --git a/app/src/main/java/org/apache/fineract/ui/online/DashboardActivity.java b/app/src/main/java/org/apache/fineract/ui/online/DashboardActivity.java index 15b4d61f..d5e4b80d 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/DashboardActivity.java +++ b/app/src/main/java/org/apache/fineract/ui/online/DashboardActivity.java @@ -1,6 +1,7 @@ package org.apache.fineract.ui.online; import android.content.Intent; +import android.content.IntentFilter; import android.os.Bundle; import android.os.Handler; @@ -33,6 +34,7 @@ import org.apache.fineract.ui.online.teller.TellerFragment; import org.apache.fineract.ui.product.ProductFragment; import org.apache.fineract.utils.MaterialDialog; +import org.apache.fineract.utils.NetworkChangeReceiver; import javax.inject.Inject; @@ -74,6 +76,8 @@ protected void onCreate(Bundle savedInstanceState) { StartSyncJob.scheduleItNow(); preferencesHelper.setFetching(false); } + + registerNetworkRegister(); } public void setupNavigationBar() { @@ -105,6 +109,12 @@ public void onDrawerSlide(View drawerView, float slideOffset) { actionBarDrawerToggle.syncState(); } + public void registerNetworkRegister() { + IntentFilter filter = new IntentFilter(); + filter.addAction("android.net.conn.CONNECTIVITY_CHANGE"); + registerReceiver(new NetworkChangeReceiver(), filter); + } + @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { clearFragmentBackStack(); diff --git a/app/src/main/java/org/apache/fineract/utils/NetworkChangeReceiver.java b/app/src/main/java/org/apache/fineract/utils/NetworkChangeReceiver.java new file mode 100644 index 00000000..f6e12b06 --- /dev/null +++ b/app/src/main/java/org/apache/fineract/utils/NetworkChangeReceiver.java @@ -0,0 +1,23 @@ +package org.apache.fineract.utils; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.widget.Toast; + +import org.apache.fineract.R; + + +public class NetworkChangeReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + final ConnectivityManager connectivityManager = (ConnectivityManager) context + .getSystemService(Context.CONNECTIVITY_SERVICE); + final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); + if (activeNetworkInfo == null) + Toast.makeText(context, context.getString(R.string.toast_internet_offline), + Toast.LENGTH_LONG).show(); + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8744d5d9..36fee50e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -500,4 +500,5 @@ Email Logged out successfully. Please click BACK again to exit + You are offline as you are not connected to internet.