From 6074bd8576e16aa6e51cd9fb8af6e18fb2a5f378 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 25 Feb 2015 19:16:11 +0200 Subject: [PATCH] Updated all tracks in my places --- OsmAnd/res/layout/available_gpx.xml | 2 +- .../plus/activities/AvailableGPXFragment.java | 71 +++++++++++-------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/OsmAnd/res/layout/available_gpx.xml b/OsmAnd/res/layout/available_gpx.xml index 1de3b2ecab..18b3c01786 100644 --- a/OsmAnd/res/layout/available_gpx.xml +++ b/OsmAnd/res/layout/available_gpx.xml @@ -30,7 +30,7 @@ - selectedItems = new ArrayList(); + private List selectedItems = new ArrayList<>(); private ActionMode actionMode; private LoadGpxTask asyncLoader; private GpxIndexesAdapter listAdapter; + private ShowedOnMapAdapter showOnMapAdapter; MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US); private LoadLocalIndexDescriptionTask descriptionLoader; private ContextMenuAdapter optionsMenuAdapter; @@ -122,19 +119,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { } updateCurrentTrack(getView()); - updateShowedOnMapTracks(); - } - private void updateShowedOnMapTracks() { - View v = getView(); - if (v == null) { - return; - } - + private void createShowedOnMapsView(View v) { + v.findViewById(R.id.on_map_layout).setVisibility(View.GONE); ListView onMap = (ListView)v.findViewById(R.id.gpx_on_map); - onMap.setAdapter(new ShowedOnMapAdapter(getActivity(), R.layout.dash_gpx_track_item)); - + showOnMapAdapter = new ShowedOnMapAdapter(getActivity(), R.layout.dash_gpx_track_item); + onMap.setAdapter(showOnMapAdapter); } @Override @@ -184,6 +175,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { MapActivity.launchMapActivityMoveToTop(getActivity()); } }); + + createShowedOnMapsView(v); return v; } @@ -641,24 +634,36 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { protected void onPreExecute() { ((ActionBarActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true); listAdapter.clear(); + if (showOnMapAdapter != null) { + showOnMapAdapter.clear(); + } } @Override protected void onProgressUpdate(GpxInfo... values) { for (GpxInfo v : values) { listAdapter.addLocalIndexInfo(v); + if (selectedGpxHelper.getSelectedFileByName(v.getFileName()) != null){ + showOnMapAdapter.add(v); + } } + showOnMapAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged(); } public void setResult(List result) { this.result = result; listAdapter.clear(); + showOnMapAdapter.clear(); if (result != null) { for (GpxInfo v : result) { listAdapter.addLocalIndexInfo(v); + if (selectedGpxHelper.getSelectedFileByName(v.getFileName()) != null){ + showOnMapAdapter.add(v); + } } listAdapter.notifyDataSetChanged(); + showOnMapAdapter.notifyDataSetChanged(); onPostExecute(result); } } @@ -685,7 +690,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { private void loadGPXData(File mapPath, List result, LoadGpxTask loadTask) { if (mapPath.canRead()) { - List progress = new ArrayList(); + List progress = new ArrayList<>(); loadGPXFolder(mapPath, result, loadTask, progress, ""); if (!progress.isEmpty()) { loadTask.loadFile(progress.toArray(new GpxInfo[progress.size()])); @@ -723,8 +728,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { protected class GpxIndexesAdapter extends OsmandBaseExpandableListAdapter implements Filterable { - Map> data = new LinkedHashMap>(); - List category = new ArrayList(); + Map> data = new LinkedHashMap<>(); + List category = new ArrayList<>(); int warningColor; int okColor; int defaultColor; @@ -741,11 +746,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { } public Set getSelectedGpx() { - Set originalSelectedItems = new HashSet(); + Set originalSelectedItems = new HashSet<>(); for (List l : data.values()) { if (l != null) { for (GpxInfo g : l) { - boolean add = false; + boolean add; if (g.gpx != null && g.gpx.showCurrentTrack) { add = selectedGpxHelper.getSelectedCurrentRecordingTrack() != null; } else { @@ -1080,7 +1085,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { int total = 0; for (GpxInfo info : params) { if (!isCancelled() && (info.gpx == null || !info.gpx.showCurrentTrack)) { - boolean successfull = false; + boolean successfull; successfull = Algorithms.removeAllFiles(info.file); total++; if (successfull) { @@ -1149,7 +1154,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { @Override protected void onPreExecute() { - ((ActionBarActivity) getActivity()).setProgressBarIndeterminateVisibility(true); + getActivity().setProgressBarIndeterminateVisibility(true); } @Override @@ -1216,7 +1221,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { results.count = 1; } else { String cs = constraint.toString().toLowerCase(); - List res = new ArrayList(); + List res = new ArrayList<>(); for (GpxInfo r : raw) { if (r.getName().toLowerCase().indexOf(cs) != -1) { res.add(r); @@ -1234,10 +1239,15 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { if (results.values != null) { synchronized (listAdapter) { listAdapter.clear(); + showOnMapAdapter.clear(); for (GpxInfo i : ((List) results.values)) { listAdapter.addLocalIndexInfo(i); + if (selectedGpxHelper.getSelectedFileByName(i.getFileName()) != null){ + showOnMapAdapter.add(i); + } } } + showOnMapAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged(); if (constraint != null && constraint.length() > 3) { collapseTrees(10); @@ -1406,12 +1416,15 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { v.findViewById(R.id.show_on_map).setVisibility(View.GONE); v.findViewById(R.id.stop).setVisibility(View.GONE); v.findViewById(R.id.divider).setVisibility(View.GONE); - String description = GpxUiHelper.getDescription(getMyApplication(), gpxInfo.gpx, gpxInfo.file, true); - int startindex = description.indexOf(">"); - int endindex = description.indexOf(""); - String distnace = description.substring(startindex + 1, endindex); - ((TextView) v.findViewById(R.id.distance)). - setText(distnace); + if (gpxInfo.gpx != null) { + String description = GpxUiHelper.getDescription(getMyApplication(), gpxInfo.gpx, gpxInfo.file, true); + int startindex = description.indexOf(">"); + int endindex = description.indexOf(""); + String distnace = description.substring(startindex + 1, endindex); + ((TextView) v.findViewById(R.id.distance)). + setText(distnace); + + } CompoundButton check = (CompoundButton)v.findViewById(R.id.check); check.setVisibility(View.VISIBLE);