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 MapMarkersActiveAdapter adapter;
|
||||||
private Location location;
|
private Location location;
|
||||||
private Float heading;
|
private Float heading;
|
||||||
|
private boolean locationUpdateStarted;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,9 +120,10 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startLocationUpdate() {
|
void startLocationUpdate() {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
if (app != null) {
|
if (app != null && !locationUpdateStarted) {
|
||||||
|
locationUpdateStarted = true;
|
||||||
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
|
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||||
app.getLocationProvider().addCompassListener(this);
|
app.getLocationProvider().addCompassListener(this);
|
||||||
app.getLocationProvider().addLocationListener(this);
|
app.getLocationProvider().addLocationListener(this);
|
||||||
|
@ -129,9 +131,10 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopLocationUpdate() {
|
void stopLocationUpdate() {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
if (app != null) {
|
if (app != null && locationUpdateStarted) {
|
||||||
|
locationUpdateStarted = false;
|
||||||
app.getLocationProvider().removeLocationListener(this);
|
app.getLocationProvider().removeLocationListener(this);
|
||||||
app.getLocationProvider().removeCompassListener(this);
|
app.getLocationProvider().removeCompassListener(this);
|
||||||
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
|
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);
|
final LockableViewPager viewPager = mainView.findViewById(R.id.map_markers_view_pager);
|
||||||
viewPager.setSwipeLocked(true);
|
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);
|
BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation);
|
||||||
bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||||
|
@ -66,9 +67,11 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
||||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case R.id.action_active:
|
case R.id.action_active:
|
||||||
|
((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate();
|
||||||
viewPager.setCurrentItem(0);
|
viewPager.setCurrentItem(0);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_history:
|
case R.id.action_history:
|
||||||
|
((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate();
|
||||||
viewPager.setCurrentItem(1);
|
viewPager.setCurrentItem(1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue