From 0c0d90d42cb21bfe4e98fb273de7d58764748875 Mon Sep 17 00:00:00 2001 From: Skalii Date: Tue, 9 Feb 2021 18:14:31 +0200 Subject: [PATCH 1/4] fix changing track info after enabling the "Join segments" option; fix display track info with enabled/disabled "Join segments" option in chart; --- .../other/TrackDetailsMenu.java | 21 ++- .../plus/track/GpxBlockStatisticsBuilder.java | 121 +++++++++--------- .../net/osmand/plus/track/OverviewCard.java | 5 +- .../osmand/plus/track/TrackMenuFragment.java | 7 +- 4 files changed, 83 insertions(+), 71 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index edec4eeb2f..e0efd25a7e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -36,6 +36,7 @@ import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -66,6 +67,8 @@ public class TrackDetailsMenu { @Nullable private GpxDisplayItem gpxItem; @Nullable + private SelectedGpxFile selectedGpxFile; + @Nullable private TrackDetailsBarController toolbarController; @Nullable private TrkSegment segment; @@ -101,6 +104,15 @@ public class TrackDetailsMenu { this.gpxItem = gpxItem; } + @Nullable + public SelectedGpxFile getSelectedGpxFile() { + return selectedGpxFile; + } + + public void setSelectedGpxFile(@NonNull SelectedGpxFile selectedGpxFile) { + this.selectedGpxFile = selectedGpxFile; + } + public boolean isVisible() { return visible; } @@ -539,7 +551,7 @@ public class TrackDetailsMenu { } } - public boolean shouldShowXAxisPoints () { + public boolean shouldShowXAxisPoints() { return true; } @@ -707,18 +719,19 @@ public class TrackDetailsMenu { if (gpxItem.chartTypes != null && gpxItem.chartTypes.length > 0) { for (int i = 0; i < gpxItem.chartTypes.length; i++) { OrderedLineDataSet dataSet = null; + boolean withoutGaps = selectedGpxFile != null && (!selectedGpxFile.isJoinSegments() && gpxItem.isGeneralTrack()); switch (gpxItem.chartTypes[i]) { case ALTITUDE: dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis, - gpxItem.chartAxisType, false, true, false); + gpxItem.chartAxisType, false, true, withoutGaps); break; case SPEED: dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis, - gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true, false); + gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true, withoutGaps); break; case SLOPE: dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis, - gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true, false); + gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true, withoutGaps); break; } if (dataSet != null) { diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index 59cd460bcc..b6f07ecf50 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -17,16 +17,16 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; -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.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.widgets.TextViewEx; @@ -40,51 +40,60 @@ public class GpxBlockStatisticsBuilder { private final OsmandApplication app; private RecyclerView blocksView; private final SelectedGpxFile selectedGpxFile; - private final TrackDisplayHelper displayHelper; - private final GpxDisplayItemType[] filterTypes = {GpxDisplayItemType.TRACK_SEGMENT}; - public GpxBlockStatisticsBuilder(OsmandApplication app, SelectedGpxFile selectedGpxFile, TrackDisplayHelper displayHelper) { + public GpxBlockStatisticsBuilder(OsmandApplication app, SelectedGpxFile selectedGpxFile) { this.app = app; this.selectedGpxFile = selectedGpxFile; - this.displayHelper = displayHelper; } public void setBlocksView(RecyclerView blocksView) { this.blocksView = blocksView; } - private GPXTrackAnalysis getAnalysis() { - return selectedGpxFile.getTrackAnalysis(app); + private GpxDisplayItem getDisplayItem(GPXFile gpxFile) { + return GpxUiHelper.makeGpxDisplayItem(app, gpxFile); + } + + private GPXFile getGPXFile() { + return selectedGpxFile.getGpxFile(); } public void initStatBlocks(SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { - GPXTrackAnalysis analysis = getAnalysis(); - float totalDistance = analysis.totalDistance; - float timeSpan = analysis.timeSpan; - String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); - String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app); - String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); - String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); List items = new ArrayList<>(); + GPXFile gpxFile = getGPXFile(); + GpxDisplayItem gpxDisplayItem = null; + GPXTrackAnalysis analysis = null; + if (gpxFile.tracks.size() > 0) { + gpxDisplayItem = getDisplayItem(gpxFile); + analysis = gpxDisplayItem.analysis; + } + if (gpxDisplayItem != null && analysis != null) { + boolean withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack(); + float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; + float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan; + String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); + String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app); + String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); + String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); - prepareData(analysis, items, app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), - R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED, ItemType.ITEM_DISTANCE); - prepareData(analysis, items, app.getString(R.string.altitude_ascent), asc, - R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null, ItemType.ITEM_ALTITUDE); - prepareData(analysis, items, app.getString(R.string.altitude_descent), desc, - R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE, ItemType.ITEM_ALTITUDE); - prepareData(analysis, items, app.getString(R.string.average_speed), avg, - R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); - prepareData(analysis, items, app.getString(R.string.max_speed), max, - R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); - prepareData(analysis, items, app.getString(R.string.shared_string_time_span), - Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()), - R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_TIME); - - if (Algorithms.isEmpty(items)) { - AndroidUiHelper.updateVisibility(blocksView, false); - } else { - final BlockStatisticsAdapter sbAdapter = new BlockStatisticsAdapter(items, actionsListener, activeColor, nightMode); + prepareData(analysis, items, app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), + R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED, ItemType.ITEM_DISTANCE); + prepareData(analysis, items, app.getString(R.string.altitude_ascent), asc, + R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null, ItemType.ITEM_ALTITUDE); + prepareData(analysis, items, app.getString(R.string.altitude_descent), desc, + R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE, ItemType.ITEM_ALTITUDE); + prepareData(analysis, items, app.getString(R.string.average_speed), avg, + R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); + prepareData(analysis, items, app.getString(R.string.max_speed), max, + R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); + prepareData(analysis, items, app.getString(R.string.shared_string_time_span), + Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()), + R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_TIME); + } + boolean isNotEmpty = !Algorithms.isEmpty(items); + AndroidUiHelper.updateVisibility(blocksView, isNotEmpty); + if (isNotEmpty && gpxDisplayItem != null) { + final BlockStatisticsAdapter sbAdapter = new BlockStatisticsAdapter(items, gpxDisplayItem, actionsListener, activeColor, nightMode); blocksView.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false)); blocksView.setAdapter(sbAdapter); } @@ -134,7 +143,6 @@ public class GpxBlockStatisticsBuilder { } public class StatBlock { - private final String title; private final String value; private final int imageResId; @@ -164,14 +172,17 @@ public class GpxBlockStatisticsBuilder { private class BlockStatisticsAdapter extends RecyclerView.Adapter { + private final List statBlocks; + private final GpxDisplayItem displayItem; + private final SegmentActionsListener actionsListener; @ColorInt private final int activeColor; - private final List statBlocks; private final boolean nightMode; - private final SegmentActionsListener actionsListener; - public BlockStatisticsAdapter(List statBlocks, SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { + public BlockStatisticsAdapter(List statBlocks, GpxDisplayItem displayItem, + SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { this.statBlocks = statBlocks; + this.displayItem = displayItem; this.actionsListener = actionsListener; this.activeColor = activeColor; this.nightMode = nightMode; @@ -200,32 +211,20 @@ public class GpxBlockStatisticsBuilder { holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - List groups = displayHelper.getDisplayGroups(filterTypes); - GpxDisplayGroup group = null; - for (GpxDisplayGroup g : groups) { - if (g.isGeneralTrack()) { - group = g; - } - } - if (group == null && !groups.isEmpty()) { - group = groups.get(0); - } - if (group != null) { - GpxDisplayItem displayItem = group.getModifiableList().get(0); - if (displayItem != null && displayItem.analysis != null) { - ArrayList list = new ArrayList<>(); - if (displayItem.analysis.hasElevationData || displayItem.analysis.isSpeedSpecified() || displayItem.analysis.hasSpeedData) { - if (item.firstType != null) { - list.add(item.firstType); - } - if (item.secondType != null) { - list.add(item.secondType); - } + GPXTrackAnalysis analysis = displayItem.analysis; + if (displayItem != null && analysis != null) { + ArrayList list = new ArrayList<>(); + if (analysis.hasElevationData || analysis.isSpeedSpecified() || analysis.hasSpeedData) { + if (item.firstType != null) { + list.add(item.firstType); + } + if (item.secondType != null) { + list.add(item.secondType); } - displayItem.chartTypes = list.size() > 0 ? list.toArray(new GPXDataSetType[0]) : null; - displayItem.locationOnMap = displayItem.locationStart; - actionsListener.openAnalyzeOnMap(displayItem); } + displayItem.chartTypes = list.size() > 0 ? list.toArray(new GPXDataSetType[0]) : null; + displayItem.locationOnMap = displayItem.locationStart; + actionsListener.openAnalyzeOnMap(displayItem); } } }); diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index d0a396499d..bb56b43f89 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -43,12 +43,11 @@ public class OverviewCard extends BaseCard { private final SelectedGpxFile selectedGpxFile; private final GpxBlockStatisticsBuilder blockStatisticsBuilder; - public OverviewCard(@NonNull MapActivity mapActivity, @NonNull TrackDisplayHelper displayHelper, - @NonNull SegmentActionsListener actionsListener, SelectedGpxFile selectedGpxFile) { + public OverviewCard(@NonNull MapActivity mapActivity, @NonNull SegmentActionsListener actionsListener, SelectedGpxFile selectedGpxFile) { super(mapActivity); this.actionsListener = actionsListener; this.selectedGpxFile = selectedGpxFile; - blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile, displayHelper); + blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile); } @Override diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index e0e196a712..ff2ec67140 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -326,7 +326,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } headerContainer.addView(overviewCard.getView()); } else { - overviewCard = new OverviewCard(getMapActivity(), displayHelper, this, selectedGpxFile); + overviewCard = new OverviewCard(getMapActivity(), this, selectedGpxFile); overviewCard.setListener(this); headerContainer.addView(overviewCard.build(getMapActivity())); } @@ -760,7 +760,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card segment = segments.get(0); } } - GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}; + GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}; List items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)); if (segment != null && !Algorithms.isEmpty(items)) { SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment); @@ -1013,6 +1013,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card public void openAnalyzeOnMap(GpxDisplayItem gpxItem) { TrackDetailsMenu trackDetailsMenu = getMapActivity().getTrackDetailsMenu(); trackDetailsMenu.setGpxItem(gpxItem); + trackDetailsMenu.setSelectedGpxFile(selectedGpxFile); trackDetailsMenu.show(); hide(); } @@ -1110,7 +1111,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override public void gpxSavingFinished(Exception errorMessage) { if (selectedGpxFile != null) { - List groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}); + List groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}); selectedGpxFile.setDisplayGroups(groups, app); selectedGpxFile.processPoints(app); } From fb3820f907f7928af27259c394475f93e2dfbeb8 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 10 Feb 2021 04:31:49 +0200 Subject: [PATCH 2/4] add ability to update data with track recording interval --- .../plus/track/GpxBlockStatisticsBuilder.java | 117 +++++++++++------- 1 file changed, 73 insertions(+), 44 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index b6f07ecf50..2f11a6136a 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -1,10 +1,10 @@ package net.osmand.plus.track; import android.graphics.drawable.Drawable; +import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.ColorInt; @@ -12,7 +12,6 @@ import androidx.annotation.ColorRes; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.appcompat.widget.AppCompatImageView; -import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -24,7 +23,6 @@ import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.UiUtilities; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; @@ -41,6 +39,13 @@ public class GpxBlockStatisticsBuilder { private RecyclerView blocksView; private final SelectedGpxFile selectedGpxFile; + private BlockStatisticsAdapter adapter; + private final List items = new ArrayList<>(); + + private final Handler handler = new Handler(); + private Runnable updatingItems; + private boolean updateRunning = false; + public GpxBlockStatisticsBuilder(OsmandApplication app, SelectedGpxFile selectedGpxFile) { this.app = app; this.selectedGpxFile = selectedGpxFile; @@ -59,7 +64,39 @@ public class GpxBlockStatisticsBuilder { } public void initStatBlocks(SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { - List items = new ArrayList<>(); + initItems(); + boolean isNotEmpty = !Algorithms.isEmpty(items); + AndroidUiHelper.updateVisibility(blocksView, isNotEmpty); + if (isNotEmpty) { + adapter = new BlockStatisticsAdapter(getDisplayItem(getGPXFile()), actionsListener, activeColor, nightMode); + adapter.setItems(items); + blocksView.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false)); + blocksView.setAdapter(adapter); + } + } + + public void stopUpdatingStatBlocks() { + handler.removeCallbacks(updatingItems); + updateRunning = false; + } + + public void runUpdatingStatBlocks() { + updatingItems = new Runnable() { + @Override + public void run() { + if (adapter != null) { + initItems(); + adapter.setItems(items); + AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items)); + } + int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get(); + handler.postDelayed(this, Math.max(1000, interval)); + } + }; + updateRunning = handler.post(updatingItems); + } + + public void initItems() { GPXFile gpxFile = getGPXFile(); GpxDisplayItem gpxDisplayItem = null; GPXTrackAnalysis analysis = null; @@ -76,72 +113,55 @@ public class GpxBlockStatisticsBuilder { String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); - prepareData(analysis, items, app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), + items.clear(); + prepareData(analysis, app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED, ItemType.ITEM_DISTANCE); - prepareData(analysis, items, app.getString(R.string.altitude_ascent), asc, + prepareData(analysis, app.getString(R.string.altitude_ascent), asc, R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null, ItemType.ITEM_ALTITUDE); - prepareData(analysis, items, app.getString(R.string.altitude_descent), desc, + prepareData(analysis, app.getString(R.string.altitude_descent), desc, R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE, ItemType.ITEM_ALTITUDE); - prepareData(analysis, items, app.getString(R.string.average_speed), avg, + prepareData(analysis, app.getString(R.string.average_speed), avg, R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); - prepareData(analysis, items, app.getString(R.string.max_speed), max, + prepareData(analysis, app.getString(R.string.max_speed), max, R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); - prepareData(analysis, items, app.getString(R.string.shared_string_time_span), + prepareData(analysis, app.getString(R.string.shared_string_time_span), Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()), R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_TIME); } - boolean isNotEmpty = !Algorithms.isEmpty(items); - AndroidUiHelper.updateVisibility(blocksView, isNotEmpty); - if (isNotEmpty && gpxDisplayItem != null) { - final BlockStatisticsAdapter sbAdapter = new BlockStatisticsAdapter(items, gpxDisplayItem, actionsListener, activeColor, nightMode); - blocksView.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false)); - blocksView.setAdapter(sbAdapter); - } } - public void prepareData(GPXTrackAnalysis analysis, List listItems, String title, - String value, @DrawableRes int imageResId, @ColorRes int imageColorId, + public void prepareData(GPXTrackAnalysis analysis, String title, String value, + @DrawableRes int imageResId, @ColorRes int imageColorId, GPXDataSetType firstType, GPXDataSetType secondType, ItemType itemType) { StatBlock statBlock = new StatBlock(title, value, imageResId, imageColorId, firstType, secondType, itemType); switch (statBlock.itemType) { case ITEM_DISTANCE: { if (analysis.totalDistance != 0f) { - listItems.add(statBlock); + items.add(statBlock); } break; } case ITEM_ALTITUDE: { if (analysis.hasElevationData) { - listItems.add(statBlock); + items.add(statBlock); } break; } case ITEM_SPEED: { if (analysis.isSpeedSpecified()) { - listItems.add(statBlock); + items.add(statBlock); } break; } case ITEM_TIME: { if (analysis.hasSpeedData) { - listItems.add(statBlock); + items.add(statBlock); } break; } } } - private void setImageDrawable(ImageView iv, @DrawableRes Integer resId, @ColorRes int color) { - Drawable icon = resId != null ? app.getUIUtilities().getIcon(resId, color) - : UiUtilities.tintDrawable(iv.getDrawable(), getResolvedColor(color)); - iv.setImageDrawable(icon); - } - - @ColorInt - protected int getResolvedColor(@ColorRes int colorId) { - return ContextCompat.getColor(app, colorId); - } - public class StatBlock { private final String title; private final String value; @@ -172,16 +192,15 @@ public class GpxBlockStatisticsBuilder { private class BlockStatisticsAdapter extends RecyclerView.Adapter { - private final List statBlocks; + private final List items = new ArrayList<>(); private final GpxDisplayItem displayItem; private final SegmentActionsListener actionsListener; @ColorInt private final int activeColor; private final boolean nightMode; - public BlockStatisticsAdapter(List statBlocks, GpxDisplayItem displayItem, - SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { - this.statBlocks = statBlocks; + public BlockStatisticsAdapter(GpxDisplayItem displayItem, SegmentActionsListener actionsListener, + @ColorInt int activeColor, boolean nightMode) { this.displayItem = displayItem; this.actionsListener = actionsListener; this.activeColor = activeColor; @@ -190,7 +209,7 @@ public class GpxBlockStatisticsBuilder { @Override public int getItemCount() { - return statBlocks.size(); + return items.size(); } @NonNull @@ -203,16 +222,19 @@ public class GpxBlockStatisticsBuilder { @Override public void onBindViewHolder(BlockStatisticsViewHolder holder, int position) { - final StatBlock item = statBlocks.get(position); + final StatBlock item = items.get(position); holder.valueText.setText(item.value); holder.titleText.setText(item.title); + if (updateRunning) { + holder.titleText.setWidth(app.getResources().getDimensionPixelSize(R.dimen.map_route_buttons_width)); + } holder.valueText.setTextColor(activeColor); holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light)); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - GPXTrackAnalysis analysis = displayItem.analysis; - if (displayItem != null && analysis != null) { + GPXTrackAnalysis analysis = displayItem != null ? displayItem.analysis : null; + if (analysis != null) { ArrayList list = new ArrayList<>(); if (analysis.hasElevationData || analysis.isSpeedSpecified() || analysis.hasSpeedData) { if (item.firstType != null) { @@ -228,9 +250,16 @@ public class GpxBlockStatisticsBuilder { } } }); - setImageDrawable(holder.imageView, item.imageResId, item.imageColorId); + Drawable icon = app.getUIUtilities().getIcon(item.imageResId, item.imageColorId); + holder.imageView.setImageDrawable(icon); AndroidUtils.setBackgroundColor(app, holder.divider, nightMode, R.color.divider_color_light, R.color.divider_color_dark); - AndroidUiHelper.updateVisibility(holder.divider, position != statBlocks.size() - 1); + AndroidUiHelper.updateVisibility(holder.divider, position != items.size() - 1); + } + + public void setItems(List items) { + this.items.clear(); + this.items.addAll(items); + notifyDataSetChanged(); } } From 162182a8ee2b91af8efad9d04ed4b7e7985fdf01 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 10 Feb 2021 12:30:09 +0200 Subject: [PATCH 3/4] fix for future use when new track recording starts --- .../net/osmand/plus/track/GpxBlockStatisticsBuilder.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index 2f11a6136a..7d7b911078 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -100,12 +100,15 @@ public class GpxBlockStatisticsBuilder { GPXFile gpxFile = getGPXFile(); GpxDisplayItem gpxDisplayItem = null; GPXTrackAnalysis analysis = null; + boolean withoutGaps = false; if (gpxFile.tracks.size() > 0) { gpxDisplayItem = getDisplayItem(gpxFile); - analysis = gpxDisplayItem.analysis; } - if (gpxDisplayItem != null && analysis != null) { - boolean withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack(); + if (gpxDisplayItem != null) { + analysis = gpxDisplayItem.analysis; + withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack(); + } + if (analysis != null) { float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan; String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); From c50a671021ed91c0d2719631451484c4c4024ecb Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 10 Feb 2021 13:07:36 +0200 Subject: [PATCH 4/4] fix for future use when new track recording starts p2 --- OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index 7d7b911078..0e005b0d8c 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -100,7 +100,7 @@ public class GpxBlockStatisticsBuilder { GPXFile gpxFile = getGPXFile(); GpxDisplayItem gpxDisplayItem = null; GPXTrackAnalysis analysis = null; - boolean withoutGaps = false; + boolean withoutGaps = true; if (gpxFile.tracks.size() > 0) { gpxDisplayItem = getDisplayItem(gpxFile); }