Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ import com.android.polybazaar.listing.ui.ListingDetailScreen
import com.android.polybazaar.listing.viewmodel.ListingDetailViewModel
import com.android.polybazaar.listing.viewmodel.ListingFormViewModel
import com.android.polybazaar.map.model.LocationRepository
import com.android.polybazaar.map.ui.ListingsMap
import com.android.polybazaar.map.ui.MapScreen
import com.android.polybazaar.map.viewmodel.MapUiState
import com.android.polybazaar.map.viewmodel.MapViewModel
import com.android.polybazaar.profile.model.ProfileRepository
import com.android.polybazaar.profile.ui.EditProfileActions
import com.android.polybazaar.profile.ui.EditProfileContent
Expand All @@ -107,8 +111,8 @@ object AppNavHostTags {
/**
* Navigation graph of the app. It starts on a loading screen until the persisted session has been
* checked, then routes a signed-in user to Browse, or to the verify email screen while their email
* is not verified, and everyone else to sign-in. Browse, Create listing, Conversations and Profile
* share a bottom bar.
* is not verified, and everyone else to sign-in. Browse, Map, Create listing, Conversations and
* Profile share a bottom bar.
*
* All auth screens share [authViewModel], so a sign-in made on one of them is seen by the others.
* Signing out from any signed-in screen returns to sign-in and clears the back stack.
Expand All @@ -118,10 +122,13 @@ object AppNavHostTags {
* @param listingRepository gives the Browse screen the listings to show, and saves new ones.
* @param chatRepository gives the Conversations screen the signed-in user's conversations.
* @param bookingRepository sends the booking requests made from a listing's "Choose dates".
* @param listingsMap draws the Map tab's map: the Google map, or a stand-in in tests, where Google
* Maps can't run.
* @param photoStorage keeps the photos of the listing being created.
* @param editPhotoStorage keeps the photos added to the listing being edited. It must use another
* folder than [photoStorage]: opening a form deletes the photos its folder holds for other forms.
* @param locationRepository finds the lender, to open the listing form's map picker where they are.
* @param locationRepository reads the device's approximate location: to centre the Map tab on the
* renter, and to open the listing form's map picker where the lender is.
* @param connectivityRepository tells the listing forms whether the device is online.
*/
@Composable
Expand All @@ -137,6 +144,7 @@ fun AppNavHost(
locationRepository: LocationRepository,
connectivityRepository: ConnectivityRepository,
navController: NavHostController = rememberNavController(),
listingsMap: @Composable (MapUiState) -> Unit = { ListingsMap(it.centre, it.markers) },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick: this default copies the map default of MapScreen. If one of them changes (say ListingsMap gets a new param), the app could quietly stop matching what MapScreen does. Could listingsMap be nullable here and only be passed on to MapScreen when it's set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good points, both are in #394 so they don't reset the approval here.

) {
val uiState by authViewModel.uiState.collectAsState()
val snackbarHostState = remember { SnackbarHostState() }
Expand Down Expand Up @@ -536,6 +544,29 @@ fun AppNavHost(
onBack = { navController.popBackStack() },
)
}
composable(Routes.MAP) {
val uid = uiState.user?.uid ?: return@composable
// Keyed by uid, like Browse: the map leaves out the signed-in user's own listings.
val mapViewModel: MapViewModel =
viewModel(
key = "map_$uid",
factory =
viewModelFactory {
initializer {
MapViewModel(
locationRepository = locationRepository,
listingRepository = listingRepository,
currentUid = uid,
savedStateHandle = createSavedStateHandle(),
)
}
},
)
// Coming back to the tab shows listings created or paused meanwhile. On opening, the
// ViewModel ignores this call while its first load runs.
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { mapViewModel.loadListings() }
MapScreen(viewModel = mapViewModel, map = listingsMap)
}
composable(Routes.INBOX) {
// Renders nothing for the frame between sign-out and the redirect to sign-in.
val uid = uiState.user?.uid ?: return@composable
Expand Down Expand Up @@ -682,6 +713,7 @@ private val signedInRoutes =
setOf(
Routes.VERIFY_EMAIL,
Routes.BROWSE,
Routes.MAP,
Routes.CREATE_LISTING,
Routes.EDIT_LISTING,
Routes.LISTING_DETAIL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.android.polybazaar.auth.ui.AuthColors
object BottomBarTags {
const val BAR = "bottom_bar"
const val BROWSE_TAB = "bottom_bar_browse_tab"
const val MAP_TAB = "bottom_bar_map_tab"
const val CREATE_LISTING_TAB = "bottom_bar_create_listing_tab"
const val CONVERSATIONS_TAB = "bottom_bar_conversations_tab"
const val PROFILE_TAB = "bottom_bar_profile_tab"
Expand All @@ -61,6 +62,13 @@ private val tabs =
R.drawable.ic_nav_browse,
BottomBarTags.BROWSE_TAB,
),
// Second, next to Browse: the same listings, on a map (Figma "Map — …" frames, #341).
BottomBarTab(
Routes.MAP,
R.string.nav_map,
R.drawable.ic_nav_map,
BottomBarTags.MAP_TAB,
),
BottomBarTab(
Routes.CREATE_LISTING,
R.string.nav_create_listing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object Routes {
const val FORGOT_PASSWORD = "forgot_password"
const val VERIFY_EMAIL = "verify_email"
const val BROWSE = "browse"
const val MAP = "map"
const val CREATE_LISTING = "create_listing"
const val LISTING_ID = "listingId"
const val EDIT_LISTING = "edit_listing/{$LISTING_ID}"
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_nav_map.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Co-authored-by: Claude Code (Claude Opus 5.5) -->
<!-- "map" (folded map) icon of the Map tab in the bottom bar (Figma "Map — …" frames). -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="21dp"
android:height="21dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:strokeColor="#20231F"
android:strokeWidth="2"
android:strokeLineCap="round"
android:strokeLineJoin="round"
android:pathData="M14.106,5.553a2,2 0,0 0,1.788 0l3.659,-1.83A1,1 0,0 1,21 4.619v12.764a1,1 0,0 1,-0.553 0.894l-4.553,2.277a2,2 0,0 1,-1.788 0l-4.212,-2.106a2,2 0,0 0,-1.788 0l-3.659,1.83A1,1 0,0 1,3 19.381V6.618a1,1 0,0 1,0.553 -0.894l4.553,-2.277a2,2 0,0 1,1.788 0zM15,5.764v15M9,3.236v15" />
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<!-- Bottom navigation -->
<string name="nav_browse">Browse</string>
<string name="nav_map">Map</string>
<string name="nav_create_listing">Create listing</string>
<string name="nav_conversations">Conversations</string>
<string name="nav_profile">Profile</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ package com.android.polybazaar.ui.navigation
import android.content.Context
import android.net.Uri
import androidx.activity.compose.LocalActivityResultRegistryOwner
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.semantics.SemanticsProperties
Expand Down Expand Up @@ -80,11 +84,14 @@ import com.android.polybazaar.listing.model.FakeListingRepository
import com.android.polybazaar.listing.model.FilePhotoStorage
import com.android.polybazaar.listing.model.ItemListing
import com.android.polybazaar.listing.model.ListingCategory
import com.android.polybazaar.listing.model.ListingLocation
import com.android.polybazaar.listing.model.ServiceListing
import com.android.polybazaar.listing.ui.CreateListingScreenTags
import com.android.polybazaar.listing.ui.EditListingScreenTags
import com.android.polybazaar.listing.ui.ListingDetailScreenTags
import com.android.polybazaar.map.model.FakeLocationRepository
import com.android.polybazaar.map.ui.MapScreenTags
import com.android.polybazaar.map.viewmodel.MapUiState
import com.android.polybazaar.profile.model.ProfileRepository
import com.android.polybazaar.profile.ui.EditProfileScreenTags
import com.android.polybazaar.profile.ui.LenderProfileScreenTags
Expand Down Expand Up @@ -134,6 +141,10 @@ class AppNavHostTest {
private val listingRepository = FakeListingRepository(ownerUid = user.uid)
private val chatRepository = FakeChatRepository()
private val bookingRepository = FakeBookingRepository()
private val locationRepository = FakeLocationRepository()

/** What the Map tab last gave its map: the stand-in records it, since it draws no markers. */
private var mapState: MapUiState? = null
private val photoStorage =
FilePhotoStorage(
ApplicationProvider.getApplicationContext(),
Expand Down Expand Up @@ -166,7 +177,12 @@ class AppNavHostTest {
editPhotoStorage = editPhotoStorage,
chatRepository = chatRepository,
bookingRepository = bookingRepository,
locationRepository = FakeLocationRepository(),
locationRepository = locationRepository,
// Google Maps can't run under Robolectric: a stand-in that shows the markers.
listingsMap = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick: this stand-in is copied in both setContent helpers (here and l.231), and l.714/1548/1627 use another one, { mapState = it }. Also no test ever looks up MAP_STAND_IN, and the comment says it shows the markers while it's an empty box. Could it be one shared private val mapStandIn, with the unused tag dropped or the comment fixed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good points, both are in #394 so they don't reset the approval here.

mapState = it
Box(Modifier.fillMaxSize().testTag(MAP_STAND_IN))
},
connectivityRepository = FakeConnectivityRepository(),
navController = navController,
)
Expand Down Expand Up @@ -210,7 +226,12 @@ class AppNavHostTest {
editPhotoStorage = editPhotoStorage,
chatRepository = chatRepository,
bookingRepository = bookingRepository,
locationRepository = FakeLocationRepository(),
locationRepository = locationRepository,
// Google Maps can't run under Robolectric: a stand-in that shows the markers.
listingsMap = {
mapState = it
Box(Modifier.fillMaxSize().testTag(MAP_STAND_IN))
},
connectivityRepository = FakeConnectivityRepository(),
navController = navController,
)
Expand Down Expand Up @@ -260,6 +281,12 @@ class AppNavHostTest {
assertEquals(Routes.INBOX, navController.currentBackStackEntry?.destination?.route)
}

private fun openMap() {
composeTestRule.onNodeWithTag(BottomBarTags.MAP_TAB).performClick()
composeTestRule.onNodeWithTag(MapScreenTags.SCREEN).assertIsDisplayed()
assertEquals(Routes.MAP, navController.currentBackStackEntry?.destination?.route)
}

private fun openBrowse() {
composeTestRule.onNodeWithTag(BottomBarTags.BROWSE_TAB).performClick()
composeTestRule.onNodeWithTag(BrowseScreenTags.SCREEN).assertIsDisplayed()
Expand Down Expand Up @@ -681,9 +708,10 @@ class AppNavHostTest {
editPhotoStorage = editPhotoStorage,
chatRepository = chatRepository,
bookingRepository = bookingRepository,
locationRepository = FakeLocationRepository(),
locationRepository = locationRepository,
connectivityRepository = FakeConnectivityRepository(),
navController = navController,
listingsMap = { mapState = it },
)
}

Expand Down Expand Up @@ -1514,9 +1542,10 @@ class AppNavHostTest {
editPhotoStorage = editPhotoStorage,
chatRepository = chatRepository,
bookingRepository = bookingRepository,
locationRepository = FakeLocationRepository(),
locationRepository = locationRepository,
connectivityRepository = FakeConnectivityRepository(),
navController = navController,
listingsMap = { mapState = it },
)
}
openProfile()
Expand Down Expand Up @@ -1592,9 +1621,10 @@ class AppNavHostTest {
editPhotoStorage = editPhotoStorage,
chatRepository = chatRepository,
bookingRepository = bookingRepository,
locationRepository = FakeLocationRepository(),
locationRepository = locationRepository,
connectivityRepository = FakeConnectivityRepository(),
navController = navController,
listingsMap = { mapState = it },
)
}
composeTestRule.onNodeWithTag(VerifyEmailScreenTags.SCREEN).assertIsDisplayed()
Expand Down Expand Up @@ -1664,6 +1694,9 @@ class AppNavHostTest {
composeTestRule.onNodeWithTag(BrowseScreenTags.SCREEN).assertIsDisplayed()
composeTestRule.onNodeWithTag(BottomBarTags.BAR).assertIsDisplayed()

openMap()
composeTestRule.onNodeWithTag(BottomBarTags.BAR).assertIsDisplayed()

openCreateListing()
composeTestRule.onNodeWithTag(BottomBarTags.BAR).assertIsDisplayed()

Expand All @@ -1674,6 +1707,39 @@ class AppNavHostTest {
composeTestRule.onNodeWithTag(BottomBarTags.BAR).assertIsDisplayed()
}

@Test
fun mapTab_isSecond_betweenBrowseAndCreateListing() {
setContent(FakeAuthRepository(currentUser = user))

fun left(tag: String) = composeTestRule.onNodeWithTag(tag).getBoundsInRoot().left
assertTrue(left(BottomBarTags.BROWSE_TAB) < left(BottomBarTags.MAP_TAB))
assertTrue(left(BottomBarTags.MAP_TAB) < left(BottomBarTags.CREATE_LISTING_TAB))
}

@Test
fun mapTab_showsOtherUsersListingsWithALocation_andReloadsWhenComingBack() {
val rolex = ListingLocation(46.5185, 6.5683, "Rolex Learning Center")
listingRepository.allListings =
listOf(
gracesDrill.copy(location = rolex),
gracesDrill.copy(listingId = "nowhere", title = "No location"),
)
setContent(FakeAuthRepository(currentUser = user))

openMap()
composeTestRule.waitForIdle()
assertEquals(listOf("drill"), mapState?.markers?.map { it.id })

// A listing placed meanwhile shows when the renter comes back to the tab.
listingRepository.allListings =
listingRepository.allListings + gracesDrill.copy(listingId = "tent", location = rolex)
openBrowse()
openMap()
composeTestRule.waitForIdle()

assertEquals(listOf("drill", "tent"), mapState?.markers?.map { it.id })
}

@Test
fun bottomBar_isHiddenOnLoading() {
setContent(FakeAuthRepository(currentUserGate = CompletableDeferred()))
Expand Down Expand Up @@ -2228,3 +2294,6 @@ class AppNavHostTest {
}

private const val NETWORK_MESSAGE = "No connection. Check your internet and try again."

/** Tag of the stand-in drawn instead of the Google map, which can't run under Robolectric. */
private const val MAP_STAND_IN = "map_stand_in"
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class EndToEndFlowTest {
chatRepository = FakeChatRepository(),
bookingRepository = FakeBookingRepository(),
locationRepository = FakeLocationRepository(),
listingsMap = {},
connectivityRepository = FakeConnectivityRepository(),
navController = navController,
)
Expand Down
Loading