added two methods for getting routes and refactored strings with osmandFormattedDistance

This commit is contained in:
Chumva 2018-02-16 14:25:09 +02:00
parent c339303e49
commit 3146aeabe1
4 changed files with 57 additions and 42 deletions

View file

@ -9,8 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="transport_nearby_routes_within">Routes within 150 meters</string> <string name="transport_nearby_routes_within">Routes within</string>
<string name="transport_nearby_routes">NEAR IN 150 M:</string> <string name="transport_nearby_routes">NEAR IN</string>
<string name="enter_the_file_name">Enter the file name.</string> <string name="enter_the_file_name">Enter the file name.</string>
<string name="make_as_start_point">Make as Start Point</string> <string name="make_as_start_point">Make as Start Point</string>
<string name="shared_string_current">Current</string> <string name="shared_string_current">Current</string>

View file

@ -40,6 +40,7 @@ import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint; import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.LockableScrollView; import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -493,32 +494,23 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
GridView nearbyTransportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_nearby_routes_grid); GridView nearbyTransportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_nearby_routes_grid);
TextView nearbRoutesWithinTv = (TextView) view.findViewById(R.id.nearby_routes_within_text_view); TextView nearbRoutesWithinTv = (TextView) view.findViewById(R.id.nearby_routes_within_text_view);
LinearLayout nearbyRoutesLayoutToHide = (LinearLayout) view.findViewById(R.id.nearby_routes); LinearLayout nearbyRoutesLayoutToHide = (LinearLayout) view.findViewById(R.id.nearby_routes);
List<TransportStopRoute> allTransportStopRoutes = menu.getTransportStopRoutes();
List<TransportStopRoute> localTransportStopRoutes = new ArrayList<>();
List<TransportStopRoute> nearbyTransportStopRoutes = new ArrayList<>();
if (allTransportStopRoutes != null && allTransportStopRoutes.size() > 0) { List<TransportStopRoute> localTransportStopRoutes = menu.getMenuController().getLocalTransportStopRoutes();
for (TransportStopRoute route : allTransportStopRoutes) { List<TransportStopRoute> nearbyTransportStopRoutes = menu.getMenuController().getNearbyTransportStopRoutes();
boolean isCurrentRouteNearby = route.refStop != null && !route.refStop.getName().equals(route.stop.getName());
if (isCurrentRouteNearby) { if (localTransportStopRoutes.size() > 0) {
nearbyTransportStopRoutes.add(route);
} else {
localTransportStopRoutes.add(route);
}
}
localTransportStopRoutesGrid.setAdapter(createTransportStopRouteAdapter(localTransportStopRoutes)); localTransportStopRoutesGrid.setAdapter(createTransportStopRouteAdapter(localTransportStopRoutes));
localTransportStopRoutesGrid.setVisibility(View.VISIBLE); localTransportStopRoutesGrid.setVisibility(View.VISIBLE);
if (nearbyTransportStopRoutes.size() > 0) {
nearbRoutesWithinTv.setText(R.string.transport_nearby_routes);
nearbyTransportStopRoutesGrid.setAdapter(createTransportStopRouteAdapter(nearbyTransportStopRoutes));
nearbyTransportStopRoutesGrid.setVisibility(View.VISIBLE);
} else {
nearbyTransportStopRoutesGrid.setVisibility(View.GONE);
nearbyRoutesLayoutToHide.setVisibility(View.GONE);
}
} else { } else {
localTransportStopRoutesGrid.setVisibility(View.GONE); localTransportStopRoutesGrid.setVisibility(View.GONE);
}
if (nearbyTransportStopRoutes.size() > 0) {
String nearInDistance = getMyApplication().getString(R.string.transport_nearby_routes) + " "
+ OsmAndFormatter.getFormattedDistance(150, getMyApplication());
nearbRoutesWithinTv.setText(nearInDistance);
nearbyTransportStopRoutesGrid.setAdapter(createTransportStopRouteAdapter(nearbyTransportStopRoutes));
nearbyTransportStopRoutesGrid.setVisibility(View.VISIBLE);
} else {
nearbyRoutesLayoutToHide.setVisibility(View.GONE); nearbyRoutesLayoutToHide.setVisibility(View.GONE);
} }

View file

@ -41,6 +41,7 @@ import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
@ -313,9 +314,10 @@ public class MenuBuilder {
buildRow(view, 0, null, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), false, false), buildRow(view, 0, null, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), false, false),
false, 0, false, null, true); false, 0, false, null, true);
CollapsableView collapsableView= getCollapsableTransportStopRoutesView(view.getContext(), false, true); CollapsableView collapsableView = getCollapsableTransportStopRoutesView(view.getContext(), false, true);
if (collapsableView!= null) { if (collapsableView != null) {
buildRow(view, 0, null, app.getString(R.string.transport_nearby_routes_within), 0, true, collapsableView, String routesWithingDistance = app.getString(R.string.transport_nearby_routes_within) + " " + OsmAndFormatter.getFormattedDistance(150, app);
buildRow(view, 0, null, routesWithingDistance, 0, true, collapsableView,
false, 0, false, null, true); false, 0, false, null, true);
} }
} }
@ -843,22 +845,12 @@ public class MenuBuilder {
private CollapsableView getCollapsableTransportStopRoutesView(final Context context, boolean collapsed, boolean isNearbyRoutes) { private CollapsableView getCollapsableTransportStopRoutesView(final Context context, boolean collapsed, boolean isNearbyRoutes) {
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, false); LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, false);
List<TransportStopRoute> localTransportStopRoutes = new ArrayList<>(); List<TransportStopRoute> localTransportStopRoutes = mapContextMenu.getMenuController().getLocalTransportStopRoutes();
List<TransportStopRoute> nearbyTransportStopRoutes = new ArrayList<>(); List<TransportStopRoute> nearbyTransportStopRoutes = mapContextMenu.getMenuController().getNearbyTransportStopRoutes();
if (routes != null && routes.size() > 0) { if (!isNearbyRoutes) {
for (TransportStopRoute route : routes) { buildTransportRouteRows(view, localTransportStopRoutes);
boolean isCurrentRouteNearby = route.refStop != null && !route.refStop.getName().equals(route.stop.getName()); } else {
if (isCurrentRouteNearby) { buildTransportRouteRows(view, nearbyTransportStopRoutes);
nearbyTransportStopRoutes.add(route);
} else {
localTransportStopRoutes.add(route);
}
}
if (!isNearbyRoutes) {
buildTransportRouteRows(view, localTransportStopRoutes);
} else {
buildTransportRouteRows(view, nearbyTransportStopRoutes);
}
} }
if (isNearbyRoutes && nearbyTransportStopRoutes.isEmpty()) { if (isNearbyRoutes && nearbyTransportStopRoutes.isEmpty()) {
return null; return null;

View file

@ -79,6 +79,7 @@ import net.osmand.util.MapUtils;
import net.osmand.util.OpeningHoursParser.OpeningHours; import net.osmand.util.OpeningHoursParser.OpeningHours;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -522,6 +523,36 @@ public abstract class MenuController extends BaseMenuController implements Colla
return null; return null;
} }
public List<TransportStopRoute> getLocalTransportStopRoutes() {
List<TransportStopRoute> allRoutes = getTransportStopRoutes();
if (allRoutes != null) {
List<TransportStopRoute> res = new ArrayList<>();
for (TransportStopRoute route : allRoutes) {
boolean isCurrentRouteNearby = route.refStop != null && !route.refStop.getName().equals(route.stop.getName());
if (!isCurrentRouteNearby) {
res.add(route);
}
}
return res;
}
return null;
}
public List<TransportStopRoute> getNearbyTransportStopRoutes() {
List<TransportStopRoute> allRoutes = getTransportStopRoutes();
if (allRoutes != null) {
List<TransportStopRoute> res = new ArrayList<>();
for (TransportStopRoute route : allRoutes) {
boolean isCurrentRouteNearby = route.refStop != null && !route.refStop.getName().equals(route.stop.getName());
if (isCurrentRouteNearby) {
res.add(route);
}
}
return res;
}
return null;
}
public void share(LatLon latLon, String title, String address) { public void share(LatLon latLon, String title, String address) {
ShareMenu.show(latLon, title, address, getMapActivity()); ShareMenu.show(latLon, title, address, getMapActivity());
} }