Repository navigation
feat(map): show the map with item and skill markers - #391
Merged
Merged
Conversation
New MapMarker (#341): a listing's id, title, type (item or service, so the map can draw them with different icons), coordinates and price, formatted by formatChf like the Browse cards. Listing.toMapMarker() builds it, or returns null for a listing that can't be placed: not saved yet, or without a location, which owners may not have set (#345 made it optional). Tests (MapMarkerTest): an item at its location, a service, no marker without a location, and none for an unsaved listing.
MapViewModel now also loads the markers for the map tab (#341): - MapUiState gets markers, isLoading and error. - loadListings(), called on creation and again on Retry or when the tab comes back, shows the same listings as Browse: every listing that isn't paused (getAllListings), except the signed-in user's own (currentUid), and only those with a location (toMapMarker). - Offline, Firestore answers from its cache; on failure the markers already shown are kept and error says why. A load while one runs is ignored, cancellation is rethrown and isLoading is cleared in a finally, as in BrowseViewModel. - The constructor takes the ListingRepository and the current uid; the existing tests pass a FakeListingRepository. Tests: 6 more in MapViewModelTest (21 in total): only other users' listings with a location (fails without the uid filter), isLoading, an error and its retry, a failed reload keeping the markers, a second load while one runs (fails without the guard), and a cancelled load.
New MapScreen for the Map tab (#341): - ListingsMap draws the Google map: the camera from cameraFor(), one MarkerComposable per listing with its icon (a box for items, a cap for skills, so they differ by icon and not only colour, #353), the renter's approximate circle (150 m) or their campus marker. The camera position is set rather than animated, since CameraUpdateFactory needs the map to be initialised first. - Every decision is in plain functions so it can be tested without Google Maps, which can't run in unit tests: cameraFor() (close on the renter or the campus, an overview of both campuses before that), markerIcon() and markerDescription() (read by TalkBack as "Bosch drill set, item, CHF 8 per day"). - MapContent draws the map, then the listings' state at the bottom (a loading pill on the first load, the error with a 48dp Retry, or "No listings with a location nearby yet"; nothing during a reload with markers, so the map doesn't flicker), then the location layer (#340) on top. MapScreen(viewModel) wires it; its map is a parameter, the Google map by default. Resources: ic_marker_item, ic_marker_service and 5 map_* strings. Tests (MapScreenTest, 14): the camera for each centre, different icons and descriptions per type, the marker label and pin, each listings state, Retry, and the screen with the real MapViewModel.
ListingsMap can't run under Robolectric ("CameraUpdateFactory is not
initialized"), so its lines would stay uncovered. The CI emulator is a
google_apis image with Google Play services, and the coverage report
already includes the connected tests, so ListingsMapTest (instrumented)
builds the map with an item and a skill marker around the renter, then
on a campus, then while choosing. Tiles need a valid key, so it checks
that the map and its markers are built without crashing, not what the
tiles show.
ListingsMapTest crashed on the CI emulator with NoClassDefFoundError org/apache/http/ProtocolVersion, thrown from Play Services' Maps module, which still uses Apache HTTP; Android 9+ no longer loads it by default, so the map could crash in the app too. The manifest now declares <uses-library android:name="org.apache.http.legacy" android:required="false"/>, as Google's Maps SDK documentation asks; not required, so devices without it can still install the app.
Mamel0uk
reviewed
Nov 19, 2026
Mamel0uk
left a comment
Contributor
There was a problem hiding this comment.
Really nice split: with cameraFor, markerIcon and the swappable map, almost every decision is tested without Google Maps. One important point and two nitpicks below.
Mamel0uk
requested changes
Nov 19, 2026
Inside the forEach, rememberMarkerState's state was tied to the marker's position in the list (its key only names the saved state, and the position only counts the first time). After a reload that dropped the first listing, the second took its state and was drawn where the first had been, and a listing its owner moved kept its old pin (Mamel0uk on #391; rememberMarkerState is deprecated in maps-compose 9 for this reason). Each listing marker, and the campus marker, now sits in key(id) { } and uses rememberUpdatedMarkerState(position), so it keeps its own state and follows its current position.
ListingsMapTest slept 3 x 3 s and asserted nothing, so it was slow and could still be flaky on a slow emulator (Mamel0uk on #391). ListingsMap takes an onMapReady callback, called from MapEffect once the map is created, and the test waits up to 20 s for it, then checks the campus and overview states recompose. It waits for "created" rather than onMapLoaded, which waits for the tiles: our Maps key doesn't accept debug builds, so onMapLoaded might never fire on CI.
screen_showsTheViewModelsMarkers_andRetryReloads never tapped Retry (Mamel0uk on #391). The first load now fails, as offline without a cache, so no marker is shown; Retry is tapped and the listing appears, and the error goes away. A campus is picked first, so the location card doesn't cover the bottom of the map where Retry is.
|
Julkzein
added a commit
that referenced
this pull request
Nov 19, 2026
* feat(map): turn listings into map markers New MapMarker (#341): a listing's id, title, type (item or service, so the map can draw them with different icons), coordinates and price, formatted by formatChf like the Browse cards. Listing.toMapMarker() builds it, or returns null for a listing that can't be placed: not saved yet, or without a location, which owners may not have set (#345 made it optional). Tests (MapMarkerTest): an item at its location, a service, no marker without a location, and none for an unsaved listing. * feat(map): load the listings to show on the map MapViewModel now also loads the markers for the map tab (#341): - MapUiState gets markers, isLoading and error. - loadListings(), called on creation and again on Retry or when the tab comes back, shows the same listings as Browse: every listing that isn't paused (getAllListings), except the signed-in user's own (currentUid), and only those with a location (toMapMarker). - Offline, Firestore answers from its cache; on failure the markers already shown are kept and error says why. A load while one runs is ignored, cancellation is rethrown and isLoading is cleared in a finally, as in BrowseViewModel. - The constructor takes the ListingRepository and the current uid; the existing tests pass a FakeListingRepository. Tests: 6 more in MapViewModelTest (21 in total): only other users' listings with a location (fails without the uid filter), isLoading, an error and its retry, a failed reload keeping the markers, a second load while one runs (fails without the guard), and a cancelled load. * feat(map): show the map with item and skill markers New MapScreen for the Map tab (#341): - ListingsMap draws the Google map: the camera from cameraFor(), one MarkerComposable per listing with its icon (a box for items, a cap for skills, so they differ by icon and not only colour, #353), the renter's approximate circle (150 m) or their campus marker. The camera position is set rather than animated, since CameraUpdateFactory needs the map to be initialised first. - Every decision is in plain functions so it can be tested without Google Maps, which can't run in unit tests: cameraFor() (close on the renter or the campus, an overview of both campuses before that), markerIcon() and markerDescription() (read by TalkBack as "Bosch drill set, item, CHF 8 per day"). - MapContent draws the map, then the listings' state at the bottom (a loading pill on the first load, the error with a 48dp Retry, or "No listings with a location nearby yet"; nothing during a reload with markers, so the map doesn't flicker), then the location layer (#340) on top. MapScreen(viewModel) wires it; its map is a parameter, the Google map by default. Resources: ic_marker_item, ic_marker_service and 5 map_* strings. Tests (MapScreenTest, 14): the camera for each centre, different icons and descriptions per type, the marker label and pin, each listings state, Retry, and the screen with the real MapViewModel. * test(map): run the Google map on the CI emulator ListingsMap can't run under Robolectric ("CameraUpdateFactory is not initialized"), so its lines would stay uncovered. The CI emulator is a google_apis image with Google Play services, and the coverage report already includes the connected tests, so ListingsMapTest (instrumented) builds the map with an item and a skill marker around the renter, then on a campus, then while choosing. Tiles need a valid key, so it checks that the map and its markers are built without crashing, not what the tiles show. * feat(map): add the Map tab The map screen (#391) gets its tab (#341): - Routes.MAP and a Map tab in the bottom bar, second between Browse and Create listing as in the Figma "Map — …" frames, with a folded-map icon (ic_nav_map) and the "Map" label. - AppNavHost builds MapViewModel for the signed-in user (keyed by uid, like Browse), with the location repository, the listing repository and createSavedStateHandle(), and reloads the listings when the tab comes back (ON_RESUME), as the Toolbox does. - AppNavHost takes a locationRepository, which MainActivity builds as FusedLocationRepository(LocationServices.getFusedLocationProviderClient), and a listingsMap (the Google map by default) that Robolectric tests replace with a stand-in, since Google Maps can't run there. - Every AppNavHost caller passes a FakeLocationRepository in tests (AppNavHostTest, EndToEndFlowTest, and the instrumented PolyBazaarTestCase, which keeps the real map on the emulator). Tests (AppNavHostTest): the bottom bar on the Map tab, Map second between Browse and Create listing, and the map showing other users' listings with a location, then a listing added meanwhile once the renter comes back to the tab (fails without the ON_RESUME reload). * fix(map): load Apache HTTP for Google Maps on Android 9+ ListingsMapTest crashed on the CI emulator with NoClassDefFoundError org/apache/http/ProtocolVersion, thrown from Play Services' Maps module, which still uses Apache HTTP; Android 9+ no longer loads it by default, so the map could crash in the app too. The manifest now declares <uses-library android:name="org.apache.http.legacy" android:required="false"/>, as Google's Maps SDK documentation asks; not required, so devices without it can still install the app. * fix(map): key each marker by its listing Inside the forEach, rememberMarkerState's state was tied to the marker's position in the list (its key only names the saved state, and the position only counts the first time). After a reload that dropped the first listing, the second took its state and was drawn where the first had been, and a listing its owner moved kept its old pin (Mamel0uk on #391; rememberMarkerState is deprecated in maps-compose 9 for this reason). Each listing marker, and the campus marker, now sits in key(id) { } and uses rememberUpdatedMarkerState(position), so it keeps its own state and follows its current position. * test(map): wait for the Google map instead of sleeping ListingsMapTest slept 3 x 3 s and asserted nothing, so it was slow and could still be flaky on a slow emulator (Mamel0uk on #391). ListingsMap takes an onMapReady callback, called from MapEffect once the map is created, and the test waits up to 20 s for it, then checks the campus and overview states recompose. It waits for "created" rather than onMapLoaded, which waits for the tiles: our Maps key doesn't accept debug builds, so onMapLoaded might never fire on CI. * test(map): tap Retry in the map screen's Retry test screen_showsTheViewModelsMarkers_andRetryReloads never tapped Retry (Mamel0uk on #391). The first load now fails, as offline without a cache, so no marker is shown; Retry is tapped and the listing appears, and the error goes away. A campus is picked first, so the location card doesn't cover the bottom of the map where Retry is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Part of #341 (story #21). Adds the map screen: a Google map centred on the renter or their campus, with the listings as markers that differ for items and skills, the listings' loading, error and empty states, and the location layer (#340) on top. The Map tab and its navigation come in the next PR.
What
ListingsMap(Google map), kept to drawing only:cameraFor(), set rather than animated, sinceCameraUpdateFactoryneeds the map to be initialised first;MarkerComposableper listing with its icon: a box for items, a cap for skills, so they differ by icon and not only by colour (Add the map screens in Figma #353);cameraFor(centre): close on the renter or the campus, an overview of both campuses before the centre is known;markerIcon(type)andmarkerDescription(type): TalkBack reads a marker as "Bosch drill set, item, CHF 8 per day".MapContent: the map, then the listings' state at the bottom, then the location layer on top:MapScreen(viewModel)wires it toMapViewModel(feat(map): load the listings to show on the map #390); the map is a parameter, the Google map by default, so the screen can be tested with a stand-in.AndroidManifest.xml:<uses-library android:name="org.apache.http.legacy" android:required="false"/>. Google Maps' Play Services module still uses Apache HTTP, which Android 9+ no longer loads by default;ListingsMapTestcrashed on the CI emulator withNoClassDefFoundError org/apache/http/ProtocolVersionwithout it.ic_marker_item,ic_marker_serviceand 5map_*strings.MapScreenTest(Robolectric): the camera for each centre, different icons and descriptions per type, the marker label and pin, each listings state, Retry, and the screen with the realMapViewModel.ListingsMapTest(instrumented): Google Maps can't run under Robolectric, so this runsListingsMapon the CI emulator (agoogle_apisimage with Play services), whose coverage the report already includes. It checks that the map and its markers are built without crashing, around the renter, on a campus and while choosing.Why
#341 (from #21): the Map tab shows items and skills with distinct markers, matching Browse, with Retry on a load error and the cached listings offline. #390 loads the markers; this PR draws them; the next one adds the tab.
Notes for the reviewer
main.Routes.MAPas the 2nd tab and buildsMapViewModelwithFusedLocationRepository.Validation
./gradlew ktfmtCheck: passed./gradlew check(with lint): 1,650 tests, 0 failures (same JIT exclusion as before for JDK 21.0.2 on Apple Silicon; CI is not affected).MapScreen.kt111/111 lines.ListingsMap.ktis only covered by the instrumented test, so on CI.connectedChecklocally (no emulator); CI runsListingsMapTest.Follow-ups
AI use
Claude Code helped write the map screen, its markers and their tests; I reviewed, ran and tested all of it.