From e5bf00162eb911b1bbb7a3e68d4da8a0b9c5dab4 Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 12 Feb 2021 15:08:56 +0200 Subject: [PATCH] fix "Currently recording track" showing with same name; add update statistics blocks in "Overview" if the current recording track is open; --- .../plus/track/GpxBlockStatisticsBuilder.java | 41 +++++++++++-------- .../net/osmand/plus/track/OverviewCard.java | 4 ++ .../osmand/plus/track/TrackMenuFragment.java | 17 +++++++- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index 0e005b0d8c..0c1b77a1fa 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -11,6 +11,7 @@ import androidx.annotation.ColorInt; import androidx.annotation.ColorRes; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatImageView; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -41,6 +42,7 @@ public class GpxBlockStatisticsBuilder { private BlockStatisticsAdapter adapter; private final List items = new ArrayList<>(); + private boolean blocksClickable = true; private final Handler handler = new Handler(); private Runnable updatingItems; @@ -51,28 +53,34 @@ public class GpxBlockStatisticsBuilder { this.selectedGpxFile = selectedGpxFile; } + public boolean isUpdateRunning() { + return updateRunning; + } + + public void setBlocksClickable(boolean blocksClickable) { + this.blocksClickable = blocksClickable; + } + public void setBlocksView(RecyclerView blocksView) { this.blocksView = blocksView; } - private GpxDisplayItem getDisplayItem(GPXFile gpxFile) { - return GpxUiHelper.makeGpxDisplayItem(app, gpxFile); + @Nullable + public GpxDisplayItem getDisplayItem(GPXFile gpxFile) { + return gpxFile.tracks.size() > 0 ? GpxUiHelper.makeGpxDisplayItem(app, gpxFile) : null; } private GPXFile getGPXFile() { return selectedGpxFile.getGpxFile(); } - public void initStatBlocks(SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { + public void initStatBlocks(@Nullable SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { 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); - } + adapter = new BlockStatisticsAdapter(getDisplayItem(getGPXFile()), actionsListener, activeColor, nightMode); + adapter.setItems(items); + blocksView.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false)); + blocksView.setAdapter(adapter); + AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items)); } public void stopUpdatingStatBlocks() { @@ -84,11 +92,11 @@ public class GpxBlockStatisticsBuilder { updatingItems = new Runnable() { @Override public void run() { + initItems(); if (adapter != null) { - initItems(); adapter.setItems(items); - AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items)); } + AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items)); int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get(); handler.postDelayed(this, Math.max(1000, interval)); } @@ -98,12 +106,9 @@ public class GpxBlockStatisticsBuilder { public void initItems() { GPXFile gpxFile = getGPXFile(); - GpxDisplayItem gpxDisplayItem = null; + GpxDisplayItem gpxDisplayItem = getDisplayItem(gpxFile); GPXTrackAnalysis analysis = null; boolean withoutGaps = true; - if (gpxFile.tracks.size() > 0) { - gpxDisplayItem = getDisplayItem(gpxFile); - } if (gpxDisplayItem != null) { analysis = gpxDisplayItem.analysis; withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack(); @@ -237,7 +242,7 @@ public class GpxBlockStatisticsBuilder { @Override public void onClick(View v) { GPXTrackAnalysis analysis = displayItem != null ? displayItem.analysis : null; - if (analysis != null) { + if (blocksClickable && analysis != null && actionsListener != null) { ArrayList list = new ArrayList<>(); if (analysis.hasElevationData || analysis.isSpeedSpecified() || analysis.hasSpeedData) { if (item.firstType != null) { diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index bb56b43f89..25fa38e04e 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -43,6 +43,10 @@ public class OverviewCard extends BaseCard { private final SelectedGpxFile selectedGpxFile; private final GpxBlockStatisticsBuilder blockStatisticsBuilder; + public GpxBlockStatisticsBuilder getBlockStatisticsBuilder() { + return blockStatisticsBuilder; + } + public OverviewCard(@NonNull MapActivity mapActivity, @NonNull SegmentActionsListener actionsListener, SelectedGpxFile selectedGpxFile) { super(mapActivity); this.actionsListener = actionsListener; diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index ff2ec67140..7aa8eebbce 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -231,7 +231,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } displayHelper.setGpx(selectedGpxFile.getGpxFile()); String fileName = Algorithms.getFileWithoutDirs(getGpx().path); - gpxTitle = GpxUiHelper.getGpxTitle(fileName); + gpxTitle = !isCurrentRecordingTrack() ? GpxUiHelper.getGpxTitle(fileName) + : app.getResources().getString(R.string.shared_string_currently_recording_track); toolbarHeightPx = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar); FragmentActivity activity = requireMyActivity(); @@ -330,8 +331,13 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card overviewCard.setListener(this); headerContainer.addView(overviewCard.build(getMapActivity())); } + GpxBlockStatisticsBuilder blocksBuilder = overviewCard.getBlockStatisticsBuilder(); + if (isCurrentRecordingTrack() && !blocksBuilder.isUpdateRunning()) { + blocksBuilder.runUpdatingStatBlocks(); + } } else { if (overviewCard != null && overviewCard.getView() != null) { + overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks(); headerContainer.removeView(overviewCard.getView()); } boolean isOptions = menuType == TrackMenuType.OPTIONS; @@ -544,6 +550,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } updateControlsVisibility(true); startLocationUpdate(); + GpxBlockStatisticsBuilder blockStats = overviewCard.getBlockStatisticsBuilder(); + if (menuType == TrackMenuType.OVERVIEW && isCurrentRecordingTrack() && !blockStats.isUpdateRunning()) { + blockStats.runUpdatingStatBlocks(); + } } @Override @@ -555,6 +565,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } updateControlsVisibility(false); stopLocationUpdate(); + overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks(); } @Override @@ -1120,6 +1131,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + private boolean isCurrentRecordingTrack() { + return app.getSavingTrackHelper().getCurrentTrack() == selectedGpxFile; + } + private void hide() { try { MapActivity mapActivity = getMapActivity();