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

Display beacons on map #96

Merged
merged 15 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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 @@ -33,7 +33,7 @@ public class BeaconConnectionTest {

@Test
fun testAddAndGetItem() = runBlocking {
withTimeout(30000) { // Timeout after 5000 milliseconds (20 seconds)
withTimeout(30000) { // Increase the timeout to 30 seconds
tsogtb marked this conversation as resolved.
Show resolved Hide resolved
val beacon =
Beacon(
id = "testBeacon",
Expand Down
29 changes: 29 additions & 0 deletions app/src/androidTest/java/ch/epfl/cs311/wanderwave/ui/MapTest.kt
IB-12 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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<TestActivity>()

@Before
fun setup() {
composeTestRule.setContent { MapScreen() }
}

@Test
fun mapIsDisplayed() = run { onComposeScreen<MapScreen>(composeTestRule) { assertIsDisplayed() } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -81,11 +79,7 @@ class BeaconConnection(private val database: FirebaseFirestore? = null) :
val beaconMap: HashMap<String, Any> =
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class TrackConnection(private val database: FirebaseFirestore? = null) :
return track.toMap()
}

fun addList(tracks: List<Track>) {
tracks.forEach { track -> addItemWithId(track) }
}

fun addItemsIfNotExist(tracks: List<Track>) {
// 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
Expand Down
19 changes: 5 additions & 14 deletions app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/MapScreen.kt
IB-12 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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)
}
}
},
Expand All @@ -80,17 +79,9 @@ fun MapScreen() {
*
* @param beacons The list of beacons to be displayed on the map.
*/
@Composable
fun DisplayBeacons(beacons: List<Beacon>) {

// Add a marker for each beacon
// source for the icon: https://www.svgrepo.com/svg/448258/waypoint
// val customIcon = BitmapDescriptorFactory.fromResource(R.drawable.waypoint)
fun DisplayBeacons(googleMap: GoogleMap, beacons: List<Beacon>) {
// Create each beacon from the list
beacons.forEach() {
Marker(
state = MarkerState(position = it.location.toLatLng()),
title = it.id,
// icon = customIcon,
)
googleMap.addMarker(MarkerOptions().position(it.location.toLatLng()).title(it.id))
}
}
Loading