Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ExperimentalComposeUiApi
- @Composable
- fun MapScreen(navController:NavHostController, viewModel: MapScreenVM = hiltViewModel()) {
- var uiSettings by remember { mutableStateOf(MapUiSettings(zoomControlsEnabled = false)) }
- val properties by remember { mutableStateOf(MapProperties(mapType = MapType.SATELLITE)) }
- var addresses by remember { mutableStateOf<List<AddressModel>>(emptyList())}
- var dropdownExpanded by remember { mutableStateOf(false) }
- var selectedIndex by remember { mutableStateOf(0) }
- var selectedAddress by remember { mutableStateOf("") }
- val scope = rememberCoroutineScope()
- Box(modifier = Modifier.fillMaxSize())
- {
- val grozny = LatLng(43.312, 45.6889)
- val cameraPositionState = rememberCameraPositionState { position = CameraPosition.fromLatLngZoom(grozny, 13f) }
- val geocoder = Geocoder(LocalContext.current)
- var addressesFromMap: List<Address> = geocoder.getFromLocation(cameraPositionState.position.target.latitude, cameraPositionState.position.target.longitude, 1)
- val mapCurrentAddress = addressesFromMap[0].getAddressLine(0)
- GoogleMap(
- modifier = Modifier.fillMaxSize(),
- cameraPositionState = cameraPositionState,
- uiSettings = uiSettings)
- {
- Marker(position = cameraPositionState.position.target,)
- }
- Column(
- horizontalAlignment = Alignment.CenterHorizontally,
- modifier = Modifier
- .fillMaxWidth()
- .clip(shape = RoundedCornerShape(30.dp))
- .padding(top = 60.dp, start = 10.dp, end = 10.dp)
- .statusBarsPadding()
- .align(Alignment.TopCenter))
- {
- DropdownMenu(
- expanded = dropdownExpanded,
- onDismissRequest = { dropdownExpanded = false },
- properties = PopupProperties(focusable = false),
- modifier = Modifier
- .fillMaxWidth()
- .background(Color.Transparent))
- {
- addresses.forEachIndexed { index, item ->
- Column {
- DropdownMenuItem(
- onClick = {
- selectedIndex = index
- selectedAddress = item.value
- dropdownExpanded = false })
- {
- Text(
- text = item.value ,
- style = MaterialTheme.typography.h4,
- fontSize = 18.sp,
- modifier = Modifier.fillMaxWidth())
- }
- Divider()
- }
- }
- }
- }
- AddressSearchCard(modifier = Modifier
- .fillMaxWidth()
- .align(Alignment.TopCenter)
- .padding(horizontal = 10.dp)
- .statusBarsPadding(),
- address = selectedAddress,
- onChange = { txt ->
- dropdownExpanded = txt.isNotEmpty()
- selectedAddress = txt
- viewModel.getAddresses(
- success = { addresses = it },
- address = txt)
- },
- clearAddress = { selectedAddress = "" })
- BottomAddressCard(
- title = stringResource(R.string.map_card_txt1),
- address = if(selectedAddress.isEmpty()) mapCurrentAddress else selectedAddress,
- modifier = Modifier
- .align(Alignment.BottomCenter)
- .padding(start = 10.dp, end = 10.dp, bottom = 80.dp)
- .navigationBarsPadding(),
- onClick = {
- if (selectedAddress.isNotEmpty()) {
- scope.launch { globalSelectedAddress.emit(selectedAddress) }
- } else { scope.launch { globalSelectedAddress.emit(mapCurrentAddress) }}
- navController.navigate(Screen.Payment.route)
- }
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement