Improve some stuff
This commit is contained in:
parent
ee4c1e6cb4
commit
1fa4d3c835
2 changed files with 11 additions and 5 deletions
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue