Fixed 0 min in route info, collapsed stops

This commit is contained in:
crimean 2019-03-11 22:03:07 +03:00
parent 09e7f99714
commit b53f27a200

View file

@ -86,7 +86,6 @@ import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout; import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView; import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView;
import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
@ -627,28 +626,44 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
if (stops.size() > 2) { if (stops.size() > 2) {
collapsableView = getCollapsableTransportStopRoutesView(app, transportStopRoute, stops.subList(1, stops.size() - 1)); collapsableView = getCollapsableTransportStopRoutesView(app, transportStopRoute, stops.subList(1, stops.size() - 1));
} }
SpannableStringBuilder spannable = new SpannableStringBuilder("~"); SpannableStringBuilder spannable = new SpannableStringBuilder();
int startIndex = spannable.length(); int startIndex;
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); int arrivalTime = segment.getArrivalTime();
spannable.append(OsmAndFormatter.getFormattedDuration(segment.getArrivalTime(), app)); if (arrivalTime > 0) {
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.append("~");
startIndex = spannable.length(); startIndex = spannable.length();
spannable.append(""); spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, startIndex + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.append(OsmAndFormatter.getFormattedDuration(arrivalTime, app));
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
arrivalTime = 0;
}
startIndex = spannable.length(); startIndex = spannable.length();
if (stops.size() > 2) { if (stops.size() > 2) {
if (spannable.length() > 0) {
startIndex = spannable.length();
spannable.append("");
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, startIndex + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
startIndex = spannable.length();
spannable.append(String.valueOf(stops.size())).append(" ").append(getString(R.string.transport_stops)); spannable.append(String.valueOf(stops.size())).append(" ").append(getString(R.string.transport_stops));
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
spannable.append("").append(OsmAndFormatter.getFormattedDistance((float) segment.getTravelDist(), app)); if (spannable.length() > 0) {
startIndex = spannable.length();
spannable.append("");
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, startIndex + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
spannable.append(OsmAndFormatter.getFormattedDistance((float) segment.getTravelDist(), app));
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableString textType = new SpannableString(getString(R.string.by_transport_type, transportStopRoute.type.name().toLowerCase())); SpannableString textType = new SpannableString(getString(R.string.by_transport_type, transportStopRoute.type.name().toLowerCase()));
buildCollapsableRow(stopsContainer, spannable, textType, true, collapsableView, null); buildCollapsableRow(stopsContainer, spannable, textType, true, collapsableView, null);
final TransportStop endStop = stops.get(stops.size() - 1); final TransportStop endStop = stops.get(stops.size() - 1);
long depTime = segment.depTime + segment.getArrivalTime(); long depTime = segment.depTime + arrivalTime;
if (depTime <= 0) { if (depTime <= 0) {
depTime = startTime + segment.getArrivalTime(); depTime = startTime + arrivalTime;
} }
String textTime = OsmAndFormatter.getFormattedTime(depTime, false); String textTime = OsmAndFormatter.getFormattedTime(depTime, false);
@ -703,7 +718,9 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
final TransportRouteResultSegment segment = segments.get(i); final TransportRouteResultSegment segment = segments.get(i);
final TransportRouteResultSegment nextSegment = segments.size() > i + 1 ? segments.get(i + 1) : null; final TransportRouteResultSegment nextSegment = segments.size() > i + 1 ? segments.get(i + 1) : null;
long walkTime = (long) getWalkTime(segment.walkDist, routeResult.getWalkSpeed()); long walkTime = (long) getWalkTime(segment.walkDist, routeResult.getWalkSpeed());
if (walkTime < 60) {
walkTime = 60;
}
if (i == 0) { if (i == 0) {
buildStartItem(parent, startPoint, startTime, segment, routeResult.getWalkSpeed()); buildStartItem(parent, startPoint, startTime, segment, routeResult.getWalkSpeed());
startTime += walkTime; startTime += walkTime;
@ -759,6 +776,9 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
} }
private Spannable getWalkTitle(double finishWalkDist, double walkTime) { private Spannable getWalkTitle(double finishWalkDist, double walkTime) {
if (walkTime < 60) {
walkTime = 60;
}
Typeface typeface = FontCache.getRobotoMedium(app); Typeface typeface = FontCache.getRobotoMedium(app);
SpannableStringBuilder title = new SpannableStringBuilder("~"); SpannableStringBuilder title = new SpannableStringBuilder("~");
int startIndex = title.length(); int startIndex = title.length();
@ -804,6 +824,9 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
buildRowDivider(infoContainer, true); buildRowDivider(infoContainer, true);
long walkTime = (long) getWalkTime(segment.walkDist, walkSpeed); long walkTime = (long) getWalkTime(segment.walkDist, walkSpeed);
if (walkTime < 60) {
walkTime = 60;
}
SpannableStringBuilder title = new SpannableStringBuilder(Algorithms.capitalizeFirstLetter(getString(R.string.on_foot))); SpannableStringBuilder title = new SpannableStringBuilder(Algorithms.capitalizeFirstLetter(getString(R.string.on_foot)));
title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int startIndex = title.length(); int startIndex = title.length();
@ -868,7 +891,9 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
buildRowDivider(infoContainer, true); buildRowDivider(infoContainer, true);
long walkTime = (long) getWalkTime(segment.walkDist, walkSpeed); long walkTime = (long) getWalkTime(segment.walkDist, walkSpeed);
if (walkTime < 60) {
walkTime = 60;
}
SpannableStringBuilder spannable = new SpannableStringBuilder("~"); SpannableStringBuilder spannable = new SpannableStringBuilder("~");
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int startIndex = spannable.length(); int startIndex = spannable.length();
@ -900,7 +925,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
buildDestinationRow(infoContainer, timeStr, title, secondaryText, destination.point, imagesContainer, new OnClickListener() { buildDestinationRow(infoContainer, timeStr, title, secondaryText, destination.point, imagesContainer, new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
showLocationOnMap(destination != null ? destination.point : null); showLocationOnMap(destination.point);
} }
}); });
@ -1228,7 +1253,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
@Nullable @Nullable
private QuadRect getWalkingSegmentRect(@NonNull RouteCalculationResult result) { private QuadRect getWalkingSegmentRect(@NonNull RouteCalculationResult result) {
double left = 0, right = 0; double left = 0, right = 0;
double top = 0, bottom = 0;; double top = 0, bottom = 0;
for (Location p : result.getRouteLocations()) { for (Location p : result.getRouteLocations()) {
if (left == 0 && right == 0) { if (left == 0 && right == 0) {
left = p.getLongitude(); left = p.getLongitude();
@ -1480,7 +1505,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
} }
}); });
} }
return new CollapsableView(view, null, false); return new CollapsableView(view, null, true);
} }
protected LinearLayout buildCollapsableContentView(Context context, boolean collapsed) { protected LinearLayout buildCollapsableContentView(Context context, boolean collapsed) {