From 5043d5b76c52c778e2dfc54f49a065802ac09c78 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 7 Mar 2015 16:10:58 +0100 Subject: [PATCH] Finish tracks --- OsmAnd/res/layout/gpx_item_list_item.xml | 3 +- .../src/net/osmand/plus/AppInitializer.java | 2 +- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 30 +-- .../net/osmand/plus/GpxSelectionHelper.java | 63 +++--- .../activities/EditPOIFilterActivity.java | 2 +- .../plus/activities/SavingTrackHelper.java | 12 +- .../osmand/plus/activities/TrackActivity.java | 63 +++--- .../plus/monitoring/DashTrackFragment.java | 6 + .../plus/myplaces/AvailableGPXFragment.java | 203 +++++------------- .../plus/myplaces/SelectedGPXFragment.java | 44 ++-- .../plus/skimapsplugin/SkiMapsPlugin.java | 3 - 11 files changed, 169 insertions(+), 262 deletions(-) diff --git a/OsmAnd/res/layout/gpx_item_list_item.xml b/OsmAnd/res/layout/gpx_item_list_item.xml index 841979723d..fd0a46697d 100644 --- a/OsmAnd/res/layout/gpx_item_list_item.xml +++ b/OsmAnd/res/layout/gpx_item_list_item.xml @@ -7,7 +7,7 @@ android:minHeight="@dimen/list_item_height" android:orientation="vertical" android:paddingLeft="@dimen/list_content_padding" - android:layout_marginTop="5dp" + android:paddingTop="10dp" android:paddingRight="@dimen/list_content_padding" > diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index ca4da1c8fa..92454711c9 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -427,7 +427,7 @@ public class AppInitializer implements IProgress { private void saveGPXTracks() { if (app.savingTrackHelper.hasDataToSave()) { long timeUpdated = app.savingTrackHelper.getLastTrackPointTime(); - if (System.currentTimeMillis() - timeUpdated >= 45000) { + if (System.currentTimeMillis() - timeUpdated >= 1000 * 60 * 30) { startTask(app.getString(R.string.saving_gpx_tracks), -1); try { warnings.addAll(app.savingTrackHelper.saveDataToGpx(app.getAppCustomization().getTracksDir())); diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index c1a707fbf0..1371cf726f 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -31,6 +31,7 @@ import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; +import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -482,6 +483,7 @@ public class GPXUtilities { public String warning = null; public String path = ""; public boolean showCurrentTrack; + public long modifiedTime = 0; public boolean isCloudmadeRouteFile() { return "cloudmade".equalsIgnoreCase(author); @@ -504,29 +506,6 @@ public class GPXUtilities { g.prepareInformation(fileTimestamp, splitSegments.toArray(new SplitSegment[splitSegments.size()])); return g ; } - - - public List splitByDistance(int meters) { - return split(getDistanceMetric(), meters); - } - - public List splitByTime(int seconds) { - return split(getTimeSplit(), seconds); - } - - - public List split(SplitMetric metric, int metricLimit) { - List splitSegments = new ArrayList(); - for(int i = 0; i< tracks.size() ; i++){ - Track subtrack = tracks.get(i); - for (int j = 0; j < subtrack.segments.size(); j++) { - TrkSegment segment = subtrack.segments.get(j); - splitSegment(metric, metricLimit, splitSegments, segment); - } - } - return convert(splitSegments); - } - public boolean hasRtePt() { @@ -538,6 +517,10 @@ public class GPXUtilities { return false; } + public boolean hasWptPt() { + return points.size() > 0; + } + public boolean hasTrkpt() { for(Track t : tracks) { for (TrkSegment ts : t.segments) { @@ -617,6 +600,7 @@ public class GPXUtilities { return points.isEmpty() && routes.isEmpty(); } + } public static String asString(GPXFile file, OsmandApplication ctx) { diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index c89630b188..e21dec6a24 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -11,6 +11,7 @@ import net.osmand.plus.GPXUtilities.Route; import net.osmand.plus.GPXUtilities.Track; import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.helpers.GpxUiHelper; @@ -54,22 +55,9 @@ public class GpxSelectionHelper { public final String getString(int resId, Object... formatArgs) { return app.getString(resId, formatArgs); } - - public List getDisplayGroups() { - List dg = new ArrayList(); - for(SelectedGpxFile s : selectedGPXFiles) { - if(s.displayGroups == null) { - s.displayGroups = new ArrayList(); - GPXFile g = s.getGpxFile(); - collectDisplayGroups(s.displayGroups, g); - } - dg.addAll(s.displayGroups); - - } - return dg; - } - public void collectDisplayGroups(List dg, GPXFile g) { + public List collectDisplayGroups(GPXFile g) { + List dg = new ArrayList(); String name = g.path; if(g.showCurrentTrack){ name = getString(R.string.gpx_available_current_track); @@ -160,6 +148,7 @@ public class GpxSelectionHelper { list.add(item); } } + return dg; } private static void processGroupTrack(OsmandApplication app, GpxDisplayGroup group) { @@ -357,7 +346,7 @@ public class GpxSelectionHelper { app.getSettings().SELECTED_GPX.set(ar.toString()); } - private void selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog) { + private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog) { boolean displayed = false; SelectedGpxFile sf ; if(gpx != null && gpx.showCurrentTrack) { @@ -380,11 +369,13 @@ public class GpxSelectionHelper { selectedGPXFiles.remove(sf); } } + return sf; } - public void selectGpxFile(GPXFile gpx, boolean show, boolean showNavigationDialog) { - selectGpxFileImpl(gpx, show, showNavigationDialog); + public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean showNavigationDialog) { + SelectedGpxFile sf = selectGpxFileImpl(gpx, show, showNavigationDialog); saveCurrentSelections(); + return sf; } @@ -395,24 +386,37 @@ public class GpxSelectionHelper { private GPXFile gpxFile; private int color; private GPXTrackAnalysis trackAnalysis; + private long modifiedTime = -1; private List> processedPointsToDisplay = new ArrayList>(); - private List displayGroups = null; private boolean routePoints; + + private List displayGroups; public void setGpxFile(GPXFile gpxFile) { this.gpxFile = gpxFile; if(gpxFile.tracks.size() > 0) { this.color = gpxFile.tracks.get(0).getColor(0); } - trackAnalysis = gpxFile.getAnalysis(new File(gpxFile.path).lastModified()); processPoints(); } public GPXTrackAnalysis getTrackAnalysis() { + if(modifiedTime != gpxFile.modifiedTime) { + update(); + } return trackAnalysis; } + private void update() { + modifiedTime = gpxFile.modifiedTime; + trackAnalysis = gpxFile.getAnalysis( + Algorithms.isEmpty(gpxFile.path) ? System.currentTimeMillis() : + new File(gpxFile.path).lastModified()); + displayGroups = null; + } + public void processPoints() { + update(); this.processedPointsToDisplay = gpxFile.proccessPoints(); if(this.processedPointsToDisplay.isEmpty()) { this.processedPointsToDisplay = gpxFile.processRoutePoints(); @@ -432,10 +436,6 @@ public class GpxSelectionHelper { return processedPointsToDisplay; } - public List getDisplayGroups() { - return displayGroups; - } - public GPXFile getGpxFile() { return gpxFile; } @@ -457,6 +457,21 @@ public class GpxSelectionHelper { return color; } + public List getDisplayGroups() { + if(modifiedTime != gpxFile.modifiedTime) { + update(); + } + return displayGroups; + } + + public void setDisplayGroups(List displayGroups) { + if(modifiedTime != gpxFile.modifiedTime) { + update(); + } + this.displayGroups = displayGroups; + } + + } public enum GpxDisplayItemType { diff --git a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java index 2948a65058..d86f44485d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java @@ -269,7 +269,7 @@ public class EditPOIFilterActivity extends OsmandListActivity { helper.editPoiFilter(filter); ListView lv = EditPOIFilterActivity.this.getListView(); AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter(); - la.notifyDataSetInvalidated(); + la.notifyDataSetChanged(); lv.setSelectionFromTop(index, top); } }); diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index 2658bb8a1e..6c2ae5d51b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -12,6 +12,7 @@ import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXUtilities.Track; import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.WptPt; @@ -311,7 +312,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { lastTimeUpdated = 0; lastPoint = null; execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis()}); - addTrackPoint( null, true); + addTrackPoint( null, true, System.currentTimeMillis()); } public void updateLocation(net.osmand.Location location) { @@ -369,10 +370,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } lastTimeUpdated = time; WptPt pt = new GPXUtilities.WptPt(lat, lon, time, alt, speed, hdop); - addTrackPoint(pt, newSegment); + addTrackPoint(pt, newSegment, time); } - private void addTrackPoint(WptPt pt, boolean newSegment) { + private void addTrackPoint(WptPt pt, boolean newSegment, long time) { List> points = currentTrack.getModifiablePointsToDisplay(); Track track = currentTrack.getGpxFile().tracks.get(0); assert track.segments.size() == points.size(); @@ -389,12 +390,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper { TrkSegment lt = track.segments.get(track.segments.size() - 1); lt.points.add(pt); } + currentTrack.getModifiableGpxFile().modifiedTime = time; } public void insertPointData(double lat, double lon, long time, String description) { final WptPt pt = new WptPt(lat, lon, time, Double.NaN, 0, Double.NaN); pt.name = description; currentTrack.getModifiableGpxFile().points.add(pt); + currentTrack.getModifiableGpxFile().modifiedTime = time; points++; execWithClose(updatePointsScript, new Object[] { lat, lon, time, description }); } @@ -419,6 +422,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper { currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks); } currentTrack.processPoints(); + GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis()); + distance = analysis.totalDistance; + points = analysis.wptPoints; } public boolean getIsRecording() { diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index f230d5ff98..6bcdf4fe2f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -11,6 +11,8 @@ import java.util.List; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.myplaces.TrackPointFragment; @@ -20,7 +22,6 @@ import net.osmand.plus.views.controls.PagerSlidingTabStrip; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; -import android.os.Handler; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; @@ -40,6 +41,8 @@ public class TrackActivity extends TabActivity { private File file = null; private GPXFile result; ViewPager mViewPager; + private long modifiedTime = -1; + private List displayGroups; @Override public void onCreate(Bundle icicle) { @@ -86,10 +89,10 @@ public class TrackActivity extends TabActivity { protected void onPostExecute(GPXFile result) { setSupportProgressBarIndeterminateVisibility(false); - setResult(result); + setGpx(result); ((OsmandFragmentPagerAdapter) mViewPager.getAdapter()).addTab( getTabIndicator(R.string.track_segments, TrackSegmentFragment.class)); - if (isHavingTrackPoints()){ + if (isHavingWayPoints()){ ((OsmandFragmentPagerAdapter) mViewPager.getAdapter()).addTab( getTabIndicator(R.string.track_points, TrackPointFragment.class)); } @@ -103,12 +106,26 @@ public class TrackActivity extends TabActivity { } - protected void setResult(GPXFile result) { + protected void setGpx(GPXFile result) { this.result = result; + if(file == null) { + result = getMyApplication().getSavingTrackHelper().getCurrentGpx(); + } } - public GPXFile getResult() { - return result; + public List getResult() { + if (result.modifiedTime != modifiedTime) { + modifiedTime = result.modifiedTime; + GpxSelectionHelper selectedGpxHelper = ((OsmandApplication) getApplication()).getSelectedGpxHelper(); + displayGroups = selectedGpxHelper.collectDisplayGroups(result); + if (file != null) { + SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByPath(result.path); + if (sf != null && file != null && sf.getDisplayGroups() != null) { + displayGroups = sf.getDisplayGroups(); + } + } + } + return displayGroups; } @Override @@ -153,38 +170,16 @@ public class TrackActivity extends TabActivity { return false; } - public List getContent() { - GpxSelectionHelper selectedGpxHelper = getMyApplication().getSelectedGpxHelper(); - List displayGrous = new ArrayList(); - selectedGpxHelper.collectDisplayGroups(displayGrous, getResult()); - return displayGrous; - } - - boolean isHavingTrackPoints(){ - List groups = getContent(); - for (GpxSelectionHelper.GpxDisplayGroup group : groups){ - GpxSelectionHelper.GpxDisplayItemType type = group.getType(); - if (type == GpxSelectionHelper.GpxDisplayItemType.TRACK_POINTS && - !group.getModifiableList().isEmpty()){ - return true; - } - } - - return false; + boolean isHavingWayPoints(){ + return getGpx().hasWptPt(); } boolean isHavingRoutePoints(){ - List groups = getContent(); - for (GpxSelectionHelper.GpxDisplayGroup group : groups){ - GpxSelectionHelper.GpxDisplayItemType type = group.getType(); - if (type == GpxSelectionHelper.GpxDisplayItemType.TRACK_ROUTE_POINTS && - !group.getModifiableList().isEmpty()){ - return true; - } - } - - return false; + return getGpx().hasRtePt(); } + public GPXFile getGpx() { + return result; + } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java index c7956ae070..d0d4e3a51b 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java @@ -133,6 +133,12 @@ public class DashTrackFragment extends DashBaseFragment { AvailableGPXFragment.createCurrentTrackView(view, app); ((TextView) view.findViewById(R.id.name)).setText(R.string.currently_recording_track); AvailableGPXFragment.updateCurrentTrack(view, getActivity(), app); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + AvailableGPXFragment.openTrack(getActivity(), null); + } + }); view.findViewById(R.id.divider).setVisibility(View.VISIBLE); tracks.addView(view); startHandler(view); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index d08fe3501b..4d8106bfa3 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -36,7 +36,6 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.download.LocalIndexesFragment; -import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.ScreenOrientationHelper; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin; @@ -60,8 +59,6 @@ import android.support.v7.app.ActionBarActivity; import android.support.v7.view.ActionMode; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.SearchView; -import android.text.Html; -import android.text.Spanned; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -91,13 +88,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { private LoadGpxTask asyncLoader; private GpxIndexesAdapter allGpxAdapter; private static MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US); - private LoadLocalIndexDescriptionTask descriptionLoader; private ContextMenuAdapter optionsMenuAdapter; private AsyncTask operationTask; private GpxSelectionHelper selectedGpxHelper; - private SavingTrackHelper savingTrackHelper; private OsmandApplication app; private boolean updateEnable; + private GpxInfo currentRecording; + private boolean showOnMapMode; @Override public void onAttach(Activity activity) { @@ -105,9 +102,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { this.app = (OsmandApplication) getActivity().getApplication(); final Collator collator = Collator.getInstance(); collator.setStrength(Collator.SECONDARY); + currentRecording = new GpxInfo(getMyApplication().getSavingTrackHelper().getCurrentGpx(), getString(R.string.currently_recording_track)); + currentRecording.currentlyRecordingTrack = true; asyncLoader = new LoadGpxTask(); selectedGpxHelper = ((OsmandApplication) activity.getApplication()).getSelectedGpxHelper(); - savingTrackHelper = ((OsmandApplication) activity.getApplication()).getSavingTrackHelper(); allGpxAdapter = new GpxIndexesAdapter(getActivity()); setAdapter(allGpxAdapter); } @@ -120,7 +118,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { if (getView() != null && updateEnable) { updateCurrentTrack(getView(), getActivity(), app); if(selectedGpxHelper.getSelectedCurrentRecordingTrack() != null) { - allGpxAdapter.notifyDataSetInvalidated(); + allGpxAdapter.notifyDataSetChanged(); } startHandler(); } @@ -142,8 +140,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { allGpxAdapter.refreshSelected(); allGpxAdapter.notifyDataSetChanged(); } - - updateCurrentTrack(getView(), getActivity(), app); + updateCurrentTrack(); + updateEnable = true; startHandler(); } @@ -156,6 +154,28 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { operationTask.cancel(true); } } + + public void updateCurrentTrack() { + updateCurrentTrack(getView(), getActivity(), app); + final CheckBox checkbox = (CheckBox) getView().findViewById(R.id.check_local_index); + checkbox.setVisibility(selectionMode && showOnMapMode? View.VISIBLE : View.GONE); + if (selectionMode && showOnMapMode) { + checkbox.setChecked(selectedItems.contains(currentRecording)); + checkbox.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + if (checkbox.isChecked()) { + selectedItems.add(currentRecording); + } else { + selectedItems.remove(currentRecording); + } + updateSelectionMode(actionMode); + } + }); + } + + } public static void updateCurrentTrack(View v, final Activity ctx, OsmandApplication app) { if (v == null) { @@ -227,7 +247,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { @Override public void onClick(View v) { openTrack(getActivity(), null); - MapActivity.launchMapActivityMoveToTop(getActivity()); } }); } @@ -403,11 +422,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { private void openShowOnMapMode() { enableSelectionMode(true); + showOnMapMode = true; selectedItems.clear(); final Set originalSelectedItems = allGpxAdapter.getSelectedGpx(); selectedItems.addAll(originalSelectedItems); actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() { + @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { enableSelectionMode(true); @@ -416,6 +437,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { it.setIcon(R.drawable.ic_action_done); MenuItemCompat.setShowAsAction(it, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); + updateCurrentTrack(); return true; } @@ -427,6 +449,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { runSelection(false); + updateCurrentTrack(); actionMode.finish(); allGpxAdapter.refreshSelected(); allGpxAdapter.notifyDataSetChanged(); @@ -441,6 +464,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { @Override public void onDestroyActionMode(ActionMode mode) { + updateCurrentTrack(); + showOnMapMode = false; enableSelectionMode(false); allGpxAdapter.notifyDataSetChanged(); } @@ -552,7 +577,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { } private void showGpxOnMap(GpxInfo info) { - info.updateGpxInfo(getMyApplication()); + info.setGpx(GPXUtilities.loadGPXFile(app, info.file)); boolean e = true; if (info != null && info.gpx != null) { WptPt loc = info.gpx.findPointToShow(); @@ -576,10 +601,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { @Override protected List doInBackground(Activity... params) { List result = new ArrayList(); - if (!savingTrackHelper.getCurrentGpx().isEmpty()) { - loadFile(new GpxInfo(savingTrackHelper.getCurrentGpx(), - app.getString(R.string.gpx_available_current_track))); - } loadGPXData(app.getAppPath(IndexConstants.GPX_INDEX_DIR), result, this); return result; } @@ -701,9 +722,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { SelectedGpxFile track = selectedGpxHelper.getSelectedCurrentRecordingTrack(); if (track != null && track.getGpxFile() != null) { if (track.getGpxFile().showCurrentTrack) { - GpxInfo g = new GpxInfo(track.getGpxFile(), getString(R.string.currently_recording_track)); - g.currentlyRecordingTrack = true; - originalSelectedItems.add(g); + originalSelectedItems.add(currentRecording); } } for (List l : data.values()) { @@ -1046,35 +1065,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { } - public class LoadLocalIndexDescriptionTask extends AsyncTask { - - @Override - protected GpxInfo[] doInBackground(GpxInfo... params) { - for (GpxInfo i : params) { - i.updateGpxInfo(getMyApplication()); - } - return params; - } - - @Override - protected void onPreExecute() { - showProgressBar(); - } - - @Override - protected void onProgressUpdate(GpxInfo... values) { - allGpxAdapter.notifyDataSetChanged(); - } - - @Override - protected void onPostExecute(GpxInfo[] result) { - hideProgressBar(); - allGpxAdapter.notifyDataSetChanged(); - - } - - } - public class DeleteGpxTask extends AsyncTask { @Override @@ -1128,7 +1118,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { protected String doInBackground(GpxInfo... params) { for (GpxInfo info : params) { if (!isCancelled()) { - info.updateGpxInfo(getMyApplication()); + if(!info.currentlyRecordingTrack) { + info.setGpx(GPXUtilities.loadGPXFile(app, info.file)); + } publishProgress(info); } } @@ -1165,42 +1157,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { } } - private void loadGpxAsync(GpxInfo info, boolean isSelected) { - final boolean selected = isSelected; - new AsyncTask() { - GpxInfo info; - - @Override - protected Void doInBackground(GpxInfo... params) { - if (params == null) { - return null; - } - info = params[0]; - params[0].updateGpxInfo(getMyApplication()); - return null; - } - - @Override - protected void onProgressUpdate(Void... values) { - } - - @Override - protected void onPreExecute() { - getActivity().setProgressBarIndeterminateVisibility(true); - } - - @Override - protected void onPostExecute(Void result) { - if (getActivity() != null) { - getActivity().setProgressBarIndeterminateVisibility(false); - } - if (info.gpx != null) { - getMyApplication().getSelectedGpxHelper().selectGpxFile(info.gpx, selected, true); - allGpxAdapter.notifyDataSetChanged(); - } - } - }.execute(info); - } private class SearchFilter extends Filter { @@ -1212,7 +1168,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { results.values = raw; results.count = 1; } else { - String cs = constraint.toString().toLowerCase(); + String cs = constraint.toString(); List res = new ArrayList<>(); for (GpxInfo r : raw) { if (r.getName().toLowerCase().indexOf(cs) != -1) { @@ -1248,9 +1204,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { @Override public void onDestroy() { super.onDestroy(); - if (descriptionLoader != null) { - descriptionLoader.cancel(true); - } if (asyncLoader != null) { asyncLoader.cancel(true); } @@ -1296,11 +1249,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { private String name = null; private int sz = -1; private String fileName = null; - private String description; private boolean corrupted; - private boolean expanded; - private Spanned htmlDescription; - private GPXUtilities.GPXTrackAnalysis analysis; public GpxInfo() { } @@ -1339,21 +1288,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { return sz; } - public boolean isExpanded() { - return expanded; - } - - public void setExpanded(boolean expanded) { - this.expanded = expanded; - } - - public CharSequence getDescription() { - if (description == null) { - return ""; - } - return description; - } - public long getFileDate() { if (file == null) { return 0; @@ -1361,42 +1295,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { return file.lastModified(); } - public Spanned getHtmlDescription() { - if (htmlDescription != null) { - return htmlDescription; - } - htmlDescription = Html.fromHtml(getDescription().toString().replace("\n", "
")); - return htmlDescription; - } - - public GPXUtilities.GPXTrackAnalysis getAnalysis() { - return analysis; - } - - public void setAnalysis(GPXUtilities.GPXTrackAnalysis analysis) { - this.analysis = analysis; - } - public void setGpx(GPXFile gpx) { this.gpx = gpx; } - public void updateGpxInfo(OsmandApplication app) { - if (gpx == null) { - gpx = GPXUtilities.loadGPXFile(app, file); - } - if (gpx.warning != null) { - corrupted = true; - description = gpx.warning; - analysis = null; - } else { - // 'Long-press for options' message - analysis = gpx.getAnalysis(file.lastModified()); - description = GpxUiHelper.getDescription(app, analysis, true); - } - htmlDescription = null; - getHtmlDescription(); - } public String getFileName() { if (fileName != null) { @@ -1465,30 +1367,25 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { TextView distance = (TextView) v.findViewById(R.id.distance); TextView pointsCount = (TextView) v.findViewById(R.id.points_count); pointsCount.setText(analysis.wptPoints + ""); - if (analysis.totalDistanceMoving != 0) { - distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistanceMoving, app)); - } else { +// if (analysis.totalDistanceMoving != 0) { +// distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistanceMoving, app)); +// } else { distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app)); - } +// } if (analysis.isTimeSpecified()) { - if (analysis.isTimeMoving()) { - time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + ""); - } else { +// if (analysis.isTimeMoving()) { +// time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + ""); +// } else { time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000)) + ""); - } +// } } else { time.setText(""); } } TextView descr = ((TextView) v.findViewById(R.id.description)); - if (child.isExpanded()) { - descr.setVisibility(View.VISIBLE); - descr.setText(child.getHtmlDescription()); - } else { - descr.setVisibility(View.GONE); - } + descr.setVisibility(View.GONE); v.findViewById(R.id.check_item).setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java index fe1e52ba03..3cf8665ff4 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java @@ -20,6 +20,7 @@ import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -90,7 +91,8 @@ public class SelectedGPXFragment extends ListFragment { @Override public void run() { if (updateEnable) { - adapter.notifyDataSetInvalidated(); + updateContent(); + adapter.notifyDataSetChanged(); startHandler(); } } @@ -121,16 +123,13 @@ public class SelectedGPXFragment extends ListFragment { - private GPXFile getGpx() { - return ((TrackActivity) getActivity()).getResult(); - } - protected List filterGroups(GpxDisplayItemType type) { - List groups = new ArrayList(); - for(GpxDisplayGroup group : ((TrackActivity) getActivity()).getContent()) { + List result = ((TrackActivity)getActivity()).getResult(); + List groups = new ArrayList(); + for (GpxDisplayGroup group : result) { boolean add = group.getType() == type || type == null; - if (isArgumentTrue(ARG_TO_FILTER_SHORT_TRACKS)) { + if (isArgumentTrue(ARG_TO_FILTER_SHORT_TRACKS)) { Iterator item = group.getModifiableList().iterator(); while (item.hasNext()) { GpxDisplayItem it2 = item.next(); @@ -141,11 +140,11 @@ public class SelectedGPXFragment extends ListFragment { if (group.getModifiableList().isEmpty()) { add = false; } - } - if(add) { - groups.add(group); - } - + } + if (add) { + groups.add(group); + } + } return groups; } @@ -161,6 +160,7 @@ public class SelectedGPXFragment extends ListFragment { adapter.clear(); List groups = filterGroups(filterType()); adapter.addAll(flatten(groups)); + adapter.notifyDataSetChanged(); } protected GpxDisplayItemType filterType() { @@ -276,7 +276,7 @@ public class SelectedGPXFragment extends ListFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); ((TrackActivity) getActivity()).getClearToolbar(false); - if (getGpx().path != null) { + if (getGpx().path != null && !getGpx().showCurrentTrack) { MenuItem item = menu.add(R.string.share_fav).setIcon(R.drawable.ic_action_gshare_dark) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override @@ -294,6 +294,10 @@ public class SelectedGPXFragment extends ListFragment { } + protected GPXFile getGpx() { + return ((TrackActivity)getActivity()).getGpx(); + } + protected void selectSplitDistance() { final List groups = filterGroups(GpxDisplayItemType.TRACK_SEGMENT); if(groups.size() == 0) { @@ -343,8 +347,9 @@ public class SelectedGPXFragment extends ListFragment { @Override public void onClick(DialogInterface dialog, int which) { - app.getSelectedGpxHelper().selectGpxFile(groups.get(0).getGpx(), vis.isChecked(), true); - updateSplit(groups, distanceSplit, timeSplit, sp.getSelectedItemPosition() ); + SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(groups.get(0).getGpx(), vis.isChecked(), true); + updateSplit(groups, distanceSplit, timeSplit, sp.getSelectedItemPosition(), + vis.isChecked() ? sf : null); } }); @@ -353,12 +358,14 @@ public class SelectedGPXFragment extends ListFragment { } private void updateSplit(final List groups, final List distanceSplit, - final TIntArrayList timeSplit, final int which) { + final TIntArrayList timeSplit, final int which, final SelectedGpxFile sf) { new AsyncTask() { protected void onPostExecute(Void result) { + if(sf != null) { + sf.setDisplayGroups(filterGroups(null)); + } updateContent(); - adapter.notifyDataSetChanged(); (getActivity()).setProgressBarIndeterminateVisibility(false); } @@ -377,6 +384,7 @@ public class SelectedGPXFragment extends ListFragment { model.splitByTime(app, timeSplit.get(which)); } } + return null; } }.execute((Void)null); diff --git a/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java b/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java index 5a9de3bcdd..886bdcb82c 100644 --- a/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/skimapsplugin/SkiMapsPlugin.java @@ -40,9 +40,6 @@ public class SkiMapsPlugin extends OsmandPlugin { @Override public boolean init(final OsmandApplication app, final Activity activity) { - if(true) { - throw new IllegalStateException("Don't enable plugin!"); - } if(activity != null) { // called from UI previousRenderer = app.getSettings().RENDERER.get();