diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 202d71c6fe..0366481bad 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -128,7 +128,7 @@ public class GpxUiHelper { return description.toString(); } - public static void selectGPXFile(List list, final Activity activity, + public static void selectGPXFile(List selectedGpxList, final Activity activity, final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject callbackWithObject){ OsmandApplication app = (OsmandApplication) activity.getApplication(); final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); @@ -138,30 +138,10 @@ public class GpxUiHelper { } if(!allGpxList.isEmpty() || showCurrentGpx){ - final ContextMenuAdapter adapter = new ContextMenuAdapter(activity); if(showCurrentGpx){ allGpxList.add(0, activity.getString(R.string.show_current_gpx_title)); } - - //element position in adapter - int i =0; - for(String s : allGpxList) { - String fileName = s; - if (s.endsWith(".gpx")) { - s = s.substring(0, s.length() - ".gpx".length()); - } - s = s.replace('_', ' '); - - adapter.item(s).selected(multipleChoice ? 0 : -1) - .icons(R.drawable.ic_action_info_dark, R.drawable.ic_action_info_light).reg(); - for (String file : list) { - if (file.endsWith(fileName)) { - adapter.setSelection(i, 1); - break; - } - } - i++; - } + final ContextMenuAdapter adapter = createGpxContextMenuAdapter(activity,allGpxList, selectedGpxList, multipleChoice); createDialog(activity, showCurrentGpx, multipleChoice, callbackWithObject, allGpxList, adapter); } } @@ -175,22 +155,42 @@ public class GpxUiHelper { AccessibleToast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show(); } if(!list.isEmpty() || showCurrentGpx){ - - final ContextMenuAdapter adapter = new ContextMenuAdapter(activity); if(showCurrentGpx){ list.add(0, activity.getString(R.string.show_current_gpx_title)); } - for(String s : list) { - if (s.endsWith(".gpx")) { - s = s.substring(0, s.length() - ".gpx".length()); - } - s = s.replace('_', ' '); - adapter.item(s).selected(multipleChoice ? 0 : -1) - .icons(R.drawable.ic_action_info_dark, R.drawable.ic_action_info_light).reg(); - } + + final ContextMenuAdapter adapter = createGpxContextMenuAdapter(activity, list, null, multipleChoice); createDialog(activity, showCurrentGpx, multipleChoice, callbackWithObject, list, adapter); } } + + private static ContextMenuAdapter createGpxContextMenuAdapter(Activity activity, List allGpxList, List selectedGpxList, boolean multipleChoice) { + final ContextMenuAdapter adapter = new ContextMenuAdapter(activity); + //element position in adapter + int i = 0; + for (String s : allGpxList) { + String fileName = s; + if (s.endsWith(".gpx")) { + s = s.substring(0, s.length() - ".gpx".length()); + } + s = s.replace('_', ' '); + + adapter.item(s).selected(multipleChoice ? 0 : -1) + .icons(R.drawable.ic_action_info_dark, R.drawable.ic_action_info_light).reg(); + + //if there's some selected files - need to mark them as selected + if (selectedGpxList != null) { + for (String file : selectedGpxList) { + if (file.endsWith(fileName)) { + adapter.setSelection(i, 1); + break; + } + } + } + i++; + } + return adapter; + } private static void setDescripionInDialog(final ArrayAdapter adapter, final ContextMenuAdapter cmAdapter, Activity activity, final File dir, String filename, final int position) { @@ -290,6 +290,11 @@ public class GpxUiHelper { @Override public void onClick(DialogInterface dialog, int which) { GPXFile currentGPX = null; + //clear all previously selected files before adding new one + OsmandApplication app = (OsmandApplication) activity.getApplication(); + if(app != null && app.getSelectedGpxHelper() != null){ + app.getSelectedGpxHelper().clearAllGpxFileToShow(); + } if (showCurrentGpx && adapter.getSelection(0) > 0) { currentGPX = app.getSavingTrackHelper().getCurrentGpx(); }