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

fix: Added network change register #96

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>