Use ui thread for adapter updates
This commit is contained in:
parent
5ea8df4b7e
commit
fc3c3f45ef
1 changed files with 14 additions and 9 deletions
|
@ -353,7 +353,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
|
|||
public void updateLocation(Location loc) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
Location location = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
|
||||
final Location location = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
|
||||
boolean newLocation = (this.location == null && location != null) || location == null;
|
||||
boolean locationChanged = this.location != null && location != null
|
||||
&& this.location.getLatitude() != location.getLatitude()
|
||||
|
@ -361,7 +361,10 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
|
|||
boolean farEnough = locationChanged && MapUtils.getDistance(this.location.getLatitude(), this.location.getLongitude(),
|
||||
location.getLatitude(), location.getLongitude()) >= MIN_DISTANCE_FOR_RECALCULATE;
|
||||
if (newLocation || farEnough) {
|
||||
this.location = location;
|
||||
mapActivity.getMyApplication().runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlanRouteFragment.this.location = location;
|
||||
adapter.reloadData();
|
||||
try {
|
||||
adapter.notifyDataSetChanged();
|
||||
|
@ -370,6 +373,8 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
|
|||
// java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue