From ad387749f8305710fc4d62829eb8d0ecd8dbc748 Mon Sep 17 00:00:00 2001 From: IB-12 <100189489+IB-12@users.noreply.github.com> Date: Tue, 9 Apr 2024 18:06:22 +0200 Subject: [PATCH 1/8] Redid my work on a fresh fork of main due to some weird issue on the previous branch --- .../ch/epfl/cs311/wanderwave/ui/MapTest.kt | 39 +++++++++++++++++++ .../cs311/wanderwave/model/data/Beacon.kt | 13 +++++++ .../cs311/wanderwave/model/data/Location.kt | 22 +++++++++++ .../cs311/wanderwave/ui/screens/MapScreen.kt | 33 +++++++++++++++- 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt create mode 100644 app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Beacon.kt create mode 100644 app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Location.kt diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt new file mode 100644 index 000000000..ed77204a3 --- /dev/null +++ b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt @@ -0,0 +1,39 @@ +package ch.epfl.cs311.wanderwave.ui + +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import ch.epfl.cs311.wanderwave.ui.screens.MapScreen +import com.kaspersky.components.composesupport.config.withComposeSupport +import com.kaspersky.kaspresso.kaspresso.Kaspresso +import com.kaspersky.kaspresso.testcases.api.testcase.TestCase +import dagger.hilt.android.testing.HiltAndroidTest +import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +@HiltAndroidTest +class MapTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComposeSupport()) { + + @get:Rule val composeTestRule = createAndroidComposeRule() + + @Before + fun setup() { + composeTestRule.setContent { MapScreen() } + } + + @Test + fun mapIsDisplayed() = run { + onComposeScreen(composeTestRule) { assertIsDisplayed() } + } + + @Test + fun beaconsAreDisplayed() = run { + onComposeScreen(composeTestRule) { + //Note: There is unfortunately no way to check whether markers are displayed on the map + //due to the way GoogleMaps handles them. + } + } +} diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Beacon.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Beacon.kt new file mode 100644 index 000000000..3a93c9c9d --- /dev/null +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Beacon.kt @@ -0,0 +1,13 @@ +package ch.epfl.cs311.wanderwave.model.data + +data class Beacon( + + /** GUID of the beacon */ + val id: String, + + /** Location of the beacon */ + val location: Location, + + /** List of tracks that are broadcast from the beacon */ + val tracks: List = listOf(), +) diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Location.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Location.kt new file mode 100644 index 000000000..9d350bf48 --- /dev/null +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Location.kt @@ -0,0 +1,22 @@ +package ch.epfl.cs311.wanderwave.model.data + +import com.google.android.gms.maps.model.LatLng + +data class Location( + /** Latitude of the location */ + val latitude: Double, + + /** Longitude of the location */ + val longitude: Double, + + /** + * Name of the location. + * Useful if the location corresponds to some point of interest. + */ + val name: String = "", + +) { + fun toLatLng(): LatLng { + return LatLng(latitude, longitude) + } +} diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt index 1c86e0eed..0f0b1b881 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt @@ -4,10 +4,41 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.tooling.preview.Preview +import ch.epfl.cs311.wanderwave.model.data.Beacon +import ch.epfl.cs311.wanderwave.model.data.Location import com.google.maps.android.compose.GoogleMap +import com.google.maps.android.compose.Marker +import com.google.maps.android.compose.MarkerState @Composable @Preview fun MapScreen() { - GoogleMap(modifier = Modifier.testTag("mapScreen")) + //TODO: Replace with actual data once implemented + val mockBeacons = listOf( + Beacon("INM" , Location(46.51857556996283, 6.5631609607190775)), + Beacon("BC" , Location(46.51857417773428, 6.5619195033506434)), + Beacon("STCC", Location(46.52298529087412, 6.564644391110982 )), + Beacon("RLC" , Location(46.51846723837138, 6.568149323030634 ))) + + GoogleMap(modifier = Modifier.testTag("mapScreen")){ + DisplayBeacons(beacons = mockBeacons) + } } + + +/** + * This is a Composable function that displays the beacons on the map. It takes a list of beacons as + * input and adds a marker for each beacon on the map. + * + * @param beacons The list of beacons to be displayed on the map. + */ +@Composable +fun DisplayBeacons(beacons: List) { + // Add a marker for each beacon + beacons.forEach() { + Marker( + state = MarkerState(position = it.location.toLatLng()), + title = it.id, + ) + } +} \ No newline at end of file From 044c61ce5388efd2bb9a9826f7f5a9ba9cfa9387 Mon Sep 17 00:00:00 2001 From: IB-12 <100189489+IB-12@users.noreply.github.com> Date: Tue, 9 Apr 2024 18:13:30 +0200 Subject: [PATCH 2/8] Applied ktfmt --- .../ch/epfl/cs311/wanderwave/ui/MapTest.kt | 8 +++---- .../cs311/wanderwave/model/data/Beacon.kt | 12 +++++----- .../cs311/wanderwave/model/data/Location.kt | 16 +++++-------- .../cs311/wanderwave/ui/screens/MapScreen.kt | 24 +++++++++---------- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt index ed77204a3..2805aad20 100644 --- a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt +++ b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt @@ -25,15 +25,13 @@ class MapTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComposeSupport } @Test - fun mapIsDisplayed() = run { - onComposeScreen(composeTestRule) { assertIsDisplayed() } - } + fun mapIsDisplayed() = run { onComposeScreen(composeTestRule) { assertIsDisplayed() } } @Test fun beaconsAreDisplayed() = run { onComposeScreen(composeTestRule) { - //Note: There is unfortunately no way to check whether markers are displayed on the map - //due to the way GoogleMaps handles them. + // Note: There is unfortunately no way to check whether markers are displayed on the map + // due to the way GoogleMaps handles them. } } } diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Beacon.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Beacon.kt index 3a93c9c9d..aa77439eb 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Beacon.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Beacon.kt @@ -2,12 +2,12 @@ package ch.epfl.cs311.wanderwave.model.data data class Beacon( - /** GUID of the beacon */ - val id: String, + /** GUID of the beacon */ + val id: String, - /** Location of the beacon */ - val location: Location, + /** Location of the beacon */ + val location: Location, - /** List of tracks that are broadcast from the beacon */ - val tracks: List = listOf(), + /** List of tracks that are broadcast from the beacon */ + val tracks: List = listOf(), ) diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Location.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Location.kt index 9d350bf48..caa261665 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Location.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/model/data/Location.kt @@ -3,18 +3,14 @@ package ch.epfl.cs311.wanderwave.model.data import com.google.android.gms.maps.model.LatLng data class Location( - /** Latitude of the location */ - val latitude: Double, + /** Latitude of the location */ + val latitude: Double, - /** Longitude of the location */ - val longitude: Double, - - /** - * Name of the location. - * Useful if the location corresponds to some point of interest. - */ - val name: String = "", + /** Longitude of the location */ + val longitude: Double, + /** Name of the location. Useful if the location corresponds to some point of interest. */ + val name: String = "", ) { fun toLatLng(): LatLng { return LatLng(latitude, longitude) diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt index 0f0b1b881..e810242ed 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt @@ -13,19 +13,17 @@ import com.google.maps.android.compose.MarkerState @Composable @Preview fun MapScreen() { - //TODO: Replace with actual data once implemented - val mockBeacons = listOf( - Beacon("INM" , Location(46.51857556996283, 6.5631609607190775)), - Beacon("BC" , Location(46.51857417773428, 6.5619195033506434)), - Beacon("STCC", Location(46.52298529087412, 6.564644391110982 )), - Beacon("RLC" , Location(46.51846723837138, 6.568149323030634 ))) + // TODO: Replace with actual data once implemented + val mockBeacons = + listOf( + Beacon("INM", Location(46.51857556996283, 6.5631609607190775)), + Beacon("BC", Location(46.51857417773428, 6.5619195033506434)), + Beacon("STCC", Location(46.52298529087412, 6.564644391110982)), + Beacon("RLC", Location(46.51846723837138, 6.568149323030634))) - GoogleMap(modifier = Modifier.testTag("mapScreen")){ - DisplayBeacons(beacons = mockBeacons) - } + GoogleMap(modifier = Modifier.testTag("mapScreen")) { DisplayBeacons(beacons = mockBeacons) } } - /** * This is a Composable function that displays the beacons on the map. It takes a list of beacons as * input and adds a marker for each beacon on the map. @@ -37,8 +35,8 @@ fun DisplayBeacons(beacons: List) { // Add a marker for each beacon beacons.forEach() { Marker( - state = MarkerState(position = it.location.toLatLng()), - title = it.id, + state = MarkerState(position = it.location.toLatLng()), + title = it.id, ) } -} \ No newline at end of file +} From ae367424aa9b33ac1191c6508bdbd0f535574114 Mon Sep 17 00:00:00 2001 From: IB-12 <100189489+IB-12@users.noreply.github.com> Date: Wed, 10 Apr 2024 21:42:17 +0200 Subject: [PATCH 3/8] Removed empty test --- .../java/ch/epfl/cs311/wanderwave/ui/MapTest.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt index 2805aad20..b2ebd1892 100644 --- a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt +++ b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt @@ -27,11 +27,4 @@ class MapTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComposeSupport @Test fun mapIsDisplayed() = run { onComposeScreen(composeTestRule) { assertIsDisplayed() } } - @Test - fun beaconsAreDisplayed() = run { - onComposeScreen(composeTestRule) { - // Note: There is unfortunately no way to check whether markers are displayed on the map - // due to the way GoogleMaps handles them. - } - } } From 9971efe670e6097b1d1e185359217ad8e0a1c595 Mon Sep 17 00:00:00 2001 From: IB-12 <100189489+IB-12@users.noreply.github.com> Date: Wed, 10 Apr 2024 22:30:32 +0200 Subject: [PATCH 4/8] Implemented viewModel to retrieve Beacons --- .../cs311/wanderwave/ui/screens/MapScreen.kt | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt index 7c4ef83e2..ae6dc6fff 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt @@ -6,10 +6,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.tooling.preview.Preview import ch.epfl.cs311.wanderwave.model.data.Beacon -import ch.epfl.cs311.wanderwave.model.data.Location import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import ch.epfl.cs311.wanderwave.model.data.Beacon import ch.epfl.cs311.wanderwave.viewmodel.MapViewModel import com.google.maps.android.compose.GoogleMap import com.google.maps.android.compose.Marker @@ -18,18 +16,11 @@ import com.google.maps.android.compose.MarkerState @Composable @Preview fun MapScreen() { + val viewModel: MapViewModel = hiltViewModel() + val uiState by viewModel.uiState.collectAsStateWithLifecycle() - val viewModel: MapViewModel = hiltViewModel() - val uiState by viewModel.uiState.collectAsStateWithLifecycle() - // TODO: Replace with actual data once implemented - val mockBeacons = - listOf( - Beacon("INM", Location(46.51857556996283, 6.5631609607190775)), - Beacon("BC", Location(46.51857417773428, 6.5619195033506434)), - Beacon("STCC", Location(46.52298529087412, 6.564644391110982)), - Beacon("RLC", Location(46.51846723837138, 6.568149323030634))) - - GoogleMap(modifier = Modifier.testTag("mapScreen")) { DisplayBeacons(beacons = mockBeacons) } + //TODO: Make sure the beacons are filtered to be within the radius + GoogleMap(modifier = Modifier.testTag("mapScreen")) { DisplayBeacons(beacons = uiState.beacons) } } /** @@ -40,15 +31,11 @@ fun MapScreen() { */ @Composable fun DisplayBeacons(beacons: List) { - - // Add a marker for each beacon - // source for the icon: https://www.svgrepo.com/svg/448258/waypoint - // val customIcon = BitmapDescriptorFactory.fromResource(R.drawable.waypoint) + //Create each beacon from the list beacons.forEach() { Marker( state = MarkerState(position = it.location.toLatLng()), title = it.id, - // icon = customIcon, ) } } From 89c898c7486d032fa451ac8851f6ede042fd6fb5 Mon Sep 17 00:00:00 2001 From: IB-12 <100189489+IB-12@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:50:00 +0200 Subject: [PATCH 5/8] Added condition on beacon display + ktfmt --- .../java/ch/epfl/cs311/wanderwave/ui/MapTest.kt | 1 - .../ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt index b2ebd1892..771363e90 100644 --- a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt +++ b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt @@ -26,5 +26,4 @@ class MapTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComposeSupport @Test fun mapIsDisplayed() = run { onComposeScreen(composeTestRule) { assertIsDisplayed() } } - } diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt index ae6dc6fff..30e26a792 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt @@ -5,9 +5,9 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.tooling.preview.Preview -import ch.epfl.cs311.wanderwave.model.data.Beacon import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import ch.epfl.cs311.wanderwave.model.data.Beacon import ch.epfl.cs311.wanderwave.viewmodel.MapViewModel import com.google.maps.android.compose.GoogleMap import com.google.maps.android.compose.Marker @@ -19,8 +19,11 @@ fun MapScreen() { val viewModel: MapViewModel = hiltViewModel() val uiState by viewModel.uiState.collectAsStateWithLifecycle() - //TODO: Make sure the beacons are filtered to be within the radius - GoogleMap(modifier = Modifier.testTag("mapScreen")) { DisplayBeacons(beacons = uiState.beacons) } + // TODO: Make sure the beacons are filtered to be within the radius + + GoogleMap(modifier = Modifier.testTag("mapScreen")) { + if (!uiState.loading) DisplayBeacons(beacons = uiState.beacons) + } } /** @@ -31,7 +34,7 @@ fun MapScreen() { */ @Composable fun DisplayBeacons(beacons: List) { - //Create each beacon from the list + // Create each beacon from the list beacons.forEach() { Marker( state = MarkerState(position = it.location.toLatLng()), From f96014c43b0eca0f84cff7c97a24d905da3c2a77 Mon Sep 17 00:00:00 2001 From: Clarence LINDEN Date: Thu, 11 Apr 2024 22:20:46 +0200 Subject: [PATCH 6/8] apply joris changes --- .../epfl/cs311/wanderwave/model/BeaconConnectionTest.kt | 2 +- .../cs311/wanderwave/model/remote/BeaconConnection.kt | 8 +------- .../epfl/cs311/wanderwave/model/remote/TrackConnection.kt | 4 ---- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/model/BeaconConnectionTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/model/BeaconConnectionTest.kt index c15546f8c..c0ee792e4 100644 --- a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/model/BeaconConnectionTest.kt +++ b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/model/BeaconConnectionTest.kt @@ -28,7 +28,7 @@ public class BeaconConnectionTest { @Test fun testAddAndGetItem() = runBlocking { - withTimeout(30000) { // Timeout after 5000 milliseconds (20 seconds) + withTimeout(30000) { // Increase the timeout to 30 seconds val beacon = Beacon( id = "testBeacon", diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/model/remote/BeaconConnection.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/model/remote/BeaconConnection.kt index 3e4227253..bc3685b6c 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/model/remote/BeaconConnection.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/model/remote/BeaconConnection.kt @@ -21,8 +21,6 @@ class BeaconConnection(private val database: FirebaseFirestore? = null) : override val db = database ?: super.db - // private val db = FirebaseFirestore.getInstance() - // Document to Beacon override fun documentToItem(document: DocumentSnapshot): Beacon? { return Beacon.from(document) @@ -81,11 +79,7 @@ class BeaconConnection(private val database: FirebaseFirestore? = null) : val beaconMap: HashMap = hashMapOf( "id" to beacon.id, - "location" to - hashMapOf( - "latitude" to beacon.location.latitude, - "longitude" to beacon.location.longitude, - "name" to beacon.location.name), + "location" to beacon.location.toMap(), "tracks" to beacon.tracks.map { track -> db.collection(trackConnection.collectionName).document(track.id) diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/model/remote/TrackConnection.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/model/remote/TrackConnection.kt index aeec6017a..5b3fa4e8a 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/model/remote/TrackConnection.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/model/remote/TrackConnection.kt @@ -24,10 +24,6 @@ class TrackConnection(private val database: FirebaseFirestore? = null) : return track.toMap() } - fun addList(tracks: List) { - tracks.forEach { track -> addItemWithId(track) } - } - fun addItemsIfNotExist(tracks: List) { // The goal of this function is to add only if the spotify id of the track is not already in the // database, for now I just check the normal ID From ba74a5ad7df1740cdf2baa746c1250e96570d6b8 Mon Sep 17 00:00:00 2001 From: IB-12 <100189489+IB-12@users.noreply.github.com> Date: Thu, 11 Apr 2024 23:22:48 +0200 Subject: [PATCH 7/8] Pulled and merged changes from main --- .../cs311/wanderwave/ui/screens/MapScreen.kt | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt index 2c2b535cd..f66b08918 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt @@ -21,12 +21,11 @@ import ch.epfl.cs311.wanderwave.R import ch.epfl.cs311.wanderwave.model.data.Beacon import ch.epfl.cs311.wanderwave.viewmodel.MapViewModel import com.google.android.gms.maps.CameraUpdateFactory +import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.MapView import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.MapStyleOptions import com.google.android.gms.maps.model.MarkerOptions -import com.google.maps.android.compose.Marker -import com.google.maps.android.compose.MarkerState /** * A screen that displays a map if loaded, else display a CircularProgressIndicator. @@ -44,7 +43,6 @@ fun MapScreen() { val context = LocalContext.current val isMapReady = remember { mutableStateOf(false) } val googleMapState = viewModel.googleMapState.collectAsState().value - // GoogleMap(modifier = Modifier.testTag("mapScreen")) { DisplayBeacons(uiState.beacons) } Box(modifier = Modifier.fillMaxSize().testTag("mapScreen"), contentAlignment = Alignment.Center) { AndroidView( @@ -57,6 +55,7 @@ fun MapScreen() { viewModel.setGoogleMap(googleMap) isMapReady.value = true googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(context, R.raw.map_style)) + if (!uiState.loading) DisplayBeacons(googleMap = googleMap, beacons = uiState.beacons) } } }, @@ -72,12 +71,6 @@ fun MapScreen() { } } } - - // TODO: Make sure the beacons are filtered to be within the radius - -// GoogleMap(modifier = Modifier.testTag("mapScreen")) { -// if (!uiState.loading) DisplayBeacons(beacons = uiState.beacons) -// } } /** @@ -86,13 +79,9 @@ fun MapScreen() { * * @param beacons The list of beacons to be displayed on the map. */ -@Composable -fun DisplayBeacons(beacons: List) { +fun DisplayBeacons(googleMap: GoogleMap, beacons: List) { // Create each beacon from the list beacons.forEach() { - Marker( - state = MarkerState(position = it.location.toLatLng()), - title = it.id, - ) + googleMap.addMarker(MarkerOptions().position(it.location.toLatLng()).title(it.id)) } } From 55c3cae44439e2b7a7f335fd60b6ce7cec3ae9f5 Mon Sep 17 00:00:00 2001 From: IB-12 <100189489+IB-12@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:16:57 +0200 Subject: [PATCH 8/8] Finished merge from main Adapted tests Finally solved all issues --- .../ch/epfl/cs311/wanderwave/ui/MapTest.kt | 29 ------------------- .../cs311/wanderwave/ui/screens/MapScreen.kt | 14 ++++----- 2 files changed, 5 insertions(+), 38 deletions(-) delete mode 100644 app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt deleted file mode 100644 index 771363e90..000000000 --- a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package ch.epfl.cs311.wanderwave.ui - -import androidx.compose.ui.test.junit4.createAndroidComposeRule -import androidx.test.ext.junit.runners.AndroidJUnit4 -import ch.epfl.cs311.wanderwave.ui.screens.MapScreen -import com.kaspersky.components.composesupport.config.withComposeSupport -import com.kaspersky.kaspresso.kaspresso.Kaspresso -import com.kaspersky.kaspresso.testcases.api.testcase.TestCase -import dagger.hilt.android.testing.HiltAndroidTest -import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -@HiltAndroidTest -class MapTest : TestCase(kaspressoBuilder = Kaspresso.Builder.withComposeSupport()) { - - @get:Rule val composeTestRule = createAndroidComposeRule() - - @Before - fun setup() { - composeTestRule.setContent { MapScreen() } - } - - @Test - fun mapIsDisplayed() = run { onComposeScreen(composeTestRule) { assertIsDisplayed() } } -} diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt index 5c3412ec5..0e2611f68 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt @@ -28,11 +28,9 @@ import com.google.accompanist.permissions.isGranted import com.google.accompanist.permissions.rememberMultiplePermissionsState import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap -import com.google.android.gms.maps.MapView import com.google.android.gms.maps.model.CameraPosition import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.MapStyleOptions -import com.google.android.gms.maps.model.MarkerOptions import com.google.maps.android.compose.CameraPositionState import com.google.maps.android.compose.GoogleMap import com.google.maps.android.compose.MapProperties @@ -108,9 +106,7 @@ fun WanderwaveGoogleMap( @Composable fun MapContent(viewModel: MapViewModel) { - val epfl = LatLng(46.518831258, 6.559331096) - val beacons = viewModel.uiState.collectAsStateWithLifecycle().value.beacons - Marker(state = MarkerState(position = epfl), title = "Marker at EPFL") + val beacons: List = viewModel.uiState.collectAsStateWithLifecycle().value.beacons DisplayBeacons(beacons = beacons) } @@ -154,9 +150,9 @@ fun moveCamera( fun DisplayBeacons(beacons: List) { // Create each beacon from the list beacons.forEach() { - Marker( - state = MarkerState(position = it.location.toLatLng()), - title = it.id, - ) + Marker( + state = MarkerState(position = it.location.toLatLng()), + title = it.id, + ) } }