show progress bar while route is recalculating
This commit is contained in:
parent
f5cacff2cd
commit
3ef12afb08
4 changed files with 78 additions and 41 deletions
|
@ -85,6 +85,16 @@
|
|||
android:tint="?attr/default_icon_color"
|
||||
tools:src="@drawable/ic_action_info_dark" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
android:layout_width="@dimen/card_button_progress_size"
|
||||
android:layout_height="@dimen/card_button_progress_size"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone" />
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/message_text"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="message_graph_will_be_available_after_recalculation">Wait for the route recalculation.\nGraph will be available after recalculation.</string>
|
||||
<string name="message_need_calculate_route_before_show_graph">%1$s data available only on the roads, you need to calculate a route using “Route between points” to get it.</string>
|
||||
<string name="shared_string_graph">Graph</string>
|
||||
<string name="osm_edit_logout_success">Logout successful</string>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<GraphType> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue