From b8bef71db70e50033f6f2c3b1dea006bc74d2893 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 30 May 2018 21:56:46 +0300 Subject: [PATCH] Added show on map checkbox to points fragment --- OsmAnd/res/layout/gpx_item_list_header.xml | 10 +++++ .../net/osmand/plus/GpxSelectionHelper.java | 6 ++- .../osmand/plus/activities/TrackActivity.java | 14 ++++++ .../TrackActivityFragmentAdapter.java | 43 ++++++++++++------- .../plus/myplaces/TrackPointFragment.java | 6 +++ .../plus/myplaces/TrackSegmentFragment.java | 2 +- 6 files changed, 63 insertions(+), 18 deletions(-) diff --git a/OsmAnd/res/layout/gpx_item_list_header.xml b/OsmAnd/res/layout/gpx_item_list_header.xml index 376ce670ed..cf4990ba48 100644 --- a/OsmAnd/res/layout/gpx_item_list_header.xml +++ b/OsmAnd/res/layout/gpx_item_list_header.xml @@ -180,4 +180,14 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index fb843bbf35..bd08eb16d7 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -244,7 +244,10 @@ public class GpxSelectionHelper { return dg; } - private static void processGroupTrack(OsmandApplication app, GpxDisplayGroup group) { + private static void processGroupTrack(@NonNull OsmandApplication app, @NonNull GpxDisplayGroup group) { + if (group.track == null) { + return; + } List list = group.getModifiableList(); String timeSpanClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_time_span_color)); String speedClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_speed)); @@ -252,7 +255,6 @@ public class GpxSelectionHelper { String descClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_altitude_desc)); String distanceClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_distance_color)); final float eleThreshold = 3; -// int t = 1; for (TrkSegment r : group.track.segments) { if (r.points.size() == 0) { continue; diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index ff6b70beab..4e42e4dbee 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -34,6 +34,7 @@ import net.osmand.plus.R; import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.SplitSegmentDialogFragment; +import net.osmand.plus.myplaces.TrackActivityFragmentAdapter; import net.osmand.plus.myplaces.TrackBitmapDrawer; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.myplaces.TrackPointFragment; @@ -321,6 +322,19 @@ public class TrackActivity extends TabActivity { } } + public void updateHeader(Fragment sender) { + for (WeakReference f : fragList) { + Fragment frag = f.get(); + if (frag != sender) { + if (frag instanceof TrackSegmentFragment) { + ((TrackSegmentFragment) frag).updateHeader(); + } else if (frag instanceof TrackPointFragment) { + ((TrackPointFragment) frag).updateHeader(); + } + } + } + } + @Override public void onBackPressed() { if (openTracksList) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 72316fa1fb..bacab3e9a0 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -276,13 +276,14 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { final View splitIntervalView = headerView.findViewById(R.id.split_interval_view); final View colorView = headerView.findViewById(R.id.color_view); vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle); + final View bottomDivider = headerView.findViewById(R.id.bottom_divider); GPXFile gpxFile = getGpx(); boolean gpxFileSelected = isGpxFileSelected(gpxFile); boolean hasPath = gpxFile != null && (gpxFile.tracks.size() > 0 || gpxFile.routes.size() > 0); TrackActivity activity = getTrackActivity(); TrackBitmapDrawer trackDrawer = getTrackBitmapDrawer(); - if (activity != null && trackDrawer!= null) { + if (activity != null && trackDrawer != null) { if (trackDrawer.isNonInitialized()) { if (trackDrawer.initAndDraw()) { imageView.setVisibility(View.VISIBLE); @@ -294,21 +295,33 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } } - if (showMapOnly) { - headerView.findViewById(R.id.track_settings_view).setVisibility(View.GONE); - } else { - vis.setChecked(gpxFileSelected); - vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (!isChecked) { - selectedSplitInterval = 0; - } - setTrackVisibilityOnMap(vis.isChecked()); + vis.setChecked(gpxFileSelected); + vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (!isChecked) { + selectedSplitInterval = 0; + } + setTrackVisibilityOnMap(vis.isChecked()); + if (!showMapOnly) { updateSplitIntervalView(splitIntervalView); updateColorView(colorView); } - }); + TrackActivity trackActivity = getTrackActivity(); + if (trackActivity != null) { + trackActivity.updateHeader(fragment); + } + } + }); + + if (showMapOnly) { + splitIntervalView.setVisibility(View.GONE); + splitColorView.setVisibility(View.GONE); + divider.setVisibility(View.GONE); + bottomDivider.setVisibility(View.VISIBLE); + } else { + bottomDivider.setVisibility(View.GONE); + updateColorView(colorView); colorView.setOnClickListener(new View.OnClickListener() { @Override @@ -411,8 +424,8 @@ 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)); + ((gpxFile.showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) || + (gpxFile.path != null && app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path) != null)); } private void setTrackVisibilityOnMap(boolean visible) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 6de0b860ee..b83c9795b3 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -675,6 +675,12 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements } } + public void updateHeader() { + if (fragmentAdapter != null) { + fragmentAdapter.updateHeader(0); + } + } + class PointGPXAdapter extends OsmandBaseExpandableListAdapter implements Filterable { Map> itemGroups = new LinkedHashMap<>(); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 39850f31be..25711761bc 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -253,7 +253,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit } } - private void updateHeader() { + public void updateHeader() { if (fragmentAdapter != null) { fragmentAdapter.updateHeader(adapter.getCount()); }