From 6cd53e5510e20dae29a1385c9a0f1bb23795490d Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 27 Jan 2020 15:21:36 +0200 Subject: [PATCH 1/3] Fix #8079 - ask permission request for location after adding destination --- .../FavouritesBottomSheetMenuFragment.java | 12 +- .../AddPointBottomSheetDialog.java | 14 ++- .../MapRouteInfoMenu.java | 103 +++++++----------- .../cards/HomeWorkCard.java | 75 ++++++------- 4 files changed, 99 insertions(+), 105 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java index f3ab61ad47..d63da7e1a0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java @@ -1,9 +1,11 @@ package net.osmand.plus.mapcontextmenu.other; +import android.Manifest; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -156,7 +158,15 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag targetPointsHelper.setStartPoint(ll, true, point.getPointDescription(app)); break; case TARGET: - targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription(app)); + if (OsmAndLocationProvider.isLocationPermissionAvailable(getContext())) { + targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription(app)); + } else { + if (getActivity() != null) { + ActivityCompat.requestPermissions(getActivity(), + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); + } + } break; case INTERMEDIATE: targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription(app)); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 94b4dfb0df..6be5c889ab 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -428,7 +428,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { menu.selectMapMarker((MapMarker) item, pointType); dismiss(); } else { - TargetPointsHelper helper = mapActivity.getMyApplication().getTargetPointsHelper(); + TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper(); Pair pair = getLocationAndDescrFromItem(item); LatLon ll = pair.first; PointDescription name = pair.second; @@ -442,13 +442,19 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { FavouritesDbHelper favorites = requiredMyApplication().getFavorites(); switch (pointType) { case START: - helper.setStartPoint(ll, true, name); + targetPointsHelper.setStartPoint(ll, true, name); break; case TARGET: - helper.navigateToPoint(ll, true, -1, name); + if (OsmAndLocationProvider.isLocationPermissionAvailable(getContext())) { + targetPointsHelper.navigateToPoint(ll, true, -1, name); + } else { + ActivityCompat.requestPermissions(mapActivity, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); + } break; case INTERMEDIATE: - helper.navigateToPoint(ll, true, helper.getIntermediatePoints().size(), name); + targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), name); break; case HOME: favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.HOME, null); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 9e486bbb47..5bfbc5e44d 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -1,6 +1,7 @@ package net.osmand.plus.routepreparationmenu; +import android.Manifest; import android.content.Context; import android.content.DialogInterface.OnDismissListener; import android.graphics.PointF; @@ -18,6 +19,7 @@ import android.support.transition.Scene; import android.support.transition.Transition; import android.support.transition.TransitionListenerAdapter; import android.support.transition.TransitionManager; +import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatImageView; @@ -258,29 +260,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - OsmandApplication app = mapActivity.getMyApplication(); if (selectFromMapTouch) { - LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y); selectFromMapTouch = false; - TargetPointsHelper targets = app.getTargetPointsHelper(); - FavouritesDbHelper favorites = app.getFavorites(); - switch (selectFromMapPointType) { - case START: - targets.setStartPoint(latlon, true, null); - break; - case TARGET: - targets.navigateToPoint(latlon, true, -1); - break; - case INTERMEDIATE: - targets.navigateToPoint(latlon, true, targets.getIntermediatePoints().size()); - break; - case HOME: - favorites.setSpecialPoint(latlon, FavouritePoint.SpecialPointType.HOME, null); - break; - case WORK: - favorites.setSpecialPoint(latlon, FavouritePoint.SpecialPointType.WORK, null); - break; - } + LatLon latLon = tileBox.getLatLonFromPixel(point.x, point.y); + choicePointTypeAction(mapActivity, latLon, selectFromMapPointType, null, null); if (selectFromMapWaypoints) { WaypointsFragment.showInstance(mapActivity.getSupportFragmentManager(), true); } else { @@ -292,6 +275,35 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener return false; } + private void choicePointTypeAction(MapActivity mapActivity, LatLon latLon, PointType pointType, PointDescription pd, String address) { + OsmandApplication app = getApp(); + FavouritesDbHelper favorites = app.getFavorites(); + TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper(); + switch (pointType) { + case START: + targetPointsHelper.setStartPoint(latLon, true, pd); + break; + case TARGET: + if (OsmAndLocationProvider.isLocationPermissionAvailable(app)) { + targetPointsHelper.navigateToPoint(latLon, true, -1, pd); + } else { + ActivityCompat.requestPermissions(mapActivity, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); + } + break; + case INTERMEDIATE: + targetPointsHelper.navigateToPoint(latLon, true, targetPointsHelper.getIntermediatePoints().size(), pd); + break; + case HOME: + favorites.setSpecialPoint(latLon, FavouritePoint.SpecialPointType.HOME, address); + break; + case WORK: + favorites.setSpecialPoint(latLon, FavouritePoint.SpecialPointType.WORK, address); + break; + } + } + public OnMarkerSelectListener getOnMarkerSelectListener() { return onMarkerSelectListener; } @@ -1785,29 +1797,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener hide(); } - public void selectAddress(@Nullable String name, @NonNull LatLon l, PointType pointType) { + public void selectAddress(@Nullable String name, @NonNull LatLon latLon, PointType pointType) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, name); - FavouritesDbHelper favorites = mapActivity.getMyApplication().getFavorites(); - TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper(); - switch (pointType) { - case START: - targets.setStartPoint(l, true, pd); - break; - case TARGET: - targets.navigateToPoint(l, true, -1, pd); - break; - case INTERMEDIATE: - targets.navigateToPoint(l, true, targets.getIntermediatePoints().size(), pd); - break; - case HOME: - favorites.setSpecialPoint(l, FavouritePoint.SpecialPointType.HOME, name); - break; - case WORK: - favorites.setSpecialPoint(l, FavouritePoint.SpecialPointType.WORK, name); - break; - } + choicePointTypeAction(mapActivity, latLon, pointType, pd, name); updateMenu(); } } @@ -1844,30 +1838,13 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } } - public void selectMapMarker(@Nullable final MapMarker m, @NonNull final PointType pointType) { + public void selectMapMarker(@Nullable final MapMarker marker, @NonNull final PointType pointType) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - if (m != null) { - LatLon point = new LatLon(m.getLatitude(), m.getLongitude()); - FavouritesDbHelper favorites = mapActivity.getMyApplication().getFavorites(); - TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper(); - switch (pointType) { - case START: - targets.setStartPoint(point, true, m.getPointDescription(mapActivity)); - break; - case TARGET: - targets.navigateToPoint(point, true, -1, m.getPointDescription(mapActivity)); - break; - case INTERMEDIATE: - targets.navigateToPoint(point, true, targets.getIntermediatePoints().size(), m.getPointDescription(mapActivity)); - break; - case HOME: - favorites.setSpecialPoint(point, FavouritePoint.SpecialPointType.HOME, null); - break; - case WORK: - favorites.setSpecialPoint(point, FavouritePoint.SpecialPointType.WORK, null); - break; - } + if (marker != null) { + LatLon latLon = new LatLon(marker.getLatitude(), marker.getLongitude()); + PointDescription pd = marker.getPointDescription(mapActivity); + choicePointTypeAction(mapActivity, latLon, pointType, pd, null); updateMenu(); } else { MapMarkerSelectionFragment selectionFragment = MapMarkerSelectionFragment.newInstance(pointType); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java index da4dd2f1c6..3e7062377f 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java @@ -1,13 +1,15 @@ package net.osmand.plus.routepreparationmenu.cards; +import android.Manifest; +import android.support.v4.app.ActivityCompat; import android.view.View; import android.widget.TextView; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.R; -import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routepreparationmenu.AddPointBottomSheetDialog; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType; @@ -25,54 +27,53 @@ public class HomeWorkCard extends BaseCard { @Override protected void updateContent() { - final TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper(); final FavouritesDbHelper favorites = getMyApplication().getFavorites(); final FavouritePoint homePoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.HOME); final FavouritePoint workPoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.WORK); - - TextView homeDescr = view.findViewById(R.id.home_button_descr); + final TextView homeDescr = view.findViewById(R.id.home_button_descr); final TextView workDescr = view.findViewById(R.id.work_button_descr); homeDescr.setText(homePoint != null ? homePoint.getAddress() : mapActivity.getString(R.string.shared_string_add)); workDescr.setText(workPoint != null ? workPoint.getAddress() : mapActivity.getString(R.string.shared_string_add)); + setSpecialButtonOnClickListeners(homePoint, R.id.home_button, PointType.HOME); + setSpecialButtonOnClickListeners(workPoint, R.id.work_button, PointType.WORK); + } - View homeButton = view.findViewById(R.id.home_button); - homeButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (homePoint == null) { - AddPointBottomSheetDialog.showInstance(mapActivity, PointType.HOME); - } else { - targetPointsHelper.navigateToPoint(new LatLon(homePoint.getLatitude(), homePoint.getLongitude()), - true, -1, homePoint.getPointDescription(mapActivity)); - } - } - }); + private void setSpecialButtonOnClickListeners(FavouritePoint point, int buttonId, final PointType pointType) { + View homeButton = view.findViewById(buttonId); + homeButton.setOnClickListener(new SpecialButtonOnClickListener(point, pointType)); homeButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - AddPointBottomSheetDialog.showInstance(mapActivity, PointType.HOME); - return true; - } - }); - - View workButton = view.findViewById(R.id.work_button); - workButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (workPoint == null) { - AddPointBottomSheetDialog.showInstance(mapActivity, PointType.WORK); - } else { - targetPointsHelper.navigateToPoint(new LatLon(workPoint.getLatitude(), workPoint.getLongitude()), - true, -1, workPoint.getPointDescription(mapActivity)); - } - } - }); - workButton.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - AddPointBottomSheetDialog.showInstance(mapActivity, PointType.WORK); + AddPointBottomSheetDialog.showInstance(mapActivity, pointType); return true; } }); } + + class SpecialButtonOnClickListener implements View.OnClickListener { + FavouritePoint point; + PointType pointType; + + SpecialButtonOnClickListener(FavouritePoint point, PointType pointType) { + this.point = point; + this.pointType = pointType; + } + + @Override + public void onClick(View v) { + if (point == null) { + AddPointBottomSheetDialog.showInstance(mapActivity, pointType); + } else { + if (OsmAndLocationProvider.isLocationPermissionAvailable(app)) { + mapActivity.getMyApplication().getTargetPointsHelper() + .navigateToPoint(new LatLon(point.getLatitude(), point.getLongitude()), + true, -1, point.getPointDescription(mapActivity)); + } else { + ActivityCompat.requestPermissions(mapActivity, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); + } + } + } + } } From da8b4602cbbfc8f23891d87aac17452b261f6161 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 31 Jan 2020 14:31:22 +0200 Subject: [PATCH 2/3] Fix remarks --- .../src/net/osmand/plus/OsmAndLocationProvider.java | 10 +++++++++- .../src/net/osmand/plus/activities/MapActivity.java | 8 ++++---- .../other/FavouritesBottomSheetMenuFragment.java | 9 ++------- .../AddPointBottomSheetDialog.java | 9 ++------- .../plus/routepreparationmenu/MapRouteInfoMenu.java | 9 ++------- .../routepreparationmenu/cards/HomeWorkCard.java | 13 ++++--------- 6 files changed, 23 insertions(+), 35 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 2a039f3bbf..9ebe58bc19 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -1,5 +1,6 @@ package net.osmand.plus; +import android.app.Activity; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import java.util.ArrayList; @@ -17,7 +18,6 @@ import net.osmand.binary.GeocodingUtilities.GeocodingResult; import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; import net.osmand.data.QuadPoint; -import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.routing.RoutingHelper; import net.osmand.router.RouteSegmentResult; @@ -975,4 +975,12 @@ public class OsmAndLocationProvider implements SensorEventListener { } return true; } + + public static void requestFineLocationPermissionIfNeeded(Activity activity) { + if (!OsmAndLocationProvider.isLocationPermissionAvailable(activity)) { + ActivityCompat.requestPermissions(activity, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 6449751c41..4e00ae2d40 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -2009,7 +2009,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } if (requestCode == DataStorageFragment.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE - && grantResults.length > 0 && permissions.length > 0 + && permissions.length > 0 && Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permissions[0])) { if (grantResults[0] != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, @@ -2017,12 +2017,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven Toast.LENGTH_LONG).show(); } } else if (requestCode == DownloadActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE - && grantResults.length > 0 && permissions.length > 0 + && permissions.length > 0 && Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permissions[0])) { permissionAsked = true; permissionGranted = grantResults[0] == PackageManager.PERMISSION_GRANTED; } else if (requestCode == FirstUsageWizardFragment.FIRST_USAGE_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION - && grantResults.length > 0 && permissions.length > 0 + && permissions.length > 0 && Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permissions[0])) { new Timer().schedule(new TimerTask() { @@ -2045,7 +2045,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } }, 1); } else if (requestCode == MapActivityActions.REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION - && grantResults.length > 0 && permissions.length > 0 + && permissions.length > 0 && Manifest.permission.ACCESS_FINE_LOCATION.equals(permissions[0])) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { LatLon latLon = getContextMenu().getLatLon(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java index d63da7e1a0..a2fc670622 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java @@ -158,14 +158,9 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag targetPointsHelper.setStartPoint(ll, true, point.getPointDescription(app)); break; case TARGET: - if (OsmAndLocationProvider.isLocationPermissionAvailable(getContext())) { + if (getActivity() != null) { targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription(app)); - } else { - if (getActivity() != null) { - ActivityCompat.requestPermissions(getActivity(), - new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, - OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); - } + OsmAndLocationProvider.requestFineLocationPermissionIfNeeded(getActivity()); } break; case INTERMEDIATE: diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 6be5c889ab..79501ffba6 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -445,13 +445,8 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { targetPointsHelper.setStartPoint(ll, true, name); break; case TARGET: - if (OsmAndLocationProvider.isLocationPermissionAvailable(getContext())) { - targetPointsHelper.navigateToPoint(ll, true, -1, name); - } else { - ActivityCompat.requestPermissions(mapActivity, - new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, - OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); - } + targetPointsHelper.navigateToPoint(ll, true, -1, name); + OsmAndLocationProvider.requestFineLocationPermissionIfNeeded(mapActivity); break; case INTERMEDIATE: targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), name); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 5bfbc5e44d..a86526fba7 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -284,13 +284,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener targetPointsHelper.setStartPoint(latLon, true, pd); break; case TARGET: - if (OsmAndLocationProvider.isLocationPermissionAvailable(app)) { - targetPointsHelper.navigateToPoint(latLon, true, -1, pd); - } else { - ActivityCompat.requestPermissions(mapActivity, - new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, - OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); - } + targetPointsHelper.navigateToPoint(latLon, true, -1, pd); + OsmAndLocationProvider.requestFineLocationPermissionIfNeeded(mapActivity); break; case INTERMEDIATE: targetPointsHelper.navigateToPoint(latLon, true, targetPointsHelper.getIntermediatePoints().size(), pd); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java index 3e7062377f..ebaf757d91 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java @@ -64,15 +64,10 @@ public class HomeWorkCard extends BaseCard { if (point == null) { AddPointBottomSheetDialog.showInstance(mapActivity, pointType); } else { - if (OsmAndLocationProvider.isLocationPermissionAvailable(app)) { - mapActivity.getMyApplication().getTargetPointsHelper() - .navigateToPoint(new LatLon(point.getLatitude(), point.getLongitude()), - true, -1, point.getPointDescription(mapActivity)); - } else { - ActivityCompat.requestPermissions(mapActivity, - new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, - OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); - } + mapActivity.getMyApplication().getTargetPointsHelper().navigateToPoint( + new LatLon(point.getLatitude(), point.getLongitude()), + true, -1, point.getPointDescription(app)); + OsmAndLocationProvider.requestFineLocationPermissionIfNeeded(mapActivity); } } } From 11550ea94dc9ecb9403975671197bac0e0d60a8b Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 31 Jan 2020 14:46:11 +0200 Subject: [PATCH 3/3] Fix remarks --- OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java | 2 +- .../plus/routepreparationmenu/MapRouteInfoMenu.java | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 9ebe58bc19..9be3c277e0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -977,7 +977,7 @@ public class OsmAndLocationProvider implements SensorEventListener { } public static void requestFineLocationPermissionIfNeeded(Activity activity) { - if (!OsmAndLocationProvider.isLocationPermissionAvailable(activity)) { + if (!isLocationPermissionAvailable(activity)) { ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index a86526fba7..cee90701f2 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -1,7 +1,6 @@ package net.osmand.plus.routepreparationmenu; -import android.Manifest; import android.content.Context; import android.content.DialogInterface.OnDismissListener; import android.graphics.PointF; @@ -19,7 +18,6 @@ import android.support.transition.Scene; import android.support.transition.Transition; import android.support.transition.TransitionListenerAdapter; import android.support.transition.TransitionManager; -import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatImageView; @@ -263,7 +261,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (selectFromMapTouch) { selectFromMapTouch = false; LatLon latLon = tileBox.getLatLonFromPixel(point.x, point.y); - choicePointTypeAction(mapActivity, latLon, selectFromMapPointType, null, null); + choosePointTypeAction(mapActivity, latLon, selectFromMapPointType, null, null); if (selectFromMapWaypoints) { WaypointsFragment.showInstance(mapActivity.getSupportFragmentManager(), true); } else { @@ -275,7 +273,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener return false; } - private void choicePointTypeAction(MapActivity mapActivity, LatLon latLon, PointType pointType, PointDescription pd, String address) { + private void choosePointTypeAction(MapActivity mapActivity, LatLon latLon, PointType pointType, PointDescription pd, String address) { OsmandApplication app = getApp(); FavouritesDbHelper favorites = app.getFavorites(); TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper(); @@ -1796,7 +1794,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, name); - choicePointTypeAction(mapActivity, latLon, pointType, pd, name); + choosePointTypeAction(mapActivity, latLon, pointType, pd, name); updateMenu(); } } @@ -1839,7 +1837,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (marker != null) { LatLon latLon = new LatLon(marker.getLatitude(), marker.getLongitude()); PointDescription pd = marker.getPointDescription(mapActivity); - choicePointTypeAction(mapActivity, latLon, pointType, pd, null); + choosePointTypeAction(mapActivity, latLon, pointType, pd, null); updateMenu(); } else { MapMarkerSelectionFragment selectionFragment = MapMarkerSelectionFragment.newInstance(pointType);