Prevent crash caused child fragment is actually null by checking if it is attached or not.

This commit is contained in:
neslihanturan 2019-05-21 14:30:42 +03:00
parent d0556419f7
commit f4321d0541
2 changed files with 15 additions and 0 deletions

View file

@ -1,5 +1,6 @@
package fr.free.nrw.commons.nearby.mvp.fragments;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
@ -104,6 +105,12 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
((NearbyParentFragment)getParentFragment()).childMapFragmentAttached();
}
@Override
public MapView setupMapView(Bundle savedInstanceState) {
return null;

View file

@ -110,6 +110,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
public void onResume() {
super.onResume();
resumeFragment();
}
/**
* Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can
* prevent NPE caused by null child fragment. This method is called from child fragment when
* it is attached.
*/
public void childMapFragmentAttached() {
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter(this, nearbyMapFragment);
}