Fixes #3260, handle null latlng when adding current location marker (#3261)

This commit is contained in:
Ashish Kumar 2019-12-03 13:14:31 +05:30 committed by Josephine Lim
parent 7b9e792efc
commit 452f799cb3

View file

@ -1,5 +1,7 @@
package fr.free.nrw.commons.nearby.fragments;
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
@ -7,11 +9,9 @@ import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
@ -26,13 +26,6 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.MapFragmentUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.inject.Inject;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
@ -48,10 +41,12 @@ import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
import fr.free.nrw.commons.utils.LocationUtils;
import fr.free.nrw.commons.utils.UiUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.inject.Inject;
import timber.log.Timber;
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
/**
* Support Fragment wrapper around a map view.
* <p>
@ -315,17 +310,21 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
*/
@Override
public void addCurrentLocationMarker(LatLng curLatLng) {
if (null != curLatLng) {
removeCurrentLocationMarker();
Timber.d("Adds current location marker");
Icon icon = IconFactory.getInstance(getContext()).fromResource(R.drawable.current_location_marker);
Icon icon = IconFactory.getInstance(getContext())
.fromResource(R.drawable.current_location_marker);
MarkerOptions currentLocationMarkerOptions = new MarkerOptions()
.position(new com.mapbox.mapboxsdk.geometry.LatLng(curLatLng.getLatitude(), curLatLng.getLongitude()));
.position(new com.mapbox.mapboxsdk.geometry.LatLng(curLatLng.getLatitude(),
curLatLng.getLongitude()));
currentLocationMarkerOptions.setIcon(icon); // Set custom icon
currentLocationMarker = mapboxMap.addMarker(currentLocationMarkerOptions);
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = UiUtils.createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = UiUtils
.createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
curLatLng.getAccuracy() * 2, 100);
PolygonOptions currentLocationPolygonOptions = new PolygonOptions()
@ -333,6 +332,9 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
.strokeColor(getResources().getColor(R.color.current_marker_stroke))
.fillColor(getResources().getColor(R.color.current_marker_fill));
currentLocationPolygon = mapboxMap.addPolygon(currentLocationPolygonOptions);
} else {
Timber.d("not adding current location marker..current location is null");
}
}
@Override