From abbc0fe2ee465d2dcf0c5016b34564ce926e5941 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 30 May 2018 19:26:11 +0300 Subject: [PATCH] Fix show/hide track from map --- .../osmand/plus/activities/TrackActivity.java | 11 ++- .../TrackActivityFragmentAdapter.java | 76 +++++++++++-------- 2 files changed, 54 insertions(+), 33 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index 0df1d42f74..ff6b70beab 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -51,6 +51,7 @@ public class TrackActivity extends TabActivity { public static final String OPEN_POINTS_TAB = "OPEN_POINTS_TAB"; public static final String OPEN_TRACKS_LIST = "OPEN_TRACKS_LIST"; public static final String CURRENT_RECORDING = "CURRENT_RECORDING"; + public static final String SHOW_TEMPORARILY = "SHOW_TEMPORARILY"; protected List> fragList = new ArrayList<>(); private OsmandApplication app; private TrackBitmapDrawer trackBitmapDrawer; @@ -440,6 +441,7 @@ public class TrackActivity extends TabActivity { private OsmandApplication app; private WeakReference activityRef; private File file; + private boolean showTemporarily; private TrackActivity getTrackActivity() { return activityRef.get(); @@ -455,6 +457,11 @@ public class TrackActivity extends TabActivity { TrackActivity activity = getTrackActivity(); if (activity != null) { activity.setSupportProgressBarIndeterminateVisibility(true); + Intent intent = activity.getIntent(); + if (intent != null && intent.hasExtra(SHOW_TEMPORARILY)) { + showTemporarily = true; + intent.removeExtra(SHOW_TEMPORARILY); + } } } @@ -491,7 +498,9 @@ public class TrackActivity extends TabActivity { TrackActivity activity = getTrackActivity(); if (activity != null) { activity.setSupportProgressBarIndeterminateVisibility(false); - + if (showTemporarily && result != null) { + app.getSelectedGpxHelper().selectGpxFile(result, false, false); + } if (!activity.stopped) { activity.onGPXFileReady(result); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 5724d816d9..288b5be08f 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -1,6 +1,7 @@ package net.osmand.plus.myplaces; import android.content.Context; +import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.os.AsyncTask; @@ -36,6 +37,7 @@ import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; 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.OsmandSettings; @@ -238,10 +240,19 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { GPXFile gpx = getGpx(); WptPt pointToShow = gpx != null ? gpx.findPointToShow() : null; if (activity != null && pointToShow != null) { + boolean gpxFileSelected = isGpxFileSelected(gpx); + if (!gpxFileSelected) { + Intent intent = activity.getIntent(); + if (intent != null) { + intent.putExtra(TrackActivity.SHOW_TEMPORARILY, true); + } + } + setTrackVisibilityOnMap(true); + LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude()); final OsmandSettings settings = app.getSettings(); - String trackName = ""; + String trackName; if (gpx.showCurrentTrack) { trackName = app.getString(R.string.shared_string_currently_recording_track); } else if (gpxDataItem != null) { @@ -266,9 +277,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { final View colorView = headerView.findViewById(R.id.color_view); vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle); GPXFile gpxFile = getGpx(); - final boolean selected = gpxFile != null && - ((gpxFile.showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) || - (gpxFile.path != null && app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path) != null)); + boolean gpxFileSelected = isGpxFileSelected(gpxFile); boolean hasPath = gpxFile != null && (gpxFile.tracks.size() > 0 || gpxFile.routes.size() > 0); TrackActivity activity = getTrackActivity(); @@ -288,24 +297,14 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { if (showMapOnly) { headerView.findViewById(R.id.track_settings_view).setVisibility(View.GONE); } else { - vis.setChecked(selected); + vis.setChecked(gpxFileSelected); vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!isChecked) { selectedSplitInterval = 0; } - GPXFile gpxFile = getGpx(); - if (gpxFile != null) { - GpxSelectionHelper.SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false); - final List groups = getDisplayGroups(); - if (groups.size() > 0) { - updateSplit(groups, vis.isChecked() ? sf : null); - if (getGpxDataItem() != null) { - updateSplitInDatabase(); - } - } - } + setTrackVisibilityOnMap(vis.isChecked()); updateSplitIntervalView(splitIntervalView); updateColorView(colorView); } @@ -338,7 +337,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { int clr = item.getColor(); if (vis.isChecked()) { if (gpx != null) { - GpxSelectionHelper.SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, vis.isChecked(), false); + SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, vis.isChecked(), false); if (clr != 0 && sf.getModifiableGpxFile() != null) { sf.getModifiableGpxFile().setColor(clr); if (getGpxDataItem() != null) { @@ -388,17 +387,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { selectedSplitInterval = position; - GPXFile gpx = getGpx(); - if (gpx != null) { - GpxSelectionHelper.SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, vis.isChecked(), false); - final List groups = getDisplayGroups(); - if (groups.size() > 0) { - updateSplit(groups, vis.isChecked() ? sf : null); - if (getGpxDataItem() != null) { - updateSplitInDatabase(); - } - } - } + setTrackVisibilityOnMap(vis.isChecked()); splitListPopupWindow.dismiss(); updateSplitIntervalView(splitIntervalView); } @@ -420,6 +409,29 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } } + private boolean isGpxFileSelected(GPXFile gpxFile) { + return gpxFile != null && + ((gpxFile.showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) || + (gpxFile.path != null && app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path) != null)); + } + + private void setTrackVisibilityOnMap(boolean visible) { + GPXFile gpxFile = getGpx(); + if (gpxFile != null) { + GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper(); + SelectedGpxFile sf = gpxHelper.selectGpxFile(gpxFile, visible, false); + if (gpxFile.hasTrkPt()) { + List groups = getDisplayGroups(); + if (groups.size() > 0) { + updateSplit(groups, visible ? sf : null); + if (getGpxDataItem() != null) { + updateSplitInDatabase(); + } + } + } + } + } + @Nullable private QuadRect getRect() { TrackActivity activity = getTrackActivity(); @@ -574,7 +586,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { addOptionSplit(3600, false, groups); } - private void updateSplit(@NonNull List groups, @Nullable GpxSelectionHelper.SelectedGpxFile sf) { + private void updateSplit(@NonNull List groups, @Nullable SelectedGpxFile sf) { TrackActivity activity = getTrackActivity(); if (activity != null) { new SplitTrackAsyncTask(activity, this, sf, groups) @@ -629,7 +641,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { public void updateSplitView() { GPXFile gpxFile = getGpx(); if (gpxFile != null) { - GpxSelectionHelper.SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, + SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, ((SwitchCompat) headerView.findViewById(R.id.showOnMapToggle)).isChecked(), false); final List groups = getDisplayGroups(); if (groups.size() > 0) { @@ -749,7 +761,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } private static class SplitTrackAsyncTask extends AsyncTask { - private final GpxSelectionHelper.SelectedGpxFile selectedGpx; + private final SelectedGpxFile selectedGpx; private OsmandApplication app; private final WeakReference activityRef; private final WeakReference fragmentAdapterRef; @@ -761,7 +773,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { SplitTrackAsyncTask(@NonNull TrackActivity activity, @NonNull TrackActivityFragmentAdapter fragmentAdapter, - @Nullable GpxSelectionHelper.SelectedGpxFile selectedGpx, + @Nullable SelectedGpxFile selectedGpx, @NonNull List groups) { activityRef = new WeakReference<>(activity); fragmentAdapterRef = new WeakReference<>(fragmentAdapter);