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

Commit

Permalink
fix: Added network change register
Browse files Browse the repository at this point in the history
reformatted code

reformatted code
  • Loading branch information
anubhav11march committed Mar 22, 2020
1 parent 2af08b0 commit d9f333d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@
<action android:name="org.apache.fineract.JobsReceiver" />
</intent-filter>
</receiver>

<receiver android:name=".utils.NetworkChangeReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -74,6 +76,8 @@ protected void onCreate(Bundle savedInstanceState) {
StartSyncJob.scheduleItNow();
preferencesHelper.setFetching(false);
}

registerNetworkRegister();
}

public void setupNavigationBar() {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,5 @@
<string name="email">Email</string>
<string name="logged_out_successfully">Logged out successfully.</string>
<string name="please_click_back_again_to_exit">Please click BACK again to exit</string>
<string name="toast_internet_offline">You are offline as you are not connected to internet.</string>
</resources>

0 comments on commit d9f333d

Please sign in to comment.