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"
|
android:tint="?attr/default_icon_color"
|
||||||
tools:src="@drawable/ic_action_info_dark" />
|
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
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
android:id="@+id/message_text"
|
android:id="@+id/message_text"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
Thx - Hardy
|
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="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="shared_string_graph">Graph</string>
|
||||||
<string name="osm_edit_logout_success">Logout successful</string>
|
<string name="osm_edit_logout_success">Logout successful</string>
|
||||||
|
|
|
@ -24,7 +24,6 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.widget.TextViewCompat;
|
import androidx.core.widget.TextViewCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
@ -222,6 +221,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
@Override
|
@Override
|
||||||
public void showProgressBar() {
|
public void showProgressBar() {
|
||||||
MeasurementToolFragment.this.showProgressBar();
|
MeasurementToolFragment.this.showProgressBar();
|
||||||
|
updateAdditionalInfoView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -659,6 +659,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
progressBarVisible = true;
|
progressBarVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProgressBarVisible() {
|
||||||
|
return progressBarVisible;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateMainIcon() {
|
private void updateMainIcon() {
|
||||||
GpxData gpxData = editingCtx.getGpxData();
|
GpxData gpxData = editingCtx.getGpxData();
|
||||||
if (gpxData != null) {
|
if (gpxData != null) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -55,11 +56,6 @@ public class MtGraphFragment extends BaseCard
|
||||||
private List<GraphType> graphTypes = new ArrayList<>();
|
private List<GraphType> graphTypes = new ArrayList<>();
|
||||||
private MeasurementToolFragment mtf;
|
private MeasurementToolFragment mtf;
|
||||||
|
|
||||||
public MtGraphFragment(@NonNull MapActivity mapActivity, MeasurementToolFragment mtf) {
|
|
||||||
super(mapActivity);
|
|
||||||
this.mtf = mtf;
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum CommonGraphType {
|
private enum CommonGraphType {
|
||||||
OVERVIEW(R.string.shared_string_overview, false),
|
OVERVIEW(R.string.shared_string_overview, false),
|
||||||
ALTITUDE(R.string.altitude, true),
|
ALTITUDE(R.string.altitude, true),
|
||||||
|
@ -75,6 +71,37 @@ public class MtGraphFragment extends BaseCard
|
||||||
final boolean canBeCalculated;
|
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() {
|
private void refreshGraphTypesSelectionMenu() {
|
||||||
rvGraphTypesMenu.removeAllViews();
|
rvGraphTypesMenu.removeAllViews();
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
|
@ -112,18 +139,18 @@ public class MtGraphFragment extends BaseCard
|
||||||
public void onUpdateAdditionalInfo() {
|
public void onUpdateAdditionalInfo() {
|
||||||
updateGraphData();
|
updateGraphData();
|
||||||
refreshGraphTypesSelectionMenu();
|
refreshGraphTypesSelectionMenu();
|
||||||
setupVisibleGraphType(currentGraphType);
|
setupVisibleGraphType(currentGraphType.isAvailable()
|
||||||
|
? currentGraphType : getFirstAvailableGraphType());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupVisibleGraphType(GraphType preferredType) {
|
private void setupVisibleGraphType(GraphType type) {
|
||||||
currentGraphType = currentGraphType != null && preferredType.hasData()
|
currentGraphType = type;
|
||||||
? preferredType : getFirstAvailableGraphType();
|
|
||||||
updateDataView();
|
updateDataView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GraphType getFirstAvailableGraphType() {
|
private GraphType getFirstAvailableGraphType() {
|
||||||
for (GraphType type : graphTypes) {
|
for (GraphType type : graphTypes) {
|
||||||
if (type.hasData() || type.canBeCalculated()) {
|
if (type.isAvailable()) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,13 +158,27 @@ public class MtGraphFragment extends BaseCard
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDataView() {
|
private void updateDataView() {
|
||||||
if (currentGraphType.hasData()) {
|
if (mtf.isProgressBarVisible()) {
|
||||||
|
showProgressMessage();
|
||||||
|
} else if (currentGraphType.hasData()) {
|
||||||
showGraph();
|
showGraph();
|
||||||
} else if (currentGraphType.canBeCalculated()) {
|
} else if (currentGraphType.canBeCalculated()) {
|
||||||
showMessage();
|
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() {
|
private void showGraph() {
|
||||||
if (currentGraphType.isCustom()) {
|
if (currentGraphType.isCustom()) {
|
||||||
customGraphChart.clear();
|
customGraphChart.clear();
|
||||||
|
@ -160,8 +201,12 @@ public class MtGraphFragment extends BaseCard
|
||||||
messageContainer.setVisibility(View.VISIBLE);
|
messageContainer.setVisibility(View.VISIBLE);
|
||||||
TextView tvMessage = messageContainer.findViewById(R.id.message_text);
|
TextView tvMessage = messageContainer.findViewById(R.id.message_text);
|
||||||
ImageView icon = messageContainer.findViewById(R.id.message_icon);
|
ImageView icon = messageContainer.findViewById(R.id.message_icon);
|
||||||
String message = app.getString(R.string.message_need_calculate_route_before_show_graph, currentGraphType.getTitle());
|
ProgressBar pb = messageContainer.findViewById(R.id.progress_bar);
|
||||||
tvMessage.setText(message);
|
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);
|
icon.setImageResource(R.drawable.ic_action_altitude_average);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,33 +341,6 @@ public class MtGraphFragment extends BaseCard
|
||||||
defaultRender, currentSearchRequest, defaultSearchRequest);
|
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 static class GraphType {
|
||||||
private String title;
|
private String title;
|
||||||
private boolean isCustom;
|
private boolean isCustom;
|
||||||
|
@ -344,6 +362,10 @@ public class MtGraphFragment extends BaseCard
|
||||||
return isCustom;
|
return isCustom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return hasData() || canBeCalculated();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canBeCalculated() {
|
public boolean canBeCalculated() {
|
||||||
return canBeCalculated;
|
return canBeCalculated;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue