Skip to content

Commit

Permalink
Merge pull request #149 from PeriodPals/feat/geolocation/change-map-s…
Browse files Browse the repository at this point in the history
…ervices-names-to-GPS

Feat/geolocation/change map services names to gps
  • Loading branch information
taghizadlaura authored Nov 7, 2024
2 parents 8f7b780 + 6d928a3 commit a751761
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.ui.test.onNodeWithTag
import androidx.navigation.compose.rememberNavController
import com.android.periodpals.resources.C.Tag.MapScreen
import com.android.periodpals.resources.C.Tag.TopAppBar
import com.android.periodpals.services.LocationServiceImpl
import com.android.periodpals.services.GPSServiceImpl
import com.android.periodpals.ui.navigation.NavigationActions
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -45,7 +45,7 @@ class MapScreenTest {
ArgumentCaptor<ActivityResultCallback<Map<String, Boolean>>>

// The location service
private lateinit var locationService: LocationServiceImpl
private lateinit var locationService: GPSServiceImpl

@Before
fun setup() {
Expand All @@ -59,7 +59,7 @@ class MapScreenTest {
any<ActivityResultContracts.RequestMultiplePermissions>(),
any<ActivityResultCallback<Map<String, Boolean>>>())

locationService = LocationServiceImpl(activity)
locationService = GPSServiceImpl(activity)

// Verify registerForActivityResult is called and capture the callback
verify(activity)
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/android/periodpals/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.navigation.compose.rememberNavController
import androidx.navigation.navigation
import com.android.periodpals.model.authentication.AuthenticationModelSupabase
import com.android.periodpals.model.authentication.AuthenticationViewModel
import com.android.periodpals.services.LocationServiceImpl
import com.android.periodpals.services.GPSServiceImpl
import com.android.periodpals.ui.alert.AlertListsScreen
import com.android.periodpals.ui.alert.CreateAlertScreen
import com.android.periodpals.ui.authentication.SignInScreen
Expand All @@ -35,7 +35,7 @@ import org.osmdroid.config.Configuration

class MainActivity : ComponentActivity() {

private val locationService = LocationServiceImpl(this)
private val locationService = GPSServiceImpl(this)

private val supabaseClient =
createSupabaseClient(
Expand Down Expand Up @@ -67,7 +67,7 @@ class MainActivity : ComponentActivity() {

@Composable
fun PeriodPalsApp(
locationService: LocationServiceImpl,
locationService: GPSServiceImpl,
authenticationViewModel: AuthenticationViewModel,
) {
val navController = rememberNavController()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.android.periodpals.model.location

import org.osmdroid.util.GeoPoint

data class GPSLocation(val lat: Double, val long: Double) {

/**
* Transform this location into a [GeoPoint].
*
* @return The respective [GeoPoint].
*/
fun toGeoPoint() = GeoPoint(lat, long)

companion object {
val DEFAULT_LOCATION = GPSLocation(46.5191, 6.5668)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android.periodpals.services

/** A service that provides the user location. */
interface LocationService {
interface GPSService {

/** Requests the user for permission to access their location. */
fun requestUserPermissionForLocation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum class LocationAccessType {
*
* @param activity The screen from which the location service is being launched from.
*/
class LocationServiceImpl(private val activity: ComponentActivity) : LocationService {
class GPSServiceImpl(private val activity: ComponentActivity) : GPSService {

private val TAG = "LocationServiceImpl: registerForActivityResult"

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/android/periodpals/ui/map/Map.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.viewinterop.AndroidView
import com.android.periodpals.resources.C.Tag.MapScreen
import com.android.periodpals.services.GPSServiceImpl
import com.android.periodpals.services.LocationAccessType
import com.android.periodpals.services.LocationServiceImpl
import com.android.periodpals.ui.navigation.BottomNavigationMenu
import com.android.periodpals.ui.navigation.LIST_TOP_LEVEL_DESTINATION
import com.android.periodpals.ui.navigation.NavigationActions
Expand All @@ -37,7 +37,7 @@ private const val TAG = "MapView"
private const val SCREEN_TITLE = "Map"

@Composable
fun MapScreen(locationService: LocationServiceImpl, navigationActions: NavigationActions) {
fun MapScreen(locationService: GPSServiceImpl, navigationActions: NavigationActions) {
val context = LocalContext.current
val fusedLocationClient = remember { LocationServices.getFusedLocationProviderClient(context) }
val mapView = remember { MapView(context) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.mockito.kotlin.doReturn
import org.mockito.kotlin.verify

@RunWith(MockitoJUnitRunner::class)
class LocationServiceImplTest {
class GPSServiceImplTest {

@Mock private lateinit var activity: ComponentActivity // Mock the "screen"

Expand All @@ -32,7 +32,7 @@ class LocationServiceImplTest {
private lateinit var permissionCallbackCaptor:
ArgumentCaptor<ActivityResultCallback<Map<String, Boolean>>>

private lateinit var locationService: LocationServiceImpl
private lateinit var locationService: GPSServiceImpl

@Before
fun setup() {
Expand All @@ -44,7 +44,7 @@ class LocationServiceImplTest {
any<ActivityResultCallback<Map<String, Boolean>>>())

// Create the actual (not mocked) location service instance
locationService = LocationServiceImpl(activity)
locationService = GPSServiceImpl(activity)

// And then we verify that upon creating the location service,
// registerForActivityResult was called. We also capture the callback.
Expand Down

0 comments on commit a751761

Please sign in to comment.