Fix click position on long tap and track points switcher visibility

This commit is contained in:
Vitaliy 2021-04-13 17:16:02 +03:00
parent 20df6ec98f
commit 3370a5bab7
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() { private void updateHeader() {
if (menuType == TrackMenuType.OVERVIEW) { updateHeaderCard();
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; boolean isOptions = menuType == TrackMenuType.OPTIONS;
setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions); setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions);
}
if (menuType == TrackMenuType.POINTS) { if (menuType == TrackMenuType.POINTS) {
AndroidUiHelper.updateVisibility(searchButton, true); AndroidUiHelper.updateVisibility(searchButton, true);
} else { } 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() { private void setupToolbar() {
toolbarTextView.setText(gpxTitle); toolbarTextView.setText(gpxTitle);

View file

@ -1118,9 +1118,9 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
if (!Algorithms.isEmpty(trackPoints)) { if (!Algorithms.isEmpty(trackPoints)) {
MapActivity mapActivity = (MapActivity) view.getContext(); MapActivity mapActivity = (MapActivity) view.getContext();
SelectedGpxPoint selectedGpxPoint = (SelectedGpxPoint) trackPoints.get(0); SelectedGpxPoint selectedGpxPoint = (SelectedGpxPoint) trackPoints.get(0);
WptPt wptPt = selectedGpxPoint.getSelectedPoint(); LatLon latLon = tileBox.getLatLonFromPixel(point.x, point.y);
PointDescription description = getObjectName(selectedGpxPoint); PointDescription description = getObjectName(selectedGpxPoint);
mapActivity.getContextMenu().show(new LatLon(wptPt.lat, wptPt.lon), description, selectedGpxPoint); mapActivity.getContextMenu().show(latLon, description, selectedGpxPoint);
return true; return true;
} }
} }