From 3370a5bab7e3e7a4d0a821baca36471390a0ffcf Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 13 Apr 2021 17:16:02 +0300 Subject: [PATCH] Fix click position on long tap and track points switcher visibility --- .../osmand/plus/track/TrackMenuFragment.java | 103 +++++++++++------- .../osmand/plus/views/layers/GPXLayer.java | 4 +- 2 files changed, 65 insertions(+), 42 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 23bcd0d99b..2eedf2eab5 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -380,46 +380,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } private void updateHeader() { - if (menuType == TrackMenuType.OVERVIEW) { - setHeaderTitle(gpxTitle, true); - if (overviewCard != null && overviewCard.getView() != null) { - ViewGroup parent = ((ViewGroup) overviewCard.getView().getParent()); - if (parent != null) { - parent.removeView(overviewCard.getView()); - } - headerContainer.addView(overviewCard.getView()); - } else { - overviewCard = new OverviewCard(getMapActivity(), this, selectedGpxFile); - overviewCard.setListener(this); - headerContainer.addView(overviewCard.build(getMapActivity())); - } - GpxBlockStatisticsBuilder blocksBuilder = overviewCard.getBlockStatisticsBuilder(); - if (isCurrentRecordingTrack()) { - blocksBuilder.runUpdatingStatBlocksIfNeeded(); - } - } else { - if (menuType == TrackMenuType.POINTS && !Algorithms.isEmpty(pointsCard.getGroups())) { - if (groupsCard != null && groupsCard.getView() != null) { - ViewGroup parent = ((ViewGroup) groupsCard.getView().getParent()); - if (parent != null) { - parent.removeView(groupsCard.getView()); - } - headerContainer.addView(groupsCard.getView()); - } else { - groupsCard = new PointsGroupsCard(getMapActivity(), pointsCard.getGroups()); - groupsCard.setListener(this); - headerContainer.addView(groupsCard.build(getMapActivity())); - } - } else if (groupsCard != null && groupsCard.getView() != null) { - headerContainer.removeView(groupsCard.getView()); - } - if (overviewCard != null && overviewCard.getView() != null) { - overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks(); - headerContainer.removeView(overviewCard.getView()); - } - boolean isOptions = menuType == TrackMenuType.OPTIONS; - setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions); - } + updateHeaderCard(); + + boolean isOptions = menuType == TrackMenuType.OPTIONS; + setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions); + if (menuType == TrackMenuType.POINTS) { AndroidUiHelper.updateVisibility(searchButton, true); } else { @@ -429,6 +394,64 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } + private void updateHeaderCard() { + if (menuType == TrackMenuType.OVERVIEW) { + addOverviewCardToHeader(); + removeCardViewFromHeader(groupsCard); + } else { + if (overviewCard != null) { + overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks(); + } + if (menuType == TrackMenuType.POINTS && !Algorithms.isEmpty(pointsCard.getGroups())) { + addPointsGroupsCardToHeader(); + } else { + removeCardViewFromHeader(groupsCard); + } + removeCardViewFromHeader(overviewCard); + } + } + + private void addOverviewCardToHeader() { + if (overviewCard != null && overviewCard.getView() != null) { + addCardViewToHeader(overviewCard); + } else { + MapActivity mapActivity = requireMapActivity(); + overviewCard = new OverviewCard(mapActivity, this, selectedGpxFile); + overviewCard.setListener(this); + headerContainer.addView(overviewCard.build(mapActivity)); + } + if (isCurrentRecordingTrack()) { + overviewCard.getBlockStatisticsBuilder().runUpdatingStatBlocksIfNeeded(); + } + } + + private void addPointsGroupsCardToHeader() { + if (groupsCard != null) { + addCardViewToHeader(groupsCard); + } else { + MapActivity mapActivity = requireMapActivity(); + groupsCard = new PointsGroupsCard(mapActivity, pointsCard.getGroups()); + groupsCard.setListener(this); + headerContainer.addView(groupsCard.build(mapActivity)); + } + } + + private void removeCardViewFromHeader(BaseCard card) { + if (card != null && card.getView() != null) { + headerContainer.removeView(card.getView()); + } + } + + private void addCardViewToHeader(BaseCard card) { + if (card != null && card.getView() != null) { + ViewGroup parent = ((ViewGroup) card.getView().getParent()); + if (parent != null) { + parent.removeView(card.getView()); + } + headerContainer.addView(card.getView()); + } + } + private void setupToolbar() { toolbarTextView.setText(gpxTitle); diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index 14e03affb0..007e6fe700 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -1118,9 +1118,9 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM if (!Algorithms.isEmpty(trackPoints)) { MapActivity mapActivity = (MapActivity) view.getContext(); SelectedGpxPoint selectedGpxPoint = (SelectedGpxPoint) trackPoints.get(0); - WptPt wptPt = selectedGpxPoint.getSelectedPoint(); + LatLon latLon = tileBox.getLatLonFromPixel(point.x, point.y); PointDescription description = getObjectName(selectedGpxPoint); - mapActivity.getContextMenu().show(new LatLon(wptPt.lat, wptPt.lon), description, selectedGpxPoint); + mapActivity.getContextMenu().show(latLon, description, selectedGpxPoint); return true; } }