Do not update compass when scrolling or drag and drop

This commit is contained in:
Alexander Sytnyk 2017-09-25 11:50:36 +03:00
parent fe195a238d
commit ab59a8cc2c

View file

@ -18,7 +18,6 @@ import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
@ -33,6 +32,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
private Location location; private Location location;
private Float heading; private Float heading;
private boolean locationUpdateStarted; private boolean locationUpdateStarted;
private boolean compassUpdateAllowed = true;
@Nullable @Nullable
@Override @Override
@ -64,12 +64,14 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
@Override @Override
public void onDragStarted(RecyclerView.ViewHolder holder) { public void onDragStarted(RecyclerView.ViewHolder holder) {
compassUpdateAllowed = false;
fromPosition = holder.getAdapterPosition(); fromPosition = holder.getAdapterPosition();
touchHelper.startDrag(holder); touchHelper.startDrag(holder);
} }
@Override @Override
public void onDragEnded(RecyclerView.ViewHolder holder) { public void onDragEnded(RecyclerView.ViewHolder holder) {
compassUpdateAllowed = true;
toPosition = holder.getAdapterPosition(); toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
hideSnackbar(); hideSnackbar();
@ -79,7 +81,13 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
} }
}); });
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
}
});
return recyclerView; return recyclerView;
} }
@ -147,6 +155,9 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
} }
private void updateLocationUi() { private void updateLocationUi() {
if (!compassUpdateAllowed) {
return;
}
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null && adapter != null) { if (mapActivity != null && adapter != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() { mapActivity.getMyApplication().runInUIThread(new Runnable() {