Fix show/hide track from map

This commit is contained in:
Alexey Kulish 2018-05-30 19:26:11 +03:00
parent 86665945be
commit abbc0fe2ee
2 changed files with 54 additions and 33 deletions

View file

@ -51,6 +51,7 @@ public class TrackActivity extends TabActivity {
public static final String OPEN_POINTS_TAB = "OPEN_POINTS_TAB"; public static final String OPEN_POINTS_TAB = "OPEN_POINTS_TAB";
public static final String OPEN_TRACKS_LIST = "OPEN_TRACKS_LIST"; public static final String OPEN_TRACKS_LIST = "OPEN_TRACKS_LIST";
public static final String CURRENT_RECORDING = "CURRENT_RECORDING"; public static final String CURRENT_RECORDING = "CURRENT_RECORDING";
public static final String SHOW_TEMPORARILY = "SHOW_TEMPORARILY";
protected List<WeakReference<Fragment>> fragList = new ArrayList<>(); protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
private OsmandApplication app; private OsmandApplication app;
private TrackBitmapDrawer trackBitmapDrawer; private TrackBitmapDrawer trackBitmapDrawer;
@ -440,6 +441,7 @@ public class TrackActivity extends TabActivity {
private OsmandApplication app; private OsmandApplication app;
private WeakReference<TrackActivity> activityRef; private WeakReference<TrackActivity> activityRef;
private File file; private File file;
private boolean showTemporarily;
private TrackActivity getTrackActivity() { private TrackActivity getTrackActivity() {
return activityRef.get(); return activityRef.get();
@ -455,6 +457,11 @@ public class TrackActivity extends TabActivity {
TrackActivity activity = getTrackActivity(); TrackActivity activity = getTrackActivity();
if (activity != null) { if (activity != null) {
activity.setSupportProgressBarIndeterminateVisibility(true); 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(); TrackActivity activity = getTrackActivity();
if (activity != null) { if (activity != null) {
activity.setSupportProgressBarIndeterminateVisibility(false); activity.setSupportProgressBarIndeterminateVisibility(false);
if (showTemporarily && result != null) {
app.getSelectedGpxHelper().selectGpxFile(result, false, false);
}
if (!activity.stopped) { if (!activity.stopped) {
activity.onGPXFileReady(result); activity.onGPXFileReady(result);
} }

View file

@ -1,6 +1,7 @@
package net.osmand.plus.myplaces; package net.osmand.plus.myplaces;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -36,6 +37,7 @@ import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -238,10 +240,19 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
GPXFile gpx = getGpx(); GPXFile gpx = getGpx();
WptPt pointToShow = gpx != null ? gpx.findPointToShow() : null; WptPt pointToShow = gpx != null ? gpx.findPointToShow() : null;
if (activity != null && pointToShow != 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(), LatLon location = new LatLon(pointToShow.getLatitude(),
pointToShow.getLongitude()); pointToShow.getLongitude());
final OsmandSettings settings = app.getSettings(); final OsmandSettings settings = app.getSettings();
String trackName = ""; String trackName;
if (gpx.showCurrentTrack) { if (gpx.showCurrentTrack) {
trackName = app.getString(R.string.shared_string_currently_recording_track); trackName = app.getString(R.string.shared_string_currently_recording_track);
} else if (gpxDataItem != null) { } else if (gpxDataItem != null) {
@ -266,9 +277,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
final View colorView = headerView.findViewById(R.id.color_view); final View colorView = headerView.findViewById(R.id.color_view);
vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle); vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle);
GPXFile gpxFile = getGpx(); GPXFile gpxFile = getGpx();
final boolean selected = gpxFile != null && boolean gpxFileSelected = isGpxFileSelected(gpxFile);
((gpxFile.showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) ||
(gpxFile.path != null && app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path) != null));
boolean hasPath = gpxFile != null && (gpxFile.tracks.size() > 0 || gpxFile.routes.size() > 0); boolean hasPath = gpxFile != null && (gpxFile.tracks.size() > 0 || gpxFile.routes.size() > 0);
TrackActivity activity = getTrackActivity(); TrackActivity activity = getTrackActivity();
@ -288,24 +297,14 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
if (showMapOnly) { if (showMapOnly) {
headerView.findViewById(R.id.track_settings_view).setVisibility(View.GONE); headerView.findViewById(R.id.track_settings_view).setVisibility(View.GONE);
} else { } else {
vis.setChecked(selected); vis.setChecked(gpxFileSelected);
vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isChecked) { if (!isChecked) {
selectedSplitInterval = 0; selectedSplitInterval = 0;
} }
GPXFile gpxFile = getGpx(); setTrackVisibilityOnMap(vis.isChecked());
if (gpxFile != null) {
GpxSelectionHelper.SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false);
final List<GpxDisplayGroup> groups = getDisplayGroups();
if (groups.size() > 0) {
updateSplit(groups, vis.isChecked() ? sf : null);
if (getGpxDataItem() != null) {
updateSplitInDatabase();
}
}
}
updateSplitIntervalView(splitIntervalView); updateSplitIntervalView(splitIntervalView);
updateColorView(colorView); updateColorView(colorView);
} }
@ -338,7 +337,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
int clr = item.getColor(); int clr = item.getColor();
if (vis.isChecked()) { if (vis.isChecked()) {
if (gpx != null) { 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) { if (clr != 0 && sf.getModifiableGpxFile() != null) {
sf.getModifiableGpxFile().setColor(clr); sf.getModifiableGpxFile().setColor(clr);
if (getGpxDataItem() != null) { if (getGpxDataItem() != null) {
@ -388,17 +387,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectedSplitInterval = position; selectedSplitInterval = position;
GPXFile gpx = getGpx(); setTrackVisibilityOnMap(vis.isChecked());
if (gpx != null) {
GpxSelectionHelper.SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, vis.isChecked(), false);
final List<GpxDisplayGroup> groups = getDisplayGroups();
if (groups.size() > 0) {
updateSplit(groups, vis.isChecked() ? sf : null);
if (getGpxDataItem() != null) {
updateSplitInDatabase();
}
}
}
splitListPopupWindow.dismiss(); splitListPopupWindow.dismiss();
updateSplitIntervalView(splitIntervalView); 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<GpxDisplayGroup> groups = getDisplayGroups();
if (groups.size() > 0) {
updateSplit(groups, visible ? sf : null);
if (getGpxDataItem() != null) {
updateSplitInDatabase();
}
}
}
}
}
@Nullable @Nullable
private QuadRect getRect() { private QuadRect getRect() {
TrackActivity activity = getTrackActivity(); TrackActivity activity = getTrackActivity();
@ -574,7 +586,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
addOptionSplit(3600, false, groups); addOptionSplit(3600, false, groups);
} }
private void updateSplit(@NonNull List<GpxDisplayGroup> groups, @Nullable GpxSelectionHelper.SelectedGpxFile sf) { private void updateSplit(@NonNull List<GpxDisplayGroup> groups, @Nullable SelectedGpxFile sf) {
TrackActivity activity = getTrackActivity(); TrackActivity activity = getTrackActivity();
if (activity != null) { if (activity != null) {
new SplitTrackAsyncTask(activity, this, sf, groups) new SplitTrackAsyncTask(activity, this, sf, groups)
@ -629,7 +641,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
public void updateSplitView() { public void updateSplitView() {
GPXFile gpxFile = getGpx(); GPXFile gpxFile = getGpx();
if (gpxFile != null) { if (gpxFile != null) {
GpxSelectionHelper.SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile,
((SwitchCompat) headerView.findViewById(R.id.showOnMapToggle)).isChecked(), false); ((SwitchCompat) headerView.findViewById(R.id.showOnMapToggle)).isChecked(), false);
final List<GpxDisplayGroup> groups = getDisplayGroups(); final List<GpxDisplayGroup> groups = getDisplayGroups();
if (groups.size() > 0) { if (groups.size() > 0) {
@ -749,7 +761,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
} }
private static class SplitTrackAsyncTask extends AsyncTask<Void, Void, Void> { private static class SplitTrackAsyncTask extends AsyncTask<Void, Void, Void> {
private final GpxSelectionHelper.SelectedGpxFile selectedGpx; private final SelectedGpxFile selectedGpx;
private OsmandApplication app; private OsmandApplication app;
private final WeakReference<TrackActivity> activityRef; private final WeakReference<TrackActivity> activityRef;
private final WeakReference<TrackActivityFragmentAdapter> fragmentAdapterRef; private final WeakReference<TrackActivityFragmentAdapter> fragmentAdapterRef;
@ -761,7 +773,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
SplitTrackAsyncTask(@NonNull TrackActivity activity, SplitTrackAsyncTask(@NonNull TrackActivity activity,
@NonNull TrackActivityFragmentAdapter fragmentAdapter, @NonNull TrackActivityFragmentAdapter fragmentAdapter,
@Nullable GpxSelectionHelper.SelectedGpxFile selectedGpx, @Nullable SelectedGpxFile selectedGpx,
@NonNull List<GpxDisplayGroup> groups) { @NonNull List<GpxDisplayGroup> groups) {
activityRef = new WeakReference<>(activity); activityRef = new WeakReference<>(activity);
fragmentAdapterRef = new WeakReference<>(fragmentAdapter); fragmentAdapterRef = new WeakReference<>(fragmentAdapter);