diff --git a/app/build.gradle b/app/build.gradle index 6930bdb..6ee6958 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,7 +54,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.9.0' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' - implementation 'androidx.activity:activity-compose:1.5.1' + implementation 'androidx.activity:activity-compose:1.6.0' implementation "androidx.compose.ui:ui:$compose_ui_version" implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version" implementation "androidx.compose.material:material:$compose_ui_version" @@ -87,4 +87,11 @@ dependencies { //DataStore implementation "androidx.datastore:datastore-preferences:1.0.0" + + //GoogleMap + implementation "com.google.maps.android:maps-compose:1.1.0" + implementation 'com.google.android.gms:play-services-maps:18.1.0' + + // Location + implementation "com.google.android.gms:play-services-location:21.0.0" } \ No newline at end of file diff --git a/app/src/main/java/com/ahgitdevelopment/course/customexamples/features/screens/AppList.kt b/app/src/main/java/com/ahgitdevelopment/course/customexamples/features/screens/AppList.kt index e919c66..fe6156e 100644 --- a/app/src/main/java/com/ahgitdevelopment/course/customexamples/features/screens/AppList.kt +++ b/app/src/main/java/com/ahgitdevelopment/course/customexamples/features/screens/AppList.kt @@ -46,16 +46,20 @@ fun AppList(navController: NavController) { } ) ItemList( - "Data Store Timer", + "Timer", onClick = { navController.navigate(AppScreens.TimerScreen.route) } ) + ItemList( + "Google Map", + onClick = { + navController.navigate(AppScreens.MapScreen.route) + } + ) } } - - @Preview(showSystemUi = true, showBackground = true) @Composable fun DefaultPreviewAppList() { diff --git a/app/src/main/java/com/ahgitdevelopment/course/customexamples/features/screens/googlemap/MapScreen.kt b/app/src/main/java/com/ahgitdevelopment/course/customexamples/features/screens/googlemap/MapScreen.kt new file mode 100644 index 0000000..155a2b1 --- /dev/null +++ b/app/src/main/java/com/ahgitdevelopment/course/customexamples/features/screens/googlemap/MapScreen.kt @@ -0,0 +1,77 @@ +package com.ahgitdevelopment.course.customexamples.features.screens.googlemap + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material.CircularProgressIndicator +import androidx.compose.material.Scaffold +import androidx.compose.material.rememberScaffoldState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.navigation.NavController +import com.ahgitdevelopment.course.customexamples.features.components.TopAppBar +import com.ahgitdevelopment.course.customexamples.navigation.AppScreens +import com.google.android.gms.maps.model.CameraPosition +import com.google.android.gms.maps.model.LatLng +import com.google.maps.android.compose.GoogleMap +import com.google.maps.android.compose.Marker +import com.google.maps.android.compose.rememberCameraPositionState + +private val MADRID = LatLng(40.416729, -3.703339) + +@Composable +fun MapScreen( + navController: NavController +) { + val scaffoldState = rememberScaffoldState() + + Scaffold( + scaffoldState = scaffoldState, + topBar = { + TopAppBar( + title = AppScreens.LazyListScreen.route, + navController = navController + ) + }, + content = { paddingVal -> + Box( + modifier = Modifier + .fillMaxSize() + .padding(paddingVal) + ) { + Column( + modifier = Modifier + .fillMaxSize() + ) { + MapContent() + } + } + } + ) +} + +@Composable +fun MapContent() { + var isMapLoading by remember { mutableStateOf(true) } + val cameraPositionState = rememberCameraPositionState { + position = CameraPosition.fromLatLngZoom(MADRID, 15f) + } + + GoogleMap( + cameraPositionState = cameraPositionState, + onMapLoaded = { isMapLoading = false }) { + Marker( + position = cameraPositionState.position.target, + title = cameraPositionState.position.target.toString() + ) + } + if (isMapLoading) { + CircularProgressIndicator() + } +} + diff --git a/app/src/main/java/com/ahgitdevelopment/course/customexamples/navigation/AppNavigation.kt b/app/src/main/java/com/ahgitdevelopment/course/customexamples/navigation/AppNavigation.kt index 99ec390..96d7329 100644 --- a/app/src/main/java/com/ahgitdevelopment/course/customexamples/navigation/AppNavigation.kt +++ b/app/src/main/java/com/ahgitdevelopment/course/customexamples/navigation/AppNavigation.kt @@ -12,6 +12,7 @@ import com.ahgitdevelopment.course.customexamples.features.screens.ScreenA import com.ahgitdevelopment.course.customexamples.features.screens.ScreenB import com.ahgitdevelopment.course.customexamples.features.screens.datastore.DataStoreResultScreen import com.ahgitdevelopment.course.customexamples.features.screens.datastore.DataStoreScreen +import com.ahgitdevelopment.course.customexamples.features.screens.googlemap.MapScreen import com.ahgitdevelopment.course.customexamples.features.screens.splash.SplashScreen import com.ahgitdevelopment.course.customexamples.features.screens.timer.TimerScreen @@ -49,5 +50,8 @@ fun AppNavigation() { composable(route = AppScreens.TimerScreen.route) { TimerScreen() } + composable(route = AppScreens.MapScreen.route) { + MapScreen(navController) + } } } diff --git a/app/src/main/java/com/ahgitdevelopment/course/customexamples/navigation/AppScreens.kt b/app/src/main/java/com/ahgitdevelopment/course/customexamples/navigation/AppScreens.kt index 8b3f46f..ce2b66a 100644 --- a/app/src/main/java/com/ahgitdevelopment/course/customexamples/navigation/AppScreens.kt +++ b/app/src/main/java/com/ahgitdevelopment/course/customexamples/navigation/AppScreens.kt @@ -12,4 +12,5 @@ sealed class AppScreens(val route: String) { object DataStoreResultScreen : AppScreens("DataStoreResultScreen") object TimerScreen : AppScreens("TimerScreen") + object MapScreen : AppScreens("MapScreen") } diff --git a/build.gradle b/build.gradle index 28746d9..b1da40a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - compose_ui_version = '1.3.0-beta02' + compose_ui_version = '1.3.0-rc01' composeNavigationVersion = '2.5.2' } @@ -14,7 +14,7 @@ buildscript { // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '7.2.2' apply false - id 'com.android.library' version '7.2.2' apply false + id 'com.android.application' version '7.3.0' apply false + id 'com.android.library' version '7.3.0' apply false id 'org.jetbrains.kotlin.android' version '1.7.10' apply false }