From e5bf00162eb911b1bbb7a3e68d4da8a0b9c5dab4 Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 12 Feb 2021 15:08:56 +0200 Subject: [PATCH 1/4] 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(); From 63351ebf66b086c840e278c6cc24b3a544ed6b2b Mon Sep 17 00:00:00 2001 From: Skalii Date: Sat, 13 Feb 2021 05:57:28 +0200 Subject: [PATCH 2/4] fix vertical arrow alignment; fix blocks within width 60dp-120dp --- OsmAnd/res/layout/favorites_list_item.xml | 1 + OsmAnd/res/layout/gpx_overview_fragment.xml | 10 ++++++---- OsmAnd/res/layout/item_gpx_stat_block.xml | 9 +++++---- .../plus/track/GpxBlockStatisticsBuilder.java | 15 +++++++++++---- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/OsmAnd/res/layout/favorites_list_item.xml b/OsmAnd/res/layout/favorites_list_item.xml index d53497c0f5..b444aae2ac 100644 --- a/OsmAnd/res/layout/favorites_list_item.xml +++ b/OsmAnd/res/layout/favorites_list_item.xml @@ -93,6 +93,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:layout_marginTop="1sp" android:contentDescription="@string/show_view_angle" osmand:srcCompat="@drawable/ic_direction_arrow" /> diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml index 3b205ae60e..e613260e86 100644 --- a/OsmAnd/res/layout/gpx_overview_fragment.xml +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -38,21 +38,23 @@ android:layout_height="wrap_content" android:layout_marginStart="@dimen/content_padding" android:layout_marginLeft="@dimen/content_padding" - android:gravity="center" - android:orientation="horizontal" - android:paddingTop="@dimen/dash_margin" - android:paddingBottom="@dimen/dash_margin"> + android:layout_marginTop="@dimen/dash_margin" + android:layout_marginBottom="@dimen/dash_margin" + android:orientation="horizontal"> @@ -61,8 +60,10 @@ android:layout_height="wrap_content" android:background="@null" android:ellipsize="end" + android:gravity="start|center_vertical" android:lines="1" android:maxWidth="@dimen/grid_menu_item_width" + android:minWidth="@dimen/map_route_buttons_width" android:textColor="?android:attr/textColorSecondary" android:textSize="@dimen/default_desc_text_size" tools:text="@string/distance" /> diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index 0c1b77a1fa..75bd8f58bb 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -32,6 +32,7 @@ import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class GpxBlockStatisticsBuilder { @@ -232,12 +233,10 @@ public class GpxBlockStatisticsBuilder { public void onBindViewHolder(BlockStatisticsViewHolder holder, int 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.setText(item.title); holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light)); + holder.titleText.setWidth(calculateWidthWithin(item.title, item.value)); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -271,6 +270,14 @@ public class GpxBlockStatisticsBuilder { } } + public int calculateWidthWithin(String... texts) { + int textSize = app.getResources().getDimensionPixelSize(R.dimen.default_desc_text_size); + int textWidth = AndroidUtils.getTextMaxWidth(textSize, Arrays.asList(texts)); + int minWidth = AndroidUtils.dpToPx(app, 60); + int maxWidth = AndroidUtils.dpToPx(app, 120); + return Math.min(maxWidth, Math.max(minWidth, textWidth)); + } + private class BlockStatisticsViewHolder extends RecyclerView.ViewHolder { private final TextViewEx valueText; From 81ce5a43725cf21d65793f0d490b02a6fb553203 Mon Sep 17 00:00:00 2001 From: Skalii Date: Tue, 16 Feb 2021 00:54:35 +0200 Subject: [PATCH 3/4] some fixes; --- OsmAnd/res/layout/favorites_list_item.xml | 279 +++++++++--------- .../plus/track/GpxBlockStatisticsBuilder.java | 60 ++-- .../osmand/plus/track/TrackMenuFragment.java | 8 +- 3 files changed, 180 insertions(+), 167 deletions(-) diff --git a/OsmAnd/res/layout/favorites_list_item.xml b/OsmAnd/res/layout/favorites_list_item.xml index b444aae2ac..106e532e1e 100644 --- a/OsmAnd/res/layout/favorites_list_item.xml +++ b/OsmAnd/res/layout/favorites_list_item.xml @@ -1,159 +1,158 @@ - + - + - + - + - + - + - - + + - + - + - + - + android:contentDescription="@string/show_view_angle" + osmand:srcCompat="@drawable/ic_direction_arrow" /> - + - + - - - + + + - + - - + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index 75bd8f58bb..c83ace3a8d 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -19,6 +19,7 @@ import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; +import net.osmand.PlatformUtil; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndFormatter; @@ -31,12 +32,17 @@ import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class GpxBlockStatisticsBuilder { + private static final Log log = PlatformUtil.getLog(GpxBlockStatisticsBuilder.class); + private static final int GENERAL_UPDATE_INTERVAL = 1000; + private final OsmandApplication app; private RecyclerView blocksView; private final SelectedGpxFile selectedGpxFile; @@ -89,20 +95,25 @@ public class GpxBlockStatisticsBuilder { updateRunning = false; } - public void runUpdatingStatBlocks() { - updatingItems = new Runnable() { - @Override - public void run() { - initItems(); - if (adapter != null) { - 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)); + public void runUpdatingStatBlocksIfNeeded() { + if (!isUpdateRunning()) { + if (handler.hasCallbacks(updatingItems)) { + stopUpdatingStatBlocks(); } - }; - updateRunning = handler.post(updatingItems); + updatingItems = new Runnable() { + @Override + public void run() { + initItems(); + if (adapter != null) { + adapter.setItems(items); + } + AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items)); + int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get(); + updateRunning = handler.postDelayed(this, Math.max(GENERAL_UPDATE_INTERVAL, interval)); + } + }; + updateRunning = handler.post(updatingItems); + } } public void initItems() { @@ -171,7 +182,7 @@ public class GpxBlockStatisticsBuilder { } } - public class StatBlock { + public static class StatBlock { private final String title; private final String value; private final int imageResId; @@ -207,6 +218,9 @@ public class GpxBlockStatisticsBuilder { @ColorInt private final int activeColor; private final boolean nightMode; + private final int minWidthPx; + private final int maxWidthPx; + private final int textSize; public BlockStatisticsAdapter(GpxDisplayItem displayItem, SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { @@ -214,6 +228,9 @@ public class GpxBlockStatisticsBuilder { this.actionsListener = actionsListener; this.activeColor = activeColor; this.nightMode = nightMode; + minWidthPx = AndroidUtils.dpToPx(app, 60f); + maxWidthPx = AndroidUtils.dpToPx(app, 120f); + textSize = app.getResources().getDimensionPixelSize(R.dimen.default_desc_text_size); } @Override @@ -268,17 +285,14 @@ public class GpxBlockStatisticsBuilder { this.items.addAll(items); notifyDataSetChanged(); } + + public int calculateWidthWithin(String... texts) { + int textWidth = AndroidUtils.getTextMaxWidth(textSize, Arrays.asList(texts)); + return Math.min(maxWidthPx, Math.max(minWidthPx, textWidth)); + } } - public int calculateWidthWithin(String... texts) { - int textSize = app.getResources().getDimensionPixelSize(R.dimen.default_desc_text_size); - int textWidth = AndroidUtils.getTextMaxWidth(textSize, Arrays.asList(texts)); - int minWidth = AndroidUtils.dpToPx(app, 60); - int maxWidth = AndroidUtils.dpToPx(app, 120); - return Math.min(maxWidth, Math.max(minWidth, textWidth)); - } - - private class BlockStatisticsViewHolder extends RecyclerView.ViewHolder { + private static class BlockStatisticsViewHolder extends RecyclerView.ViewHolder { private final TextViewEx valueText; private final TextView titleText; diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 7aa8eebbce..9d31b03ed8 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -332,8 +332,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card headerContainer.addView(overviewCard.build(getMapActivity())); } GpxBlockStatisticsBuilder blocksBuilder = overviewCard.getBlockStatisticsBuilder(); - if (isCurrentRecordingTrack() && !blocksBuilder.isUpdateRunning()) { - blocksBuilder.runUpdatingStatBlocks(); + if (isCurrentRecordingTrack()) { + blocksBuilder.runUpdatingStatBlocksIfNeeded(); } } else { if (overviewCard != null && overviewCard.getView() != null) { @@ -551,8 +551,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card updateControlsVisibility(true); startLocationUpdate(); GpxBlockStatisticsBuilder blockStats = overviewCard.getBlockStatisticsBuilder(); - if (menuType == TrackMenuType.OVERVIEW && isCurrentRecordingTrack() && !blockStats.isUpdateRunning()) { - blockStats.runUpdatingStatBlocks(); + if (menuType == TrackMenuType.OVERVIEW && isCurrentRecordingTrack()) { + blockStats.runUpdatingStatBlocksIfNeeded(); } } From 6895dc95294d9e5acad47a2ba0efa72a3aa489dc Mon Sep 17 00:00:00 2001 From: Skalii Date: Tue, 16 Feb 2021 03:24:19 +0200 Subject: [PATCH 4/4] fix excess code requiring too high API level --- .../src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index c83ace3a8d..d75416052e 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -97,9 +97,6 @@ public class GpxBlockStatisticsBuilder { public void runUpdatingStatBlocksIfNeeded() { if (!isUpdateRunning()) { - if (handler.hasCallbacks(updatingItems)) { - stopUpdatingStatBlocks(); - } updatingItems = new Runnable() { @Override public void run() {