Merge pull request #11417 from osmandapp/track_menu_fixes

Fix click position on long tap and track points switcher visibility
This commit is contained in:
vshcherb 2021-04-13 19:52:20 +02:00 committed by GitHub
commit 26f9e85f2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 42 deletions

View file

@ -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());
}
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);

View file

@ -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;
}
}