Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16632 show items on group selection #17404

Merged
merged 12 commits into from
Jun 27, 2023
2 changes: 1 addition & 1 deletion OsmAnd/src/net/osmand/plus/NavigationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void updateCarNavigation(Location currentLocation) {
destinations = Collections.singletonList(destination);
}
TravelEstimate lastStepTravelEstimate = tripHelper.getLastStepTravelEstimate();
navigationScreen.updateTrip(true, routingHelper.isRouteBeingCalculated(),
navigationScreen.updateTrip(routingHelper.isRouteBeingCalculated(),
false/*routingHelper.isRouteWasFinished()*/,
destinations, trip.getSteps(), destinationTravelEstimate,
lastStepTravelEstimate != null ? lastStepTravelEstimate.getRemainingDistance() : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ abstract class BaseOsmAndAndroidAutoScreen(carContext: CarContext) : Screen(carC
}

companion object {
private const val DEFAULT_CONTENT_LIMIT = 12
private const val DEFAULT_CONTENT_LIMIT = 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 100? Possible crash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use system value from ConstraintManager. This value limits that value to reduce probability of crash

}
}
13 changes: 7 additions & 6 deletions OsmAnd/src/net/osmand/plus/auto/FavoriteGroupsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ class FavoriteGroupsScreen(
.setBrowsable(true)
.setOnClickListener { onClickFavoriteGroup(null) }
.build())
var collectionSize = 1
for (group in favoriteGroups) {
if (collectionSize == contentLimit) {
break
}
if (contentLimit < 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes. If ConstraintManager gives such value

return
}
val favoriteGroupsSize = favoriteGroups.size
val limitedFavoriteGroups =
favoriteGroups.subList(0, favoriteGroupsSize.coerceAtMost(contentLimit - 2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why -2 if other screens -1?

for (group in limitedFavoriteGroups) {
val title = group.getDisplayName(app)
val groupIcon = app.favoritesHelper.getColoredIconForGroup(group.name);
val icon = CarIcon.Builder(
Expand All @@ -60,7 +62,6 @@ class FavoriteGroupsScreen(
.setBrowsable(true)
.setOnClickListener { onClickFavoriteGroup(group) }
.build())
collectionSize++
}
}

Expand Down
22 changes: 16 additions & 6 deletions OsmAnd/src/net/osmand/plus/auto/FavoritesScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import androidx.car.app.navigation.model.PlaceListNavigationTemplate;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.IconCompat;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;

import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
Expand Down Expand Up @@ -60,6 +62,14 @@ public FavoritesScreen(
this.settingsAction = settingsAction;
this.surfaceRenderer = surfaceRenderer;
selectedGroup = group;
getLifecycle().addObserver(new DefaultLifecycleObserver() {
@Override
public void onDestroy(@NonNull LifecycleOwner owner) {
DefaultLifecycleObserver.super.onDestroy(owner);
getApp().getOsmandMap().getMapLayers().getFavouritesLayer().setAndroidAutoFavouritePoints(null);
getApp().getOsmandMap().refreshMap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should move this two rows in separate methods in each screen, also add getOsmandMap in base screen class

}
});
}

@NonNull
Expand All @@ -82,11 +92,12 @@ protected int getConstraintLimitType() {

private void setupFavorites(ItemList.Builder listBuilder) {
LatLon location = getApp().getSettings().getLastKnownMapLocation();
int collectionSize = 0;
for (FavouritePoint point : getFavorites()) {
if (collectionSize == getContentLimit()) {
break;
}
List<FavouritePoint> favoritesPoints = getFavorites();
int favoritesPointsSize = favoritesPoints.size();
List<FavouritePoint> limitedFavoritesPoints = favoritesPoints.subList(0, Math.min(favoritesPointsSize, getContentLimit() - 1));
getApp().getOsmandMap().getMapLayers().getFavouritesLayer().setAndroidAutoFavouritePoints(limitedFavoritesPoints);
getApp().getOsmandMap().refreshMap();
for (FavouritePoint point : limitedFavoritesPoints) {
String title = point.getDisplayName(getApp());
int color = getApp().getFavoritesHelper().getColorWithCategory(point, ContextCompat.getColor(getApp(), R.color.color_favorite));
CarIcon icon = new CarIcon.Builder(IconCompat.createWithBitmap(
Expand All @@ -105,7 +116,6 @@ private void setupFavorites(ItemList.Builder listBuilder) {
.setMetadata(new Metadata.Builder().setPlace(new Place.Builder(
CarLocation.create(point.getLatitude(), point.getLongitude())).build()).build())
.build());
collectionSize++;
}
}

Expand Down
14 changes: 5 additions & 9 deletions OsmAnd/src/net/osmand/plus/auto/HistoryScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ class HistoryScreen(
val historyHelper = SearchHistoryHelper.getInstance(app)
val results = historyHelper.getHistoryEntries(true)
val location = app.settings.lastKnownMapLocation

var collectionSize = 0
for (result in results) {
if (collectionSize == contentLimit) {
break
}
val resultsSize = results.size
val limitedResults = results.subList(0, resultsSize.coerceAtMost(contentLimit - 1))
for (result in limitedResults) {
val searchResult =
SearchHistoryAPI.createSearchResult(app, result, SearchPhrase.emptyPhrase())
val listItem = QuickSearchListItem(app, searchResult)
Expand Down Expand Up @@ -64,7 +61,6 @@ class HistoryScreen(
address.setSpan(distanceSpan, 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
rowBuilder.addText(address)
listBuilder.addItem(rowBuilder.build())
collectionSize++
}
val actionStripBuilder = ActionStrip.Builder()
actionStripBuilder.addAction(
Expand All @@ -75,8 +71,8 @@ class HistoryScreen(
carContext, R.drawable.ic_action_search_dark)).build())
.setOnClickListener { openSearch() }
.build())
return PlaceListNavigationTemplate.Builder()
.setItemList(listBuilder.build())
return ListTemplate.Builder()
.setSingleList(listBuilder.build())
.setTitle(app.getString(R.string.shared_string_history))
.setHeaderAction(Action.BACK)
.setActionStrip(actionStripBuilder.build())
Expand Down
35 changes: 28 additions & 7 deletions OsmAnd/src/net/osmand/plus/auto/MapMarkersScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ package net.osmand.plus.auto
import android.text.SpannableString
import android.text.Spanned
import androidx.car.app.CarContext
import androidx.car.app.model.*
import androidx.car.app.model.Action
import androidx.car.app.model.ActionStrip
import androidx.car.app.model.CarColor
import androidx.car.app.model.CarIcon
import androidx.car.app.model.CarLocation
import androidx.car.app.model.DistanceSpan
import androidx.car.app.model.ItemList
import androidx.car.app.model.Metadata
import androidx.car.app.model.Place
import androidx.car.app.model.Row
import androidx.car.app.model.Template
import androidx.car.app.navigation.model.PlaceListNavigationTemplate
import androidx.core.graphics.drawable.IconCompat
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import net.osmand.data.LatLon
import net.osmand.plus.R
import net.osmand.plus.mapmarkers.MapMarker
Expand All @@ -18,15 +30,25 @@ class MapMarkersScreen(
private val settingsAction: Action,
private val surfaceRenderer: SurfaceRenderer) : BaseOsmAndAndroidAutoScreen(carContext) {

init {
lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
super.onDestroy(owner)
app.osmandMap.mapLayers.mapMarkersLayer.setAndroidAutoMarkers(null)
app.osmandMap.refreshMap()
}
})
}

override fun onGetTemplate(): Template {
val listBuilder = ItemList.Builder()
val markers = app.mapMarkersHelper.mapMarkers
val markersSize = app.mapMarkersHelper.mapMarkers.size
val markers =
app.mapMarkersHelper.mapMarkers.subList(0, markersSize.coerceAtMost(contentLimit - 1))
val location = app.settings.lastKnownMapLocation
var itemsCount = 0
app.osmandMap.mapLayers.mapMarkersLayer.setAndroidAutoMarkers(markers)
app.osmandMap.refreshMap()
for (marker in markers) {
if (itemsCount == contentLimit) {
break
}
val title = marker.getName(app)
val markerColor = MapMarker.getColorId(marker.colorIndex)
val icon = CarIcon.Builder(
Expand Down Expand Up @@ -56,7 +78,6 @@ class MapMarkersScreen(
location.longitude)).build()).build())
}
listBuilder.addItem(rowBuilder.build())
itemsCount++
}
val actionStripBuilder = ActionStrip.Builder()
actionStripBuilder.addAction(
Expand Down
1 change: 0 additions & 1 deletion OsmAnd/src/net/osmand/plus/auto/NavigationListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ package net.osmand.plus.auto

interface NavigationListener {
fun requestLocationNavigation(): Boolean
fun updateNavigation(navigating: Boolean)
fun stopNavigation()
}
106 changes: 46 additions & 60 deletions OsmAnd/src/net/osmand/plus/auto/NavigationScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import java.util.List;

public final class NavigationScreen extends BaseOsmAndAndroidAutoScreen implements SurfaceRendererCallback,
IRouteInformationListener, DefaultLifecycleObserver {
IRouteInformationListener, DefaultLifecycleObserver {

@NonNull
private final NavigationListener listener;
Expand Down Expand Up @@ -122,7 +122,6 @@ public void onFrameRendered(@NonNull Canvas canvas, @NonNull Rect visibleArea, @
* Updates the navigation screen with the next instruction.
*/
public void updateTrip(
boolean navigating,
boolean rerouting,
boolean arrived,
@Nullable List<Destination> destinations,
Expand All @@ -132,7 +131,6 @@ public void updateTrip(
boolean shouldShowNextStep,
boolean shouldShowLanes,
@Nullable CarIcon junctionImage) {
this.navigating = navigating;
this.rerouting = rerouting;
this.arrived = arrived;
this.destinations = destinations;
Expand All @@ -148,7 +146,6 @@ public void updateTrip(
}

public void stopTrip() {
navigating = false;
rerouting = false;
arrived = false;
destinations = null;
Expand All @@ -164,8 +161,7 @@ public void stopTrip() {
}

private void updateNavigation() {
listener.updateNavigation(navigating);
adjustMapPosition(navigating);
adjustMapPosition(true);
}

private void adjustMapPosition(boolean shiftMapIfSessionRunning) {
Expand All @@ -192,19 +188,11 @@ public Template onGetTemplate() {
.setOnClickListener(this::compassClick)
.build());
actionStripBuilder.addAction(settingsAction);
if (navigating) {
actionStripBuilder.addAction(
new Action.Builder()
.setTitle(getApp().getString(R.string.shared_string_control_stop))
.setOnClickListener(this::stopNavigation)
.build());
} else {
actionStripBuilder.addAction(
new Action.Builder()
.setIcon(new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), R.drawable.ic_action_search_dark)).build())
.setOnClickListener(this::openSearch)
.build());
}
actionStripBuilder.addAction(
new Action.Builder()
.setTitle(getApp().getString(R.string.shared_string_control_stop))
.setOnClickListener(this::stopNavigation)
.build());
builder.setActionStrip(actionStripBuilder.build());

// Set the map action strip with the pan and zoom buttons.
Expand Down Expand Up @@ -273,52 +261,50 @@ public Template onGetTemplate() {
invalidate();
});

if (navigating) {
if (destinationTravelEstimate != null) {
builder.setDestinationTravelEstimate(destinationTravelEstimate);
if (destinationTravelEstimate != null) {
builder.setDestinationTravelEstimate(destinationTravelEstimate);
}
if (isRerouting()) {
builder.setNavigationInfo(new RoutingInfo.Builder().setLoading(true).build());
} else if (arrived) {
MessageInfo messageInfo = new MessageInfo.Builder(
getCarContext().getString(R.string.arrived_at_destination)).build();
builder.setNavigationInfo(messageInfo);
} else if (!Algorithms.isEmpty(steps)) {
RoutingInfo.Builder info = new RoutingInfo.Builder();
Step firstStep = steps.get(0);
Step.Builder currentStep = new Step.Builder();
CarText cue = firstStep.getCue();
if (cue != null) {
currentStep.setCue(cue.toCharSequence());
}
if (isRerouting()) {
builder.setNavigationInfo(new RoutingInfo.Builder().setLoading(true).build());
} else if (arrived) {
MessageInfo messageInfo = new MessageInfo.Builder(
getCarContext().getString(R.string.arrived_at_destination)).build();
builder.setNavigationInfo(messageInfo);
} else if (!Algorithms.isEmpty(steps)) {
RoutingInfo.Builder info = new RoutingInfo.Builder();
Step firstStep = steps.get(0);
Step.Builder currentStep = new Step.Builder();
CarText cue = firstStep.getCue();
if (cue != null) {
currentStep.setCue(cue.toCharSequence());
}
Maneuver maneuver = firstStep.getManeuver();
if (maneuver != null) {
currentStep.setManeuver(maneuver);
}
CarText road = firstStep.getRoad();
if (road != null) {
currentStep.setRoad(road.toCharSequence());
}
if (shouldShowLanes) {
for (Lane lane : firstStep.getLanes()) {
currentStep.addLane(lane);
}
CarIcon lanesImage = firstStep.getLanesImage();
if (lanesImage != null) {
currentStep.setLanesImage(lanesImage);
}
Maneuver maneuver = firstStep.getManeuver();
if (maneuver != null) {
currentStep.setManeuver(maneuver);
}
CarText road = firstStep.getRoad();
if (road != null) {
currentStep.setRoad(road.toCharSequence());
}
if (shouldShowLanes) {
for (Lane lane : firstStep.getLanes()) {
currentStep.addLane(lane);
}
if (stepRemainingDistance != null) {
info.setCurrentStep(currentStep.build(), stepRemainingDistance);
if (shouldShowNextStep && steps.size() > 1) {
info.setNextStep(steps.get(1));
}
CarIcon lanesImage = firstStep.getLanesImage();
if (lanesImage != null) {
currentStep.setLanesImage(lanesImage);
}
if (junctionImage != null) {
info.setJunctionImage(junctionImage);
}
if (stepRemainingDistance != null) {
info.setCurrentStep(currentStep.build(), stepRemainingDistance);
if (shouldShowNextStep && steps.size() > 1) {
info.setNextStep(steps.get(1));
}
builder.setNavigationInfo(info.build());
}
if (junctionImage != null) {
info.setJunctionImage(junctionImage);
}
builder.setNavigationInfo(info.build());
}
return builder.build();
}
Expand Down
4 changes: 0 additions & 4 deletions OsmAnd/src/net/osmand/plus/auto/NavigationSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ public boolean requestLocationNavigation() {
return requestLocationPermission();
}

@Override
public void updateNavigation(boolean navigating) {
}

public void startNavigation() {
createNavigationScreen();
getCarContext().getCarService(ScreenManager.class).push(navigationScreen);
Expand Down
6 changes: 5 additions & 1 deletion OsmAnd/src/net/osmand/plus/auto/POICategoriesScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class POICategoriesScreen(
}

private fun setupPOICategories(listBuilder: ItemList.Builder) {
for (poiFilter in app.poiFilters.getSortedPoiFilters(false)) {
val poiFilters = app.poiFilters.getSortedPoiFilters(false)
val poiFiltersSize = poiFilters.size
val limitedPOIFilters = app.poiFilters.getSortedPoiFilters(false)
.subList(0, poiFiltersSize.coerceAtMost(contentLimit - 1))
for (poiFilter in limitedPOIFilters) {
val title = poiFilter.name
var groupIcon = RenderingIcons.getBigIcon(app, poiFilter.iconId)
if (groupIcon == null) {
Expand Down
Loading