Hot fix bundle issue (#1425)

* Fixed bug #1399

* Changed visibility from visible to gone

* Changed behaviour according to review

* Changed bottom sheet visibility from visible to gone

* Fix adding bundle to an already created fragment
This commit is contained in:
neslihanturan 2018-04-08 12:17:20 +03:00 committed by Josephine Lim
parent 3949dbca5c
commit 802b2a8df4
3 changed files with 25 additions and 17 deletions

View file

@ -474,17 +474,17 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::populatePlaces);
nearbyMapFragment.setArguments(bundle);
nearbyMapFragment.setBundleForUpdtes(bundle);
nearbyMapFragment.updateMapSignificantly();
updateListFragment();
return;
}
if (isSlightUpdate) {
nearbyMapFragment.setArguments(bundle);
nearbyMapFragment.setBundleForUpdtes(bundle);
nearbyMapFragment.updateMapSlightly();
} else {
nearbyMapFragment.setArguments(bundle);
nearbyMapFragment.setBundleForUpdtes(bundle);
nearbyMapFragment.updateMapSignificantly();
updateListFragment();
}
@ -498,7 +498,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
}
private void updateListFragment() {
nearbyListFragment.setArguments(bundle);
nearbyListFragment.setBundleForUpdates(bundle);
nearbyListFragment.updateNearbyListSignificantly();
}

View file

@ -33,6 +33,8 @@ import static android.app.Activity.RESULT_OK;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
public class NearbyListFragment extends DaggerFragment {
private Bundle bundleForUpdates; // Carry information from activity about changed nearby places and current location
private static final Type LIST_TYPE = new TypeToken<List<Place>>() {
}.getType();
private static final Type CUR_LAT_LNG_TYPE = new TypeToken<LatLng>() {
@ -80,8 +82,7 @@ public class NearbyListFragment extends DaggerFragment {
}
public void updateNearbyListSignificantly() {
Bundle bundle = this.getArguments();
adapterFactory.updateAdapterData(getPlaceListFromBundle(bundle),
adapterFactory.updateAdapterData(getPlaceListFromBundle(bundleForUpdates),
(RVRendererAdapter<Place>) recyclerView.getAdapter());
}
@ -140,4 +141,8 @@ public class NearbyListFragment extends DaggerFragment {
}
}
public void setBundleForUpdates(Bundle bundleForUpdates) {
this.bundleForUpdates = bundleForUpdates;
}
}

View file

@ -110,6 +110,8 @@ public class NearbyMapFragment extends DaggerFragment {
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06;
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04;
private Bundle bundleForUpdtes;// Carry information from activity about changed nearby places and current location
@Inject
@Named("prefs")
SharedPreferences prefs;
@ -191,14 +193,12 @@ public class NearbyMapFragment extends DaggerFragment {
}
public void updateMapSlightly() {
// Get arguments from bundle for new location
Bundle bundle = this.getArguments();
if (mapboxMap != null) {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriDeserializer())
.create();
if (bundle != null) {
String gsonLatLng = bundle.getString("CurLatLng");
if (bundleForUpdtes != null) {
String gsonLatLng = bundleForUpdtes.getString("CurLatLng");
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
}
@ -208,17 +208,15 @@ public class NearbyMapFragment extends DaggerFragment {
}
public void updateMapSignificantly() {
Bundle bundle = this.getArguments();
if (mapboxMap != null) {
if (bundle != null) {
if (bundleForUpdtes != null) {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriDeserializer())
.create();
String gsonPlaceList = bundle.getString("PlaceList");
String gsonLatLng = bundle.getString("CurLatLng");
String gsonBoundaryCoordinates = bundle.getString("BoundaryCoord");
String gsonPlaceList = bundleForUpdtes.getString("PlaceList");
String gsonLatLng = bundleForUpdtes.getString("CurLatLng");
String gsonBoundaryCoordinates = bundleForUpdtes.getString("BoundaryCoord");
Type listType = new TypeToken<List<Place>>() {}.getType();
List<Place> placeList = gson.fromJson(gsonPlaceList, listType);
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
@ -773,7 +771,7 @@ public class NearbyMapFragment extends DaggerFragment {
}
}
private void closeFabs ( boolean isFabOpen){
private void closeFabs ( boolean isFabOpen){
if (isFabOpen) {
fabPlus.startAnimation(rotate_backward);
fabCamera.startAnimation(fab_close);
@ -784,6 +782,11 @@ public class NearbyMapFragment extends DaggerFragment {
}
}
public void setBundleForUpdtes(Bundle bundleForUpdtes) {
this.bundleForUpdtes = bundleForUpdtes;
}
@Override
public void onStart() {
if (mapView != null) {