Codacy fixes

This commit is contained in:
maskara 2017-04-02 22:34:42 +05:30
parent 2e063a3dcf
commit c14e2566f5
7 changed files with 58 additions and 27 deletions

View file

@ -5,6 +5,11 @@ public class LatLng {
public final double latitude;
public final double longitude;
/**
* Accepts latitude and longitude
* @param latitude
* @param longitude
*/
public LatLng(double latitude, double longitude) {
if(-180.0D <= longitude && longitude < 180.0D) {
this.longitude = longitude;

View file

@ -12,7 +12,7 @@ public class LocationServiceManager implements LocationListener {
public static final String TAG = "LocationServiceManager";
private String provider;
private LocationManager locationManager;
private LatLng mLatestLocation;
private LatLng latestLocation;
public LocationServiceManager(Context context) {
this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
@ -20,17 +20,17 @@ public class LocationServiceManager implements LocationListener {
}
public LatLng getLatestLocation() {
return mLatestLocation;
return latestLocation;
}
/**
* Registers a LocationManager to listen for current location
/** Registers a LocationManager to listen for current location
*/
public void registerLocationManager() {
try {
locationManager.requestLocationUpdates(provider, 400, 1, this);
Location location = locationManager.getLastKnownLocation(provider);
//Location works, just need to 'send' GPS coords via emulator extended controls if testing on emulator
//Location works, just need to 'send' GPS coords
// via emulator extended controls if testing on emulator
Log.d(TAG, "Checking for location...");
if (location != null) {
this.onLocationChanged(location);
@ -42,6 +42,8 @@ public class LocationServiceManager implements LocationListener {
}
}
/** Unregisters location manager
*/
public void unregisterLocationManager() {
try {
locationManager.removeUpdates(this);
@ -54,9 +56,10 @@ public class LocationServiceManager implements LocationListener {
public void onLocationChanged(Location location) {
double currentLatitude = location.getLatitude();
double currentLongitude = location.getLongitude();
Log.d(TAG, "Latitude: " + String.valueOf(currentLatitude) + " Longitude: " + String.valueOf(currentLongitude));
Log.d(TAG, "Latitude: " + String.valueOf(currentLatitude)
+ " Longitude: " + String.valueOf(currentLongitude));
mLatestLocation = new LatLng(currentLatitude, currentLongitude);
latestLocation = new LatLng(currentLatitude, currentLongitude);
}
@Override

View file

@ -12,12 +12,20 @@ import java.util.List;
import fr.free.nrw.commons.R;
public class NearbyAdapter extends ArrayAdapter<Place> {
public List<Place> placesList;
private Context mContext;
private List<Place> placesList;
private Context context;
public List<Place> getPlacesList() {
return placesList;
}
/** Accepts activity context and list of places
* @param context
* @param places
*/
public NearbyAdapter(Context context, List<Place> places) {
super(context, R.layout.item_place, places);
this.mContext = context;
this.context = context;
placesList = places;
}
@ -29,11 +37,12 @@ public class NearbyAdapter extends ArrayAdapter<Place> {
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_place, parent, false);
convertView = LayoutInflater.from(getContext())
.inflate(R.layout.item_place, parent, false);
}
NearbyViewHolder viewHolder = new NearbyViewHolder(convertView);
viewHolder.bindModel(mContext, place);
viewHolder.bindModel(context, place);
// Return the completed view to render on screen
return convertView;
}

View file

@ -12,10 +12,6 @@ import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ProgressBar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnItemClick;
@ -26,6 +22,10 @@ import fr.free.nrw.commons.location.LocationServiceManager;
import static fr.free.nrw.commons.utils.LengthUtils.computeDistanceBetween;
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class NearbyListFragment extends ListFragment implements TaskListener {
private NearbyAsyncTask nearbyAsyncTask;
@ -166,14 +166,18 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
}
}
@OnItemClick(R.id.listview) void onItemClicked(int position) {
@OnItemClick(R.id.listview)
void onItemClicked(int position) {
Place place = places.get(position);
LatLng placeLatLng = place.location;
double latitude = placeLatLng.latitude;
double longitude = placeLatLng.longitude;
Log.d(TAG, "Item at position " + position + " has coords: Lat: " + latitude + " Long: " + longitude);
Log.d(TAG, "Item at position "
+ position + " has coords: Lat: "
+ latitude + " Long: "
+ longitude);
//Open map app at given position
Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + latitude + "," + longitude);

View file

@ -3,6 +3,8 @@ package fr.free.nrw.commons.nearby;
import android.os.StrictMode;
import android.util.Log;
import fr.free.nrw.commons.location.LatLng;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -10,7 +12,6 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import fr.free.nrw.commons.location.LatLng;
public class NearbyPlaces {

View file

@ -1,10 +1,15 @@
package fr.free.nrw.commons.utils;
import java.text.NumberFormat;
import fr.free.nrw.commons.location.LatLng;
import java.text.NumberFormat;
public class LengthUtils {
/** Returns a formatted distance string between two points
* @param point1
* @param point2
* @return
*/
public static String formatDistanceBetween(LatLng point1, LatLng point2) {
if (point1 == null || point2 == null) {
return null;
@ -27,7 +32,10 @@ public class LengthUtils {
}
private static double computeAngleBetween(LatLng from, LatLng to) {
return distanceRadians(Math.toRadians(from.latitude), Math.toRadians(from.longitude), Math.toRadians(to.latitude), Math.toRadians(to.longitude));
return distanceRadians(Math.toRadians(from.latitude),
Math.toRadians(from.longitude),
Math.toRadians(to.latitude),
Math.toRadians(to.longitude));
}
private static double distanceRadians(double lat1, double lng1, double lat2, double lng2) {
@ -38,8 +46,8 @@ public class LengthUtils {
return 2.0D * Math.asin(Math.sqrt(x));
}
private static double havDistance(double lat1, double lat2, double dLng) {
return hav(lat1 - lat2) + hav(dLng) * Math.cos(lat1) * Math.cos(lat2);
private static double havDistance(double lat1, double lat2, double longitude) {
return hav(lat1 - lat2) + hav(longitude) * Math.cos(lat1) * Math.cos(lat2);
}
private static double hav(double x) {

View file

@ -8,15 +8,16 @@ public class ResourceUtils {
/**
* See https://github.com/commons-app/apps-android-commons/issues/250
* Most common types of desc: building, house, cottage, farmhouse, village, civil parish, church, railway station,
* Most common types of desc: building, house, cottage, farmhouse,
* village, civil parish, church, railway station,
* gatehouse, milestone, inn, secondary school, hotel
* @param description Place description
* @return
* @return icon res id
*/
@DrawableRes
public static int getDescriptionIcon(String description) {
int resourceId;
switch(description) {
switch (description) {
case "building":
resourceId = R.drawable.round_icon_generic_building;
break;