Seperate all methods logically, to increase modularity

This commit is contained in:
neslihanturan 2018-02-24 12:24:13 +03:00
parent 0df35beab2
commit 1dcf4fb461

View file

@ -48,7 +48,7 @@ import java.util.List;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.utils.UriDeserializer; import fr.free.nrw.commons.utils.UriDeserializer;
public class NearbyMapFragment extends android.support.v4.app.Fragment { public class NearbyMapFragment extends android.support.v4.app.Fragment{
private MapView mapView; private MapView mapView;
private List<NearbyBaseMarker> baseMarkerOptions; private List<NearbyBaseMarker> baseMarkerOptions;
@ -166,48 +166,62 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
public void updateMapSlightly() { public void updateMapSlightly() {
// Get arguments from bundle for new location // Get arguments from bundle for new location
Bundle bundle = this.getArguments(); Bundle bundle = this.getArguments();
Gson gson = new GsonBuilder() if (mapboxMap != null) {
.registerTypeAdapter(Uri.class, new UriDeserializer()) Gson gson = new GsonBuilder()
.create(); .registerTypeAdapter(Uri.class, new UriDeserializer())
if (bundle != null) { .create();
String gsonLatLng = bundle.getString("CurLatLng"); if (bundle != null) {
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType(); String gsonLatLng = bundle.getString("CurLatLng");
curLatLng = gson.fromJson(gsonLatLng, curLatLngType); Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
}
updateMapToTrackPosition();
} }
updateMapToTrackPosition();
} }
public void updateMapSignificantly() { public void updateMapSignificantly() {
Log.d("deneme", "oldu updateMapSignificantly");
Bundle bundle = this.getArguments(); Bundle bundle = this.getArguments();
Gson gson = new GsonBuilder() if (mapboxMap != null) {
.registerTypeAdapter(Uri.class, new UriDeserializer()) Log.d("deneme", "oldu1 updateMapSignificantly");
.create(); if (bundle != null) {
if (bundle != null) { Gson gson = new GsonBuilder()
String gsonPlaceList = bundle.getString("PlaceList"); .registerTypeAdapter(Uri.class, new UriDeserializer())
String gsonLatLng = bundle.getString("CurLatLng"); .create();
String gsonBoundaryCoordinates = bundle.getString("BoundaryCoord"); Log.d("deneme", "oldu2 updateMapSignificantly");
Type listType = new TypeToken<List<Place>>() {}.getType(); String gsonPlaceList = bundle.getString("PlaceList");
List<Place> placeList = gson.fromJson(gsonPlaceList, listType); String gsonLatLng = bundle.getString("CurLatLng");
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType(); String gsonBoundaryCoordinates = bundle.getString("BoundaryCoord");
Type gsonBoundaryCoordinatesType = new TypeToken<fr.free.nrw.commons.location.LatLng[]>() {}.getType(); Type listType = new TypeToken<List<Place>>() {}.getType();
curLatLng = gson.fromJson(gsonLatLng, curLatLngType); List<Place> placeList = gson.fromJson(gsonPlaceList, listType);
baseMarkerOptions = NearbyController Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, Type gsonBoundaryCoordinatesType = new TypeToken<fr.free.nrw.commons.location.LatLng[]>() {}.getType();
placeList, curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
getActivity()); baseMarkerOptions = NearbyController
boundaryCoordinates = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType); .loadAttractionsFromLocationToBaseMarkerOptions(curLatLng,
} placeList,
updateMapToTrackPosition(); getActivity());
//addNearbyMarkerstoMapBoxMap(); boundaryCoordinates = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType);
}
mapboxMap.clear();
addCurrentLocationMarker(mapboxMap);
updateMapToTrackPosition();
addNearbyMarkerstoMapBoxMap();
} /*else {
setupMapView(bundle);
}*/
//mapView.setStyleUrl("asset://mapstyle.json");
} }
// Only update current position marker and camera view // Only update current position marker and camera view
private void updateMapToTrackPosition() { private void updateMapToTrackPosition() {
// Change // Change
Log.d("deneme","updateMapToTrackPosition"); Log.d("deneme","updateMapToTrackPosition");
if (currentLocationMarker != null && mapboxMap != null) { if (currentLocationMarker != null) {
LatLng curMapBoxLatLng = new LatLng(curLatLng.getLatitude(),curLatLng.getLongitude()); LatLng curMapBoxLatLng = new LatLng(curLatLng.getLatitude(),curLatLng.getLongitude());
ValueAnimator markerAnimator = ObjectAnimator.ofObject(currentLocationMarker, "position", ValueAnimator markerAnimator = ObjectAnimator.ofObject(currentLocationMarker, "position",
new LatLngEvaluator(), currentLocationMarker.getPosition(), new LatLngEvaluator(), currentLocationMarker.getPosition(),
@ -342,34 +356,15 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
// create map // create map
mapView = new MapView(getActivity(), options); mapView = new MapView(getActivity(), options);
mapView.onCreate(savedInstanceState); mapView.onCreate(savedInstanceState);
/*mapView.getMapAsync(new OnMapReadyCallback() { mapView.getMapAsync(new OnMapReadyCallback() {
@Override @Override
public void onMapReady(MapboxMap mapboxMap) { public void onMapReady(MapboxMap mapboxMap) {
NearbyMapFragment.this.mapboxMap = mapboxMap; NearbyMapFragment.this.mapboxMap = mapboxMap;
NearbyMapFragment.this.mapboxMap.addMarkers(baseMarkerOptions); //addNearbyMarkerstoMapBoxMap();
updateMapSignificantly();
NearbyMapFragment.this.mapboxMap.setOnInfoWindowCloseListener(marker -> {
if (marker == selected){
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
});
NearbyMapFragment.this.mapboxMap.setOnMarkerClickListener(marker -> {
if (marker instanceof NearbyMarker) {
NearbyMapFragment.this.selected = marker;
NearbyMarker nearbyMarker = (NearbyMarker) marker;
Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
passInfoToSheet(place);
bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
return false;
});
addCurrentLocationMarker(NearbyMapFragment.this.mapboxMap);
} }
});*/ });
addNearbyMarkerstoMapBoxMap(); mapView.setStyleUrl("asset://mapstyle.json");
//addCurrentLocationMarker(mapboxMap);
} }
/** /**
@ -403,38 +398,28 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
} }
private void addNearbyMarkerstoMapBoxMap() { private void addNearbyMarkerstoMapBoxMap() {
mapView.getMapAsync(new OnMapReadyCallback() { Log.d("deneme", "oldu3");
@Override mapboxMap.addMarkers(baseMarkerOptions);
public void onMapReady(MapboxMap mapboxMap) {
mapboxMap.setOnInfoWindowCloseListener(marker -> {
if (marker == selected){
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
} }
}); });
mapView.getMapAsync(mapboxMap -> {
mapboxMap.addMarkers(baseMarkerOptions);
mapboxMap.setOnInfoWindowCloseListener(marker -> { mapboxMap.setOnMarkerClickListener(marker -> {
if (marker == selected){ if (marker instanceof NearbyMarker) {
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); this.selected = marker;
} NearbyMarker nearbyMarker = (NearbyMarker) marker;
}); Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
passInfoToSheet(place);
mapboxMap.setOnMarkerClickListener(marker -> { bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
if (marker instanceof NearbyMarker) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
this.selected = marker; }
NearbyMarker nearbyMarker = (NearbyMarker) marker; return false;
Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
passInfoToSheet(place);
bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
return false;
});
addCurrentLocationMarker(mapboxMap);
NearbyMapFragment.this.mapboxMap = mapboxMap;
}); });
mapView.setStyleUrl("asset://mapstyle.json"); // addCurrentLocationMarker(mapboxMap);
} }
@ -589,6 +574,9 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
public void onResume() { public void onResume() {
if (mapView != null) { if (mapView != null) {
mapView.onResume(); mapView.onResume();
if (mapboxMap!=null) {
mapboxMap.clear(); // To clear nearby markers from previous setup
}
} }
super.onResume(); super.onResume();
} }
@ -623,5 +611,6 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
return latLng; return latLng;
} }
} }
} }