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) {
|
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,14 +361,19 @@ 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() {
|
||||||
adapter.reloadData();
|
@Override
|
||||||
try {
|
public void run() {
|
||||||
adapter.notifyDataSetChanged();
|
PlanRouteFragment.this.location = location;
|
||||||
} catch (Exception e) {
|
adapter.reloadData();
|
||||||
// to avoid crash because of:
|
try {
|
||||||
// java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
|
adapter.notifyDataSetChanged();
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
// to avoid crash because of:
|
||||||
|
// java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue