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
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
42 changes: 37 additions & 5 deletions OsmAnd/src/net/osmand/plus/auto/FavoritesScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
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;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.myplaces.favorites.FavoriteGroup;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.PointImageDrawable;
import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchResult;
Expand Down Expand Up @@ -60,6 +65,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().setCustomMapObjects(null);
getApp().getOsmandMap().getMapView().backToLocation();
}
});
}

@NonNull
Expand All @@ -82,11 +95,26 @@ 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().setCustomMapObjects(limitedFavoritesPoints);
QuadRect mapRect = new QuadRect();
for (FavouritePoint point : limitedFavoritesPoints) {
double longitude = point.getLongitude();
double latitude = point.getLatitude();
if (mapRect.left == 0.0) {
mapRect.left = longitude;
} else {
mapRect.left = Math.min(mapRect.left, longitude);
}
mapRect.right = Math.max(mapRect.right, longitude);
if (mapRect.bottom == 0.0) {
mapRect.bottom = latitude;
} else {
mapRect.bottom = Math.min(mapRect.bottom, latitude);
}
mapRect.top = Math.max(mapRect.top, latitude);
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 +133,11 @@ private void setupFavorites(ItemList.Builder listBuilder) {
.setMetadata(new Metadata.Builder().setPlace(new Place.Builder(
CarLocation.create(point.getLatitude(), point.getLongitude())).build()).build())
.build());
collectionSize++;
}
if (mapRect.left != 0.0 && mapRect.right != 0.0 && mapRect.top != 0.0 && mapRect.bottom != 0.0) {
OsmandMapTileView mapView = getApp().getOsmandMap().getMapView();
RotatedTileBox tileBox =mapView.getCurrentRotatedTileBox().copy();
mapView.fitRectToMap(mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, tileBox.getPixHeight(), tileBox.getPixHeight(), 0);
}
}

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
49 changes: 42 additions & 7 deletions OsmAnd/src/net/osmand/plus/auto/MapMarkersScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,62 @@ 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.data.QuadRect
import net.osmand.data.RotatedTileBox
import net.osmand.plus.R
import net.osmand.plus.mapmarkers.MapMarker
import net.osmand.search.core.ObjectType
import net.osmand.search.core.SearchResult
import net.osmand.util.MapUtils
import kotlin.math.max
import kotlin.math.min

class MapMarkersScreen(
carContext: CarContext,
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.setCustomMapObjects(null)
app.osmandMap.mapView.backToLocation()
}
})
}

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.setCustomMapObjects(markers)
val mapRect = QuadRect()
for (marker in markers) {
if (itemsCount == contentLimit) {
break
}
val longitude = marker.longitude
val latitude = marker.latitude
mapRect.left = if(mapRect.left == 0.0) longitude else min(mapRect.left, longitude)
mapRect.right = max(mapRect.right, longitude)
mapRect.bottom = if(mapRect.bottom == 0.0) latitude else min(mapRect.bottom, latitude)
mapRect.top = max(mapRect.top, latitude)
val title = marker.getName(app)
val markerColor = MapMarker.getColorId(marker.colorIndex)
val icon = CarIcon.Builder(
Expand Down Expand Up @@ -56,7 +88,10 @@ class MapMarkersScreen(
location.longitude)).build()).build())
}
listBuilder.addItem(rowBuilder.build())
itemsCount++
}
if (mapRect.left != 0.0 && mapRect.right != 0.0 && mapRect.top != 0.0 && mapRect.bottom != 0.0) {
val tb: RotatedTileBox = app.osmandMap.mapView.currentRotatedTileBox.copy()
app.osmandMap.mapView.fitRectToMap(mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, tb.pixWidth, tb.pixHeight, 0)
}
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()
}
1 change: 0 additions & 1 deletion OsmAnd/src/net/osmand/plus/auto/NavigationScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ public void stopTrip() {
}

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

Expand Down
16 changes: 12 additions & 4 deletions OsmAnd/src/net/osmand/plus/auto/NavigationSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import net.osmand.plus.auto.RequestPermissionScreen.LocationPermissionCheckCallback;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.routing.IRouteInformationListener;
import net.osmand.plus.views.MapLayers;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.base.OsmandMapLayer;

/**
* Session class for the Navigation sample app.
Expand Down Expand Up @@ -103,11 +105,21 @@ private OsmandApplication getApp() {
@Override
public void onStart(@NonNull LifecycleOwner owner) {
getApp().getRoutingHelper().addListener(this);
MapLayers mapLayers = getApp().getOsmandMap().getMapLayers();
mapLayers.getFavouritesLayer().customObjectsDelegate = new OsmandMapLayer.CustomMapObjects<>();
mapLayers.getGpxLayer().customObjectsDelegate = new OsmandMapLayer.CustomMapObjects<>();
mapLayers.getPoiMapLayer().customObjectsDelegate = new OsmandMapLayer.CustomMapObjects<>();
mapLayers.getMapMarkersLayer().customObjectsDelegate = new OsmandMapLayer.CustomMapObjects<>();
}

@Override
public void onStop(@NonNull LifecycleOwner owner) {
getApp().getRoutingHelper().removeListener(this);
MapLayers mapLayers = getApp().getOsmandMap().getMapLayers();
mapLayers.getFavouritesLayer().customObjectsDelegate = null;
mapLayers.getGpxLayer().customObjectsDelegate = null;
mapLayers.getPoiMapLayer().customObjectsDelegate = null;
mapLayers.getMapMarkersLayer().customObjectsDelegate = null;
}

@Override
Expand Down Expand Up @@ -246,10 +258,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