mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
NetworkBroadcastReceiver is unregistered in onPause() and not reregistered in onResume(). This causes the snackbar doesn't disappear after network becomes available. Fixed this and improved the null checking logic in snackbar related code.
This commit is contained in:
parent
5c4278bbff
commit
bb40c24de8
1 changed files with 15 additions and 8 deletions
|
|
@ -152,6 +152,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
|||
// Find the retained fragment on activity restarts
|
||||
nearbyMapFragment = getMapFragment();
|
||||
nearbyListFragment = getListFragment();
|
||||
addNetworkBroadcastReceiver();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -711,21 +712,32 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
|||
if (!FragmentUtils.isFragmentUIActive(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (broadcastReceiver != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter(NETWORK_INTENT_ACTION);
|
||||
snackbar = Snackbar.make(transparentView, R.string.no_internet, Snackbar.LENGTH_INDEFINITE);
|
||||
|
||||
broadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (snackbar != null && getActivity() != null) {
|
||||
if (getActivity() != null) {
|
||||
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
|
||||
if (isNetworkErrorOccured) {
|
||||
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
|
||||
isNetworkErrorOccured = false;
|
||||
}
|
||||
snackbar.dismiss();
|
||||
|
||||
if (snackbar != null) {
|
||||
snackbar.dismiss();
|
||||
snackbar = null;
|
||||
}
|
||||
} else {
|
||||
if (snackbar == null) {
|
||||
snackbar = Snackbar.make(view, R.string.no_internet, Snackbar.LENGTH_INDEFINITE);
|
||||
}
|
||||
|
||||
isNetworkErrorOccured = true;
|
||||
snackbar.show();
|
||||
}
|
||||
|
|
@ -733,12 +745,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
};
|
||||
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
getActivity().registerReceiver(broadcastReceiver, intentFilter);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue