Check sorted list - location not working

This commit is contained in:
misaochan 2016-08-26 18:31:48 +12:00
parent 01a104f029
commit 2cdc07c601
2 changed files with 8 additions and 3 deletions

View file

@ -31,8 +31,6 @@ public class NearbyActivity extends AppCompatActivity {
setContentView(R.layout.activity_nearby);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
registerLocationManager();
// Begin the transaction
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
NearbyListFragment fragment = new NearbyListFragment();
@ -70,6 +68,7 @@ public class NearbyActivity extends AppCompatActivity {
try {
locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener);
Location location = locationManager.getLastKnownLocation(provider);
Log.d(TAG, "Checking for location...");
if (location != null) {
myLocationListener.onLocationChanged(location);
}

View file

@ -61,11 +61,12 @@ public class NearbyListFragment extends ListFragment {
return view;
}
//TODO: Do asynchronously?
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
//Load from data source (NearbyPlaces.java)
//TODO: Do asynchronously?
//FIXME: mLatestLocation not set. Hardcode it first for testing
places = loadAttractionsFromLocation(mLatestLocation);
final ListView listview = (ListView) view.findViewById(R.id.listview);
@ -81,6 +82,7 @@ public class NearbyListFragment extends ListFragment {
List<Place> places = NearbyPlaces.get();
if (curLatLng != null) {
Log.d(TAG, "Sorting places by distance...");
Collections.sort(places,
new Comparator<Place>() {
@Override
@ -94,6 +96,10 @@ public class NearbyListFragment extends ListFragment {
}
);
}
//FIXME: This doesn't sort appropriately
for(int i = 0; i < places.size(); i++) {
System.out.println("Sorted " + places.get(i).name);
}
return places;
}