Skip to content

Commit 371fbbb

Browse files
authored
Merge pull request #118 from cuappdev/jonathan/eaterymarkers
Map pins and improvements
2 parents b61d2a4 + 03959f9 commit 371fbbb

9 files changed

Lines changed: 207 additions & 5 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.cornellappdev.transit.ui.components.home
2+
3+
import androidx.annotation.DrawableRes
4+
import androidx.compose.material.Icon
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.ui.graphics.Color
7+
import androidx.compose.ui.res.painterResource
8+
import com.cornellappdev.transit.R
9+
import com.cornellappdev.transit.models.Place
10+
import com.cornellappdev.transit.models.ecosystem.StaticPlaces
11+
import com.cornellappdev.transit.networking.ApiResponse
12+
import com.cornellappdev.transit.ui.viewmodels.FilterState
13+
import com.google.android.gms.maps.model.LatLng
14+
import com.google.maps.android.compose.GoogleMapComposable
15+
import com.google.maps.android.compose.MarkerComposable
16+
import com.google.maps.android.compose.rememberMarkerState
17+
18+
/**
19+
* Set of pins displayed on the home screen map depending on the [filterState]
20+
*/
21+
@Composable
22+
@GoogleMapComposable
23+
fun HomeScreenMarkers(filterState: FilterState, favorites: Set<Place>, staticPlaces: StaticPlaces) {
24+
25+
when (filterState) {
26+
FilterState.FAVORITES -> {
27+
favorites.forEach {
28+
LocationMarker(LatLng(it.latitude, it.longitude), R.drawable.favorite_pin)
29+
}
30+
}
31+
32+
FilterState.PRINTERS -> {
33+
if (staticPlaces.printers is ApiResponse.Success) {
34+
staticPlaces.printers.data.forEach {
35+
LocationMarker(LatLng(it.latitude, it.longitude), R.drawable.printer_pin)
36+
}
37+
}
38+
}
39+
40+
FilterState.GYMS -> {
41+
if (staticPlaces.gyms is ApiResponse.Success) {
42+
staticPlaces.gyms.data.forEach {
43+
LocationMarker(LatLng(it.latitude, it.longitude), R.drawable.gym_pin)
44+
}
45+
}
46+
}
47+
48+
FilterState.EATERIES -> {
49+
if (staticPlaces.eateries is ApiResponse.Success) {
50+
staticPlaces.eateries.data.forEach { eatery ->
51+
eatery.latitude?.let { latitude ->
52+
eatery.longitude?.let { longitude ->
53+
LocationMarker(LatLng(latitude, longitude), R.drawable.eatery_pin)
54+
}
55+
}
56+
}
57+
}
58+
}
59+
60+
FilterState.LIBRARIES -> {
61+
if (staticPlaces.libraries is ApiResponse.Success) {
62+
staticPlaces.libraries.data.forEach {
63+
LocationMarker(LatLng(it.latitude, it.longitude), R.drawable.library_pin)
64+
}
65+
}
66+
}
67+
}
68+
}
69+
70+
@Composable
71+
private fun LocationMarker(
72+
position: LatLng,
73+
@DrawableRes iconRes: Int
74+
) {
75+
MarkerComposable(
76+
state = rememberMarkerState(
77+
position = position
78+
)
79+
) {
80+
Icon(
81+
painter = painterResource(iconRes),
82+
contentDescription = null,
83+
tint = Color.Unspecified
84+
)
85+
}
86+
}

app/src/main/java/com/cornellappdev/transit/ui/screens/DetailsScreen.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.compose.foundation.background
77
import androidx.compose.foundation.clickable
88
import androidx.compose.foundation.layout.Arrangement
99
import androidx.compose.foundation.layout.Column
10+
import androidx.compose.foundation.layout.PaddingValues
1011
import androidx.compose.foundation.layout.Row
1112
import androidx.compose.foundation.layout.fillMaxSize
1213
import androidx.compose.foundation.layout.fillMaxWidth
@@ -59,6 +60,7 @@ import com.cornellappdev.transit.ui.theme.TransitBlue
5960
import com.cornellappdev.transit.ui.theme.robotoFamily
6061
import com.cornellappdev.transit.ui.viewmodels.DirectionDetails
6162
import com.cornellappdev.transit.ui.viewmodels.RouteViewModel
63+
import com.cornellappdev.transit.util.orZeroIfUnspecified
6264
import com.google.accompanist.permissions.ExperimentalPermissionsApi
6365
import com.google.accompanist.permissions.isGranted
6466
import com.google.accompanist.permissions.rememberPermissionState
@@ -78,8 +80,10 @@ import com.google.maps.android.compose.MarkerState
7880
import com.google.maps.android.compose.Polyline
7981
import com.google.maps.android.compose.rememberCameraPositionState
8082
import io.morfly.compose.bottomsheet.material3.BottomSheetScaffold
83+
import io.morfly.compose.bottomsheet.material3.BottomSheetState
8184
import io.morfly.compose.bottomsheet.material3.rememberBottomSheetScaffoldState
8285
import io.morfly.compose.bottomsheet.material3.rememberBottomSheetState
86+
import io.morfly.compose.bottomsheet.material3.sheetVisibleHeightDp
8387

8488

8589
private enum class DetailsSheetValue { Collapsed, PartiallyExpanded, Expanded }
@@ -147,6 +151,7 @@ fun DetailsScreen(navController: NavHostController, routeViewModel: RouteViewMod
147151
// Screen content
148152
DetailsMainScreen(
149153
mapState,
154+
sheetState,
150155
cameraPositionState,
151156
permissionState.status.isGranted,
152157
onBackClick = { navController.popBackStack() },
@@ -158,10 +163,11 @@ fun DetailsScreen(navController: NavHostController, routeViewModel: RouteViewMod
158163
/**
159164
* Background map and contents
160165
*/
161-
@OptIn(ExperimentalPermissionsApi::class)
166+
@OptIn(ExperimentalFoundationApi::class)
162167
@Composable
163168
private fun DrawableMap(
164169
mapState: MapState,
170+
sheetState: BottomSheetState<DetailsSheetValue>,
165171
cameraPositionState: CameraPositionState,
166172
hasLocationPermission: Boolean
167173
) {
@@ -171,7 +177,10 @@ private fun DrawableMap(
171177
properties = MapProperties(
172178
isMyLocationEnabled = hasLocationPermission
173179
),
174-
uiSettings = MapUiSettings(zoomControlsEnabled = false)
180+
uiSettings = MapUiSettings(zoomControlsEnabled = false, mapToolbarEnabled = false),
181+
contentPadding = PaddingValues(
182+
bottom = sheetState.sheetVisibleHeightDp.orZeroIfUnspecified()
183+
)
175184
) {
176185
mapState.route?.directions?.takeIf { mapState.isShowing }?.let { directions ->
177186
directions.forEach { direction ->
@@ -367,10 +376,11 @@ private fun DetailsBottomSheet(
367376
}
368377
}
369378

370-
@OptIn(ExperimentalMaterial3Api::class)
379+
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
371380
@Composable
372381
private fun DetailsMainScreen(
373382
mapState: MapState,
383+
sheetState: BottomSheetState<DetailsSheetValue>,
374384
cameraPositionState: CameraPositionState,
375385
hasLocationPermission: Boolean,
376386
onBackClick: () -> Unit,
@@ -400,6 +410,7 @@ private fun DetailsMainScreen(
400410

401411
DrawableMap(
402412
mapState,
413+
sheetState,
403414
cameraPositionState,
404415
hasLocationPermission
405416
)

app/src/main/java/com/cornellappdev/transit/ui/screens/HomeScreen.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.foundation.clickable
99
import androidx.compose.foundation.gestures.detectTapGestures
1010
import androidx.compose.foundation.layout.Box
1111
import androidx.compose.foundation.layout.Column
12+
import androidx.compose.foundation.layout.PaddingValues
1213
import androidx.compose.foundation.layout.Spacer
1314
import androidx.compose.foundation.layout.fillMaxSize
1415
import androidx.compose.foundation.layout.fillMaxWidth
@@ -61,6 +62,7 @@ import com.cornellappdev.transit.ui.components.LoadingLocationItems
6162
import com.cornellappdev.transit.ui.components.SearchSuggestions
6263
import com.cornellappdev.transit.ui.components.home.DetailedPlaceSheetContent
6364
import com.cornellappdev.transit.ui.components.home.EcosystemBottomSheetContent
65+
import com.cornellappdev.transit.ui.components.home.HomeScreenMarkers
6466
import com.cornellappdev.transit.ui.theme.DetailsHeaderGray
6567
import com.cornellappdev.transit.ui.theme.DividerGray
6668
import com.cornellappdev.transit.ui.theme.IconGray
@@ -71,6 +73,7 @@ import com.cornellappdev.transit.ui.viewmodels.HomeViewModel
7173
import com.cornellappdev.transit.ui.viewmodels.SearchBarUIState
7274
import com.cornellappdev.transit.util.BOTTOM_SHEET_MAX_HEIGHT_PERCENT
7375
import com.cornellappdev.transit.util.ECOSYSTEM_FLAG
76+
import com.cornellappdev.transit.util.orZeroIfUnspecified
7477
import com.google.accompanist.permissions.ExperimentalPermissionsApi
7578
import com.google.accompanist.permissions.isGranted
7679
import com.google.accompanist.permissions.rememberPermissionState
@@ -80,6 +83,7 @@ import com.google.maps.android.compose.MapProperties
8083
import com.google.maps.android.compose.MapUiSettings
8184
import com.google.maps.android.compose.rememberCameraPositionState
8285
import io.morfly.compose.bottomsheet.material3.rememberBottomSheetState
86+
import io.morfly.compose.bottomsheet.material3.sheetVisibleHeightDp
8387
import kotlinx.coroutines.launch
8488

8589
private enum class HomeSheetValue { Collapsed, PartiallyExpanded, Expanded }
@@ -224,8 +228,13 @@ fun HomeScreen(
224228
properties = MapProperties(
225229
isMyLocationEnabled = permissionState.status.isGranted
226230
),
227-
uiSettings = MapUiSettings(zoomControlsEnabled = false)
228-
)
231+
uiSettings = MapUiSettings(zoomControlsEnabled = false, mapToolbarEnabled = false),
232+
contentPadding = PaddingValues(
233+
bottom = filterSheetState.sheetVisibleHeightDp.orZeroIfUnspecified()
234+
)
235+
) {
236+
HomeScreenMarkers(filterStateValue, favorites, staticPlaces)
237+
}
229238

230239
// Overlay transparent box to intercept clicks to disable search
231240
if (searchActive) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.cornellappdev.transit.util
2+
3+
import androidx.compose.ui.unit.Dp
4+
import androidx.compose.ui.unit.dp
5+
6+
fun Dp.orZeroIfUnspecified(): Dp = if (this == Dp.Unspecified) 0.dp else this
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="32dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="32">
6+
<path
7+
android:pathData="M12,0C5.716,0 0.458,5.04 0.017,11.476C-0.137,14.429 0.766,17.34 2.565,19.687L11.154,31.198C11.354,31.466 11.668,31.623 12.002,31.623C12.336,31.623 12.65,31.466 12.849,31.198L21.435,19.687C23.234,17.34 24.138,14.429 23.983,11.476C23.542,5.04 18.284,0 12,0Z"
8+
android:fillColor="#079DDC"/>
9+
<path
10+
android:pathData="M16.5,14C13.7,9.6 9.667,9.167 8,9.5C7.667,12.167 7,17.7 7,18.5C7,19.3 8.333,19.5 9,19.5L16.5,14Z"
11+
android:fillColor="#ffffff"/>
12+
<path
13+
android:pathData="M9.57,13.177C10.048,13.453 10.66,13.29 10.936,12.811C11.212,12.333 11.048,11.721 10.57,11.445C10.092,11.169 9.48,11.333 9.204,11.811C8.928,12.29 9.092,12.901 9.57,13.177Z"
14+
android:fillColor="#079DDC"/>
15+
<path
16+
android:pathData="M13.823,14.478C13.547,14.956 12.935,15.12 12.457,14.844C11.979,14.568 11.815,13.956 12.091,13.478C12.367,13 12.979,12.836 13.457,13.112C13.935,13.388 14.099,14 13.823,14.478Z"
17+
android:fillColor="#079DDC"/>
18+
<path
19+
android:pathData="M9.347,16.897C9.825,17.174 10.437,17.01 10.713,16.531C10.989,16.053 10.825,15.441 10.347,15.165C9.868,14.889 9.257,15.053 8.981,15.531C8.705,16.01 8.868,16.621 9.347,16.897Z"
20+
android:fillColor="#079DDC"/>
21+
<path
22+
android:pathData="M14.68,7.66C12.859,6.609 10.806,6.006 9.479,5.693C8.285,5.411 7.224,6.307 7.154,7.465L6.508,18.237C6.409,19.882 8.231,20.934 9.606,20.026L18.612,14.08C19.58,13.441 19.825,12.074 18.984,11.181C18.05,10.188 16.501,8.711 14.68,7.66ZM9.173,6.991C10.447,7.291 12.356,7.857 14.014,8.815C15.671,9.772 17.117,11.142 18.013,12.094C18.242,12.337 18.211,12.747 17.877,12.967L17.174,13.431C17.025,13.212 16.829,12.947 16.583,12.654C15.914,11.857 14.868,10.847 13.347,9.969C11.826,9.091 10.428,8.69 9.404,8.509C9.027,8.442 8.699,8.406 8.435,8.386L8.485,7.545C8.509,7.145 8.849,6.914 9.173,6.991ZM15.561,13.511C15.771,13.761 15.936,13.984 16.061,14.166L8.871,18.913C8.413,19.216 7.806,18.865 7.839,18.317L8.355,9.717C8.575,9.734 8.851,9.765 9.172,9.822C10.069,9.981 11.314,10.335 12.68,11.124C14.046,11.912 14.976,12.814 15.561,13.511Z"
23+
android:fillColor="#ffffff"
24+
android:fillType="evenOdd"/>
25+
<path
26+
android:pathData="M19,12C16.2,8.8 11.167,7 9,6.5H8V8V9L10,9.5L12.5,10.5L15,12L17.5,14L18.5,13.5L19,12Z"
27+
android:fillColor="#ffffff"/>
28+
<path
29+
android:pathData="M9,8C12,9 14,10 17,12.5"
30+
android:strokeWidth="1.5"
31+
android:fillColor="#00000000"
32+
android:strokeColor="#079DDC"
33+
android:strokeLineCap="round"/>
34+
</vector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="32dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="32">
6+
<path
7+
android:pathData="M12,0C5.716,0 0.458,5.04 0.017,11.476C-0.137,14.429 0.766,17.34 2.565,19.687L11.154,31.198C11.354,31.466 11.668,31.623 12.002,31.623C12.336,31.623 12.65,31.466 12.849,31.198L21.435,19.687C23.234,17.34 24.138,14.429 23.983,11.476C23.542,5.04 18.284,0 12,0Z"
8+
android:fillColor="#D82D4D"/>
9+
<path
10+
android:pathData="M12,7.166L13.803,10.818L17.833,11.407L14.917,14.248L15.605,18.261L12,16.365L8.395,18.261L9.083,14.248L6.167,11.407L10.198,10.818L12,7.166Z"
11+
android:strokeLineJoin="round"
12+
android:strokeWidth="0.928571"
13+
android:fillColor="#ffffff"
14+
android:strokeColor="#ffffff"
15+
android:strokeLineCap="round"/>
16+
</vector>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="32dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="32">
6+
<path
7+
android:pathData="M12,0C5.716,0 0.458,5.04 0.017,11.476C-0.137,14.429 0.766,17.34 2.565,19.687L11.154,31.198C11.354,31.466 11.668,31.623 12.002,31.623C12.336,31.623 12.65,31.466 12.849,31.198L21.435,19.687C23.234,17.34 24.138,14.429 23.983,11.476C23.542,5.04 18.284,0 12,0Z"
8+
android:fillColor="#E79C20"/>
9+
<path
10+
android:pathData="M17.334,10V15.333C17.334,15.701 17,16.333 16.334,16.333C15.667,16.333 15.334,15.701 15.334,15.333V13.667H8.667V15.333C8.667,15.701 8.334,16.333 7.667,16.333C7,16.333 6.667,15.701 6.667,15.333V10C6.667,9.632 7,9 7.667,9C8.334,9 8.667,9.632 8.667,10V11.667H15.334V10C15.334,9.632 15.667,9 16.334,9C17,9 17.334,9.632 17.334,10ZM4,12C4,11.448 4.448,11 5,11C5.552,11 6,11.448 6,12V13.333C6,13.885 5.552,14.333 5,14.333C4.448,14.333 4,13.885 4,13.333V12ZM18,12C18,11.448 18.448,11 19,11C19.552,11 20,11.448 20,12V13.333C20,13.885 19.552,14.333 19,14.333C18.448,14.333 18,13.885 18,13.333V12Z"
11+
android:fillColor="#ffffff"
12+
android:fillType="evenOdd"/>
13+
</vector>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="32dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="32">
6+
<path
7+
android:pathData="M12,0C5.716,0 0.458,5.04 0.017,11.476C-0.137,14.429 0.766,17.34 2.565,19.687L11.154,31.198C11.354,31.466 11.668,31.623 12.002,31.623C12.336,31.623 12.65,31.466 12.849,31.198L21.435,19.687C23.234,17.34 24.138,14.429 23.983,11.476C23.542,5.04 18.284,0 12,0Z"
8+
android:fillColor="#1BAF5D"/>
9+
<path
10+
android:pathData="M12,11.674C10.938,10.683 9.597,9.989 8.103,9.72C7.398,9.598 6.75,10.158 6.75,10.875V14.515C6.75,15.495 7.17,16.008 7.747,16.084C9.206,16.271 10.53,16.872 11.615,17.758C11.819,17.928 12.152,17.945 12.356,17.782C13.447,16.889 14.783,16.277 16.253,16.09C16.801,16.014 17.25,15.472 17.25,14.912V10.875C17.25,10.158 16.603,9.598 15.897,9.72C14.403,9.989 13.062,10.683 12,11.674ZM12,9.604C12.968,9.604 13.75,8.822 13.75,7.854C13.75,6.885 12.968,6.104 12,6.104C11.032,6.104 10.25,6.885 10.25,7.854C10.25,8.822 11.032,9.604 12,9.604Z"
11+
android:fillColor="#ffffff"/>
12+
</vector>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="32dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="32">
6+
<path
7+
android:pathData="M12,0C5.716,0 0.458,5.04 0.017,11.476C-0.137,14.429 0.766,17.34 2.565,19.687L11.154,31.198C11.354,31.466 11.668,31.623 12.002,31.623C12.336,31.623 12.65,31.466 12.849,31.198L21.435,19.687C23.234,17.34 24.138,14.429 23.983,11.476C23.542,5.04 18.284,0 12,0Z"
8+
android:fillColor="#616161"/>
9+
<path
10+
android:pathData="M15.6,10.222V8.556C15.6,8.25 15.33,8 15,8H9C8.67,8 8.4,8.25 8.4,8.556V10.222H15.6Z"
11+
android:fillColor="#ffffff"/>
12+
<path
13+
android:pathData="M16.2,10.778H7.8C6.804,10.778 6,11.522 6,12.444V15.222C6,15.528 6.27,15.778 6.6,15.778H8.4V16.889C8.4,17.5 8.94,18 9.6,18H14.4C15.06,18 15.6,17.5 15.6,16.889V15.778H17.4C17.73,15.778 18,15.528 18,15.222V12.444C18,11.522 17.196,10.778 16.2,10.778ZM14.4,16.889H9.6V14.667H14.4V16.889ZM15.6,13.278C15.27,13.278 15,13.028 15,12.722C15,12.417 15.27,12.167 15.6,12.167C15.93,12.167 16.2,12.417 16.2,12.722C16.2,13.028 15.93,13.278 15.6,13.278Z"
14+
android:fillColor="#ffffff"/>
15+
</vector>

0 commit comments

Comments
 (0)