From aaf4d7ad8c11302c5cbbddb3f5464f74c3a94ef1 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 8 Nov 2017 18:13:08 +0200 Subject: [PATCH] Fix NPE --- .../plus/myplaces/TrackPointFragment.java | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index c2c640eefd..356dc4e414 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -629,36 +629,39 @@ public class TrackPointFragment extends OsmandExpandableListFragment { private void addMapMarkersSyncGroup() { MapMarkersHelper markersHelper = app.getMapMarkersHelper(); - File gpx = getGpxDataItem().getFile(); - MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), - AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); - markersHelper.addMarkersSyncGroup(syncGroup); - markersHelper.syncGroup(syncGroup); - GPXFile gpxFile = getTrackActivity().getGpx(); - if (gpxFile != null) { - app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false); - } - hideTransparentOverlay(); - closeMenu(); - updateMenuFabVisibility(false); - Snackbar snackbar = Snackbar.make(mainView, getResources().getString(R.string.waypoints_added_to_map_markers), Snackbar.LENGTH_LONG) - .setAction(getResources().getString(R.string.view), new View.OnClickListener() { - @Override - public void onClick(View v) { - MapActivity.launchMapActivityMoveToTop(getTrackActivity(), MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS); - } - }); - snackbar.addCallback(new Snackbar.Callback() { - @Override - public void onDismissed(Snackbar transientBottomBar, int event) { - updateMenuFabVisibility(true); - super.onDismissed(transientBottomBar, event); + GpxDataItem gpxDataItem = getGpxDataItem(); + if (gpxDataItem != null) { + File gpx = gpxDataItem.getFile(); + MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), + AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); + markersHelper.addMarkersSyncGroup(syncGroup); + markersHelper.syncGroup(syncGroup); + GPXFile gpxFile = getTrackActivity().getGpx(); + if (gpxFile != null) { + app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false); } - }); - View snackBarView = snackbar.getView(); - TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action); - tv.setTextColor(ContextCompat.getColor(getContext(), R.color.color_dialog_buttons_dark)); - snackbar.show(); + hideTransparentOverlay(); + closeMenu(); + updateMenuFabVisibility(false); + Snackbar snackbar = Snackbar.make(mainView, getResources().getString(R.string.waypoints_added_to_map_markers), Snackbar.LENGTH_LONG) + .setAction(getResources().getString(R.string.view), new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivity.launchMapActivityMoveToTop(getTrackActivity(), MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS); + } + }); + snackbar.addCallback(new Snackbar.Callback() { + @Override + public void onDismissed(Snackbar transientBottomBar, int event) { + updateMenuFabVisibility(true); + super.onDismissed(transientBottomBar, event); + } + }); + View snackBarView = snackbar.getView(); + TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action); + tv.setTextColor(ContextCompat.getColor(getContext(), R.color.color_dialog_buttons_dark)); + snackbar.show(); + } } private void updateMenuFabVisibility(boolean visible) {