refactored gpx layers dialog

This commit is contained in:
unknown 2014-07-04 14:18:44 +03:00
parent 2eb942aa0a
commit 350c5ccc0a

View file

@ -128,7 +128,7 @@ public class GpxUiHelper {
return description.toString();
}
public static void selectGPXFile(List<String> list, final Activity activity,
public static void selectGPXFile(List<String> selectedGpxList, final Activity activity,
final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile[]> 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) {
final ContextMenuAdapter adapter = createGpxContextMenuAdapter(activity, list, null, multipleChoice);
createDialog(activity, showCurrentGpx, multipleChoice, callbackWithObject, list, adapter);
}
}
private static ContextMenuAdapter createGpxContextMenuAdapter(Activity activity, List<String> allGpxList, List<String> 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;
}
createDialog(activity, showCurrentGpx, multipleChoice, callbackWithObject, list, adapter);
}
}
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();
}