Use ui thread for adapter updates

This commit is contained in:
Alex 2017-10-11 14:32:54 +03:00
parent 5ea8df4b7e
commit fc3c3f45ef

View file

@ -353,7 +353,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
public void updateLocation(Location loc) { public void updateLocation(Location loc) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { 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 newLocation = (this.location == null && location != null) || location == null;
boolean locationChanged = this.location != null && location != null boolean locationChanged = this.location != null && location != null
&& this.location.getLatitude() != location.getLatitude() && 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(), boolean farEnough = locationChanged && MapUtils.getDistance(this.location.getLatitude(), this.location.getLongitude(),
location.getLatitude(), location.getLongitude()) >= MIN_DISTANCE_FOR_RECALCULATE; location.getLatitude(), location.getLongitude()) >= MIN_DISTANCE_FOR_RECALCULATE;
if (newLocation || farEnough) { if (newLocation || farEnough) {
this.location = location; mapActivity.getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
PlanRouteFragment.this.location = location;
adapter.reloadData(); adapter.reloadData();
try { try {
adapter.notifyDataSetChanged(); 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 // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
} }
} }
});
}
} }
} }