diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 53ac0c78e4..e8263c6cb9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -28,6 +28,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL private MapMarkersActiveAdapter adapter; private Location location; private Float heading; + private boolean locationUpdateStarted; @Nullable @Override @@ -119,9 +120,10 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL } } - private void startLocationUpdate() { + void startLocationUpdate() { OsmandApplication app = getMyApplication(); - if (app != null) { + if (app != null && !locationUpdateStarted) { + locationUpdateStarted = true; app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo()); app.getLocationProvider().addCompassListener(this); app.getLocationProvider().addLocationListener(this); @@ -129,9 +131,10 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL } } - private void stopLocationUpdate() { + void stopLocationUpdate() { OsmandApplication app = getMyApplication(); - if (app != null) { + if (app != null && locationUpdateStarted) { + locationUpdateStarted = false; app.getLocationProvider().removeLocationListener(this); app.getLocationProvider().removeCompassListener(this); app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 90109cbeb8..4b689e261b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -58,7 +58,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm final LockableViewPager viewPager = mainView.findViewById(R.id.map_markers_view_pager); viewPager.setSwipeLocked(true); - viewPager.setAdapter(new MapMarkersViewPagerAdapter(getChildFragmentManager())); + final MapMarkersViewPagerAdapter adapter = new MapMarkersViewPagerAdapter(getChildFragmentManager()); + viewPager.setAdapter(adapter); BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation); bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -66,9 +67,11 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_active: + ((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate(); viewPager.setCurrentItem(0); return true; case R.id.action_history: + ((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate(); viewPager.setCurrentItem(1); return true; }