From ba1d74f01769f322be2292cdc3de69a79291074d Mon Sep 17 00:00:00 2001 From: AllenTom Date: Fri, 19 Jul 2024 15:24:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9C=B0=E5=9B=BE=E7=BB=86?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 + .../main/java/com/aiosman/riderpro/Street.kt | 233 ++++++++++++++++-- .../res/drawable/rider_pro_my_location.xml | 21 ++ 3 files changed, 236 insertions(+), 20 deletions(-) create mode 100644 app/src/main/res/drawable/rider_pro_my_location.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 678b3de..8a3d08b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + (null) } + val navigationBarHeight = with(LocalDensity.current) { + WindowInsets.navigationBars.getBottom(this).toDp() } - GoogleMap( - modifier = Modifier.fillMaxSize(), - cameraPositionState = cameraPositionState - ) { - countries.forEach { position -> - MarkerComposable( - state = MarkerState(position = LatLng(position.lat, position.lng)), - onClick = { it -> - navController.navigate("LocationDetail") - true + val cameraPositionState = rememberCameraPositionState { + position = CameraPosition.fromLatLngZoom(currentLocation ?: LatLng(0.0, 0.0), 10f) + } + var hasLocationPermission by remember { mutableStateOf(false) } + var searchText by remember { mutableStateOf("") } + val permissionLauncher = rememberLauncherForActivityResult( + contract = ActivityResultContracts.RequestPermission(), + onResult = { isGranted -> + hasLocationPermission = isGranted + if (isGranted) { + fusedLocationClient.lastLocation.addOnSuccessListener { location -> + if (location != null) { + currentLocation = LatLng(location.latitude, location.longitude) + } } - ) { - Image( - painter = painterResource(id = R.drawable.rider_pro_map_mark), - contentDescription = "", - ) + } + } + ) + LaunchedEffect(Unit) { + when (PackageManager.PERMISSION_GRANTED) { + ContextCompat.checkSelfPermission( + context, + android.Manifest.permission.ACCESS_FINE_LOCATION + ) -> { + fusedLocationClient.lastLocation.addOnSuccessListener { location -> + if (location != null) { + currentLocation = LatLng(location.latitude, location.longitude) + } + } + hasLocationPermission = true + } + + else -> { + permissionLauncher.launch(android.Manifest.permission.ACCESS_FINE_LOCATION) } } } + LaunchedEffect(currentLocation) { + cameraPositionState.position = + CameraPosition.fromLatLngZoom(currentLocation ?: LatLng(0.0, 0.0), 10f) + } + Box( + modifier = Modifier.fillMaxSize().padding(bottom = 56.dp + navigationBarHeight) + ) { + GoogleMap( + modifier = Modifier.fillMaxSize(), + cameraPositionState = cameraPositionState, + properties = MapProperties( + isMyLocationEnabled = hasLocationPermission, + ), + uiSettings = MapUiSettings( + compassEnabled = true, + myLocationButtonEnabled = false, + zoomControlsEnabled = false + ) + ) { + + countries.forEach { position -> + MarkerComposable( + state = MarkerState(position = LatLng(position.lat, position.lng)), + onClick = { it -> + navController.navigate("LocationDetail") + true + } + ) { + Image( + painter = painterResource(id = R.drawable.rider_pro_map_mark), + contentDescription = "", + ) + } + } + + + + } + Image( + painter = painterResource(id = R.drawable.rider_pro_my_location), + contentDescription = "", + modifier = Modifier + .align(Alignment.BottomStart) + .padding(start = 16.dp, bottom = 16.dp + navigationBarHeight) .clickable { + currentLocation?.let { + cameraPositionState.position = CameraPosition.fromLatLngZoom(it, cameraPositionState.position.zoom) + } + } + ) + Box( + modifier = Modifier + .align(Alignment.BottomEnd) + .padding(end = 16.dp, bottom = 16.dp + navigationBarHeight) + ) { + Box( + modifier = Modifier + .size(48.dp) + .clip(CircleShape) + .background(color = Color(0xffda3832)) + + ) { + Image( + painter = painterResource(id = R.drawable.rider_pro_new_post_add_pic), + contentDescription = "", + modifier = Modifier + .align(Alignment.Center).size(36.dp), + colorFilter = ColorFilter.tint(Color.White) + + ) + } + } + + Box( + modifier = Modifier + .fillMaxWidth() + .align(Alignment.TopCenter) + .padding(top = 64.dp, start = 16.dp,end=16.dp) + ) { + Box( + modifier = Modifier.background(Color.White).padding(16.dp), + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .clip(RoundedCornerShape(16.dp)) + .background(Color(0xfff7f7f7)) + .padding(vertical = 8.dp, horizontal = 16.dp) + ) { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically + ) { + Icon( + painter = painterResource(id = R.drawable.rider_pro_search_location), + contentDescription = "", + tint = Color(0xffc6c6c6), + modifier = Modifier.size(24.dp) + ) + Spacer(modifier = Modifier.width(8.dp)) + Box( + modifier = Modifier + .fillMaxWidth() + ) { + if (searchText.isEmpty()){ + Text( + text = "Please enter a search location", + color = Color(0xffc6c6c6), + fontSize = 16.sp, + modifier = Modifier.padding(start = 8.dp) + ) + } + + BasicTextField( + value = searchText, + onValueChange = { + searchText = it + }, + modifier = Modifier + .fillMaxWidth(), + textStyle = TextStyle( + fontSize = 16.sp, + fontWeight = FontWeight.Normal + ) + ) + } + + } + + } + } + } + + } + } \ No newline at end of file diff --git a/app/src/main/res/drawable/rider_pro_my_location.xml b/app/src/main/res/drawable/rider_pro_my_location.xml new file mode 100644 index 0000000..b85edd4 --- /dev/null +++ b/app/src/main/res/drawable/rider_pro_my_location.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +