From 0469f33fd1239c6f45e44f3506694eb5210dabd0 Mon Sep 17 00:00:00 2001 From: taghizadlaura Date: Thu, 7 Nov 2024 21:45:56 +0100 Subject: [PATCH 1/3] feat: create a new GPSLocation.kt class --- .../periodpals/model/location/GPSLocation.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/src/main/java/com/android/periodpals/model/location/GPSLocation.kt diff --git a/app/src/main/java/com/android/periodpals/model/location/GPSLocation.kt b/app/src/main/java/com/android/periodpals/model/location/GPSLocation.kt new file mode 100644 index 000000000..bfc3b1564 --- /dev/null +++ b/app/src/main/java/com/android/periodpals/model/location/GPSLocation.kt @@ -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) + } +} \ No newline at end of file From 09869d462032cf05906538cb86359b2cb9846eef Mon Sep 17 00:00:00 2001 From: taghizadlaura Date: Thu, 7 Nov 2024 21:50:05 +0100 Subject: [PATCH 2/3] feat: change LocationServiceImpl.kt and LocationService.kt into GPSServiceImpl.kt and GPSService.kt --- .../java/com/android/periodpals/ui/map/MapScreenTest.kt | 6 +++--- app/src/main/java/com/android/periodpals/MainActivity.kt | 8 ++++---- .../services/{LocationService.kt => GPSService.kt} | 2 +- .../{LocationServiceImpl.kt => GPSServiceImpl.kt} | 2 +- app/src/main/java/com/android/periodpals/ui/map/Map.kt | 4 ++-- .../{LocationServiceImplTest.kt => GPSServiceImplTest.kt} | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) rename app/src/main/java/com/android/periodpals/services/{LocationService.kt => GPSService.kt} (87%) rename app/src/main/java/com/android/periodpals/services/{LocationServiceImpl.kt => GPSServiceImpl.kt} (96%) rename app/src/test/java/com/android/periodpals/services/{LocationServiceImplTest.kt => GPSServiceImplTest.kt} (96%) diff --git a/app/src/androidTest/java/com/android/periodpals/ui/map/MapScreenTest.kt b/app/src/androidTest/java/com/android/periodpals/ui/map/MapScreenTest.kt index 5c5a448bb..06f5b656c 100644 --- a/app/src/androidTest/java/com/android/periodpals/ui/map/MapScreenTest.kt +++ b/app/src/androidTest/java/com/android/periodpals/ui/map/MapScreenTest.kt @@ -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 @@ -45,7 +45,7 @@ class MapScreenTest { ArgumentCaptor>> // The location service - private lateinit var locationService: LocationServiceImpl + private lateinit var locationService: GPSServiceImpl @Before fun setup() { @@ -59,7 +59,7 @@ class MapScreenTest { any(), any>>()) - locationService = LocationServiceImpl(activity) + locationService = GPSServiceImpl(activity) // Verify registerForActivityResult is called and capture the callback verify(activity) diff --git a/app/src/main/java/com/android/periodpals/MainActivity.kt b/app/src/main/java/com/android/periodpals/MainActivity.kt index c6c42138d..4543652b7 100644 --- a/app/src/main/java/com/android/periodpals/MainActivity.kt +++ b/app/src/main/java/com/android/periodpals/MainActivity.kt @@ -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 @@ -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( @@ -67,8 +67,8 @@ class MainActivity : ComponentActivity() { @Composable fun PeriodPalsApp( - locationService: LocationServiceImpl, - authenticationViewModel: AuthenticationViewModel, + locationService: GPSServiceImpl, + authenticationViewModel: AuthenticationViewModel, ) { val navController = rememberNavController() val navigationActions = NavigationActions(navController) diff --git a/app/src/main/java/com/android/periodpals/services/LocationService.kt b/app/src/main/java/com/android/periodpals/services/GPSService.kt similarity index 87% rename from app/src/main/java/com/android/periodpals/services/LocationService.kt rename to app/src/main/java/com/android/periodpals/services/GPSService.kt index 5af377faf..ffcb75ad8 100644 --- a/app/src/main/java/com/android/periodpals/services/LocationService.kt +++ b/app/src/main/java/com/android/periodpals/services/GPSService.kt @@ -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() diff --git a/app/src/main/java/com/android/periodpals/services/LocationServiceImpl.kt b/app/src/main/java/com/android/periodpals/services/GPSServiceImpl.kt similarity index 96% rename from app/src/main/java/com/android/periodpals/services/LocationServiceImpl.kt rename to app/src/main/java/com/android/periodpals/services/GPSServiceImpl.kt index dc18f17cc..374938053 100644 --- a/app/src/main/java/com/android/periodpals/services/LocationServiceImpl.kt +++ b/app/src/main/java/com/android/periodpals/services/GPSServiceImpl.kt @@ -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" diff --git a/app/src/main/java/com/android/periodpals/ui/map/Map.kt b/app/src/main/java/com/android/periodpals/ui/map/Map.kt index 2e59d7da3..df0be3aec 100644 --- a/app/src/main/java/com/android/periodpals/ui/map/Map.kt +++ b/app/src/main/java/com/android/periodpals/ui/map/Map.kt @@ -15,7 +15,7 @@ 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.LocationAccessType -import com.android.periodpals.services.LocationServiceImpl +import com.android.periodpals.services.GPSServiceImpl import com.android.periodpals.ui.navigation.BottomNavigationMenu import com.android.periodpals.ui.navigation.LIST_TOP_LEVEL_DESTINATION import com.android.periodpals.ui.navigation.NavigationActions @@ -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) } diff --git a/app/src/test/java/com/android/periodpals/services/LocationServiceImplTest.kt b/app/src/test/java/com/android/periodpals/services/GPSServiceImplTest.kt similarity index 96% rename from app/src/test/java/com/android/periodpals/services/LocationServiceImplTest.kt rename to app/src/test/java/com/android/periodpals/services/GPSServiceImplTest.kt index 1010002a7..df9733725 100644 --- a/app/src/test/java/com/android/periodpals/services/LocationServiceImplTest.kt +++ b/app/src/test/java/com/android/periodpals/services/GPSServiceImplTest.kt @@ -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" @@ -32,7 +32,7 @@ class LocationServiceImplTest { private lateinit var permissionCallbackCaptor: ArgumentCaptor>> - private lateinit var locationService: LocationServiceImpl + private lateinit var locationService: GPSServiceImpl @Before fun setup() { @@ -44,7 +44,7 @@ class LocationServiceImplTest { any>>()) // 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. From 6d928a382436a2b71d825aa76a4500adc67acaf5 Mon Sep 17 00:00:00 2001 From: taghizadlaura Date: Thu, 7 Nov 2024 21:52:07 +0100 Subject: [PATCH 3/3] style: run ktfmt --- .../com/android/periodpals/MainActivity.kt | 4 ++-- .../periodpals/model/location/GPSLocation.kt | 20 +++++++++---------- .../java/com/android/periodpals/ui/map/Map.kt | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/android/periodpals/MainActivity.kt b/app/src/main/java/com/android/periodpals/MainActivity.kt index 4543652b7..cf76dc4e1 100644 --- a/app/src/main/java/com/android/periodpals/MainActivity.kt +++ b/app/src/main/java/com/android/periodpals/MainActivity.kt @@ -67,8 +67,8 @@ class MainActivity : ComponentActivity() { @Composable fun PeriodPalsApp( - locationService: GPSServiceImpl, - authenticationViewModel: AuthenticationViewModel, + locationService: GPSServiceImpl, + authenticationViewModel: AuthenticationViewModel, ) { val navController = rememberNavController() val navigationActions = NavigationActions(navController) diff --git a/app/src/main/java/com/android/periodpals/model/location/GPSLocation.kt b/app/src/main/java/com/android/periodpals/model/location/GPSLocation.kt index bfc3b1564..b678ec340 100644 --- a/app/src/main/java/com/android/periodpals/model/location/GPSLocation.kt +++ b/app/src/main/java/com/android/periodpals/model/location/GPSLocation.kt @@ -4,14 +4,14 @@ 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) + /** + * 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) - } -} \ No newline at end of file + companion object { + val DEFAULT_LOCATION = GPSLocation(46.5191, 6.5668) + } +} diff --git a/app/src/main/java/com/android/periodpals/ui/map/Map.kt b/app/src/main/java/com/android/periodpals/ui/map/Map.kt index df0be3aec..64d84e840 100644 --- a/app/src/main/java/com/android/periodpals/ui/map/Map.kt +++ b/app/src/main/java/com/android/periodpals/ui/map/Map.kt @@ -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.LocationAccessType import com.android.periodpals.services.GPSServiceImpl +import com.android.periodpals.services.LocationAccessType import com.android.periodpals.ui.navigation.BottomNavigationMenu import com.android.periodpals.ui.navigation.LIST_TOP_LEVEL_DESTINATION import com.android.periodpals.ui.navigation.NavigationActions