From 3ef12afb08841818d4151bb53c5bcc706295e628 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Tue, 13 Oct 2020 12:27:24 +0300 Subject: [PATCH] show progress bar while route is recalculating --- .../fragment_measurement_tool_graph.xml | 10 ++ OsmAnd/res/values/strings.xml | 1 + .../MeasurementToolFragment.java | 6 +- .../plus/measurementtool/MtGraphFragment.java | 102 +++++++++++------- 4 files changed, 78 insertions(+), 41 deletions(-) diff --git a/OsmAnd/res/layout/fragment_measurement_tool_graph.xml b/OsmAnd/res/layout/fragment_measurement_tool_graph.xml index dd9d3b7cae..3d14187712 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool_graph.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool_graph.xml @@ -85,6 +85,16 @@ android:tint="?attr/default_icon_color" tools:src="@drawable/ic_action_info_dark" /> + + + Wait for the route recalculation.\nGraph will be available after recalculation. %1$s data available only on the roads, you need to calculate a route using “Route between points” to get it. Graph Logout successful diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index e5737ceca1..671539ffb8 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -24,7 +24,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.core.widget.TextViewCompat; -import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; @@ -222,6 +221,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void showProgressBar() { MeasurementToolFragment.this.showProgressBar(); + updateAdditionalInfoView(); } @Override @@ -659,6 +659,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route progressBarVisible = true; } + public boolean isProgressBarVisible() { + return progressBarVisible; + } + private void updateMainIcon() { GpxData gpxData = editingCtx.getGpxData(); if (gpxData != null) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MtGraphFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MtGraphFragment.java index 71a7c45db2..c8f6e3cf2d 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MtGraphFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MtGraphFragment.java @@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool; import android.view.View; import android.widget.ImageView; +import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; @@ -55,11 +56,6 @@ public class MtGraphFragment extends BaseCard private List graphTypes = new ArrayList<>(); private MeasurementToolFragment mtf; - public MtGraphFragment(@NonNull MapActivity mapActivity, MeasurementToolFragment mtf) { - super(mapActivity); - this.mtf = mtf; - } - private enum CommonGraphType { OVERVIEW(R.string.shared_string_overview, false), ALTITUDE(R.string.altitude, true), @@ -75,6 +71,37 @@ public class MtGraphFragment extends BaseCard final boolean canBeCalculated; } + public MtGraphFragment(@NonNull MapActivity mapActivity, MeasurementToolFragment mtf) { + super(mapActivity); + this.mtf = mtf; + } + + @Override + protected void updateContent() { + if (mapActivity == null || mtf == null) return; + editingCtx = mtf.getEditingCtx(); + + commonGraphContainer = view.findViewById(R.id.common_graphs_container); + customGraphContainer = view.findViewById(R.id.custom_graphs_container); + messageContainer = view.findViewById(R.id.message_container); + commonGraphChart = (LineChart) view.findViewById(R.id.line_chart); + customGraphChart = (HorizontalBarChart) view.findViewById(R.id.horizontal_chart); + updateGraphData(); + + rvGraphTypesMenu = view.findViewById(R.id.graph_types_recycler_view); + rvGraphTypesMenu.setLayoutManager( + new LinearLayoutManager(mapActivity, RecyclerView.HORIZONTAL, false)); + + refreshGraphTypesSelectionMenu(); + GraphType firstAvailableGraphType = getFirstAvailableGraphType(); + setupVisibleGraphType(firstAvailableGraphType); + } + + @Override + public int getCardLayoutId() { + return R.layout.fragment_measurement_tool_graph; + } + private void refreshGraphTypesSelectionMenu() { rvGraphTypesMenu.removeAllViews(); OsmandApplication app = getMyApplication(); @@ -112,18 +139,18 @@ public class MtGraphFragment extends BaseCard public void onUpdateAdditionalInfo() { updateGraphData(); refreshGraphTypesSelectionMenu(); - setupVisibleGraphType(currentGraphType); + setupVisibleGraphType(currentGraphType.isAvailable() + ? currentGraphType : getFirstAvailableGraphType()); } - private void setupVisibleGraphType(GraphType preferredType) { - currentGraphType = currentGraphType != null && preferredType.hasData() - ? preferredType : getFirstAvailableGraphType(); + private void setupVisibleGraphType(GraphType type) { + currentGraphType = type; updateDataView(); } private GraphType getFirstAvailableGraphType() { for (GraphType type : graphTypes) { - if (type.hasData() || type.canBeCalculated()) { + if (type.isAvailable()) { return type; } } @@ -131,13 +158,27 @@ public class MtGraphFragment extends BaseCard } private void updateDataView() { - if (currentGraphType.hasData()) { + if (mtf.isProgressBarVisible()) { + showProgressMessage(); + } else if (currentGraphType.hasData()) { showGraph(); } else if (currentGraphType.canBeCalculated()) { showMessage(); } } + private void showProgressMessage() { + commonGraphContainer.setVisibility(View.GONE); + customGraphContainer.setVisibility(View.GONE); + messageContainer.setVisibility(View.VISIBLE); + TextView tvMessage = messageContainer.findViewById(R.id.message_text); + ImageView icon = messageContainer.findViewById(R.id.message_icon); + ProgressBar pb = messageContainer.findViewById(R.id.progress_bar); + pb.setVisibility(View.VISIBLE); + icon.setVisibility(View.GONE); + tvMessage.setText(R.string.message_graph_will_be_available_after_recalculation); + } + private void showGraph() { if (currentGraphType.isCustom()) { customGraphChart.clear(); @@ -160,8 +201,12 @@ public class MtGraphFragment extends BaseCard messageContainer.setVisibility(View.VISIBLE); TextView tvMessage = messageContainer.findViewById(R.id.message_text); ImageView icon = messageContainer.findViewById(R.id.message_icon); - String message = app.getString(R.string.message_need_calculate_route_before_show_graph, currentGraphType.getTitle()); - tvMessage.setText(message); + ProgressBar pb = messageContainer.findViewById(R.id.progress_bar); + pb.setVisibility(View.GONE); + icon.setVisibility(View.VISIBLE); + tvMessage.setText(app.getString( + R.string.message_need_calculate_route_before_show_graph, + currentGraphType.getTitle())); icon.setImageResource(R.drawable.ic_action_altitude_average); } @@ -296,33 +341,6 @@ public class MtGraphFragment extends BaseCard defaultRender, currentSearchRequest, defaultSearchRequest); } - @Override - public int getCardLayoutId() { - return R.layout.fragment_measurement_tool_graph; - } - - @Override - protected void updateContent() { - if (mapActivity == null || mtf == null) return; - - editingCtx = mtf.getEditingCtx(); - OsmandApplication app = mapActivity.getMyApplication(); - - commonGraphContainer = view.findViewById(R.id.common_graphs_container); - customGraphContainer = view.findViewById(R.id.custom_graphs_container); - messageContainer = view.findViewById(R.id.message_container); - commonGraphChart = (LineChart) view.findViewById(R.id.line_chart); - customGraphChart = (HorizontalBarChart) view.findViewById(R.id.horizontal_chart); - updateGraphData(); - - rvGraphTypesMenu = view.findViewById(R.id.graph_types_recycler_view); - rvGraphTypesMenu.setLayoutManager( - new LinearLayoutManager(mapActivity, RecyclerView.HORIZONTAL, false)); - - refreshGraphTypesSelectionMenu(); - setupVisibleGraphType(currentGraphType); - } - private static class GraphType { private String title; private boolean isCustom; @@ -344,6 +362,10 @@ public class MtGraphFragment extends BaseCard return isCustom; } + public boolean isAvailable() { + return hasData() || canBeCalculated(); + } + public boolean canBeCalculated() { return canBeCalculated; }