Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/NearbyStopsFragment.java
Show First 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | public Loader<Cursor> onCreateLoader(int id, Bundle args) { | ||||
.appendPath(String.valueOf(distance)); //distance | .appendPath(String.valueOf(distance)); //distance | ||||
CursorLoader cl = new CursorLoader(getContext(),builder.build(),PROJECTION,null,null,null); | CursorLoader cl = new CursorLoader(getContext(),builder.build(),PROJECTION,null,null,null); | ||||
cl.setUpdateThrottle(2000); | cl.setUpdateThrottle(2000); | ||||
return cl; | return cl; | ||||
} | } | ||||
@Override | @Override | ||||
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) { | public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) { | ||||
if (0 > MAX_DISTANCE) throw new AssertionError(); | if (0 > MAX_DISTANCE) throw new AssertionError(); | ||||
//Cursor might be null | //Cursor might be null | ||||
Log.d(DEBUG_TAG, "Num stops found: "+data.getCount()+", Current distance: "+distance); | if(cursor==null){ | ||||
if(data==null){ | |||||
Log.e(DEBUG_TAG,"Null cursor, something really wrong happened"); | Log.e(DEBUG_TAG,"Null cursor, something really wrong happened"); | ||||
return; | return; | ||||
} | } | ||||
if(!isDBUpdating() && (data.getCount()<MIN_NUM_STOPS && distance<=MAX_DISTANCE)){ | Log.d(DEBUG_TAG, "Num stops found: "+cursor.getCount()+", Current distance: "+distance); | ||||
if(!isDBUpdating() && (cursor.getCount()<MIN_NUM_STOPS && distance<=MAX_DISTANCE)){ | |||||
distance = distance*2; | distance = distance*2; | ||||
Bundle d = new Bundle(); | Bundle d = new Bundle(); | ||||
d.putParcelable(BUNDLE_LOCATION,lastReceivedLocation); | d.putParcelable(BUNDLE_LOCATION,lastReceivedLocation); | ||||
getLoaderManager().restartLoader(LOADER_ID,d,this); | getLoaderManager().restartLoader(LOADER_ID,d,this); | ||||
//Log.d(DEBUG_TAG, "Doubling distance now!"); | //Log.d(DEBUG_TAG, "Doubling distance now!"); | ||||
return; | return; | ||||
} | } | ||||
Log.d("LoadFromCursor","Number of nearby stops: "+data.getCount()); | Log.d("LoadFromCursor","Number of nearby stops: "+cursor.getCount()); | ||||
//////// | //////// | ||||
if(data.getCount()>0) { | if(cursor.getCount()>0) { | ||||
ArrayList<Stop> stopList = createStopListFromCursor(data); | ArrayList<Stop> stopList = createStopListFromCursor(cursor); | ||||
double minDistance = Double.POSITIVE_INFINITY; | double minDistance = Double.POSITIVE_INFINITY; | ||||
for(Stop s: stopList){ | for(Stop s: stopList){ | ||||
minDistance = Math.min(minDistance, s.getDistanceFromLocation(lastReceivedLocation)); | minDistance = Math.min(minDistance, s.getDistanceFromLocation(lastReceivedLocation)); | ||||
} | } | ||||
//quick trial to hopefully always get the stops in the correct order | //quick trial to hopefully always get the stops in the correct order | ||||
Collections.sort(stopList,new StopSorterByDistance(lastReceivedLocation)); | Collections.sort(stopList,new StopSorterByDistance(lastReceivedLocation)); | ||||
▲ Show 20 Lines • Show All 345 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register