From a9af2ca5e8d07b3a3df63602396ea1655efcd683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Jesus?= Date: Wed, 8 May 2024 23:30:32 +0100 Subject: [PATCH] Fixed bug on map - crash being loaded. Improvements on frontend responsiveness. --- .../about/components/AuthorInfoView.kt | 86 ++++++------- .../AddMedicineToPharmacyScreen.kt | 28 +++-- .../components/MedicinePharmacyEntry.kt | 115 ++++++++---------- .../components/MedicineEntry.kt | 20 +-- .../ui/screens/pharmacy/PharmacyScreen.kt | 28 ++--- .../components/PharmacyMedicineEntry.kt | 93 ++++++-------- .../pharmacyMap/PharmacyMapActivity.kt | 3 +- .../screens/pharmacyMap/PharmacyMapScreen.kt | 2 + .../pharmacyMap/PharmacyMapViewModel.kt | 13 +- .../components/AddPharmacyButton.kt | 2 + .../components/AddPharmacyWindow.kt | 33 +++-- .../pharmacyMap/components/MapScreen.kt | 9 +- .../app/src/main/res/values/strings.xml | 2 +- 13 files changed, 204 insertions(+), 230 deletions(-) diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/about/components/AuthorInfoView.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/about/components/AuthorInfoView.kt index 8eaba10..99d8a95 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/about/components/AuthorInfoView.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/about/components/AuthorInfoView.kt @@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedCard import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -49,52 +50,55 @@ fun AuthorInfoView( onSendEmail: (String) -> Unit, onOpenUrl: (Uri) -> Unit ) { - Row( - modifier = Modifier.fillMaxWidth(DEV_INFO_MAX_WIDTH_FACTOR), - verticalAlignment = Alignment.CenterVertically - ) { - Image( - painter = painterResource(author.imageId), - contentDescription = stringResource(R.string.about_authorImage_contentDescription), - contentScale = ContentScale.Crop, - modifier = Modifier - .clip(CircleShape) - .size(IMAGE_SIZE.dp) - ) - - Column( - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center, - modifier = Modifier - .padding(DEV_INFO_PADDING.dp) - .fillMaxWidth() - .height(DEV_INFO_HEIGHT.dp) - .clip(RoundedCornerShape(DEV_INFO_CORNER_RADIUS.dp)) - .background(Color.LightGray) + OutlinedCard(modifier = Modifier.padding(bottom = 8.dp)) { + Row( + modifier = Modifier.fillMaxWidth(DEV_INFO_MAX_WIDTH_FACTOR), + verticalAlignment = Alignment.CenterVertically ) { - Text( - text = author.name, - style = MaterialTheme.typography.bodyLarge, - textAlign = TextAlign.Center, - color = Color.Black + Image( + painter = painterResource(author.imageId), + contentDescription = stringResource(R.string.about_authorImage_contentDescription), + contentScale = ContentScale.Crop, + modifier = Modifier + .padding(start = DEV_INFO_PADDING.dp) + .clip(CircleShape) + .size(IMAGE_SIZE.dp) ) - Row { - Image( - painter = painterResource(R.drawable.ic_github_dark), - contentDescription = stringResource(R.string.about_githubLogo_contentDescription), - modifier = Modifier - .clickable { onOpenUrl(author.githubLink) } - .padding(IMAGE_PADDING.dp) + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + modifier = Modifier + .padding(DEV_INFO_PADDING.dp) + .fillMaxWidth() + .height(DEV_INFO_HEIGHT.dp) + .clip(RoundedCornerShape(DEV_INFO_CORNER_RADIUS.dp)) + .background(Color.LightGray) + ) { + Text( + text = author.name, + style = MaterialTheme.typography.bodyLarge, + textAlign = TextAlign.Center, + color = Color.Black ) - Image( - painter = painterResource(R.drawable.ic_email), - contentDescription = stringResource(R.string.about_emailIcon_contentDescription), - modifier = Modifier - .clickable { onSendEmail(author.email) } - .padding(IMAGE_PADDING.dp) - ) + Row { + Image( + painter = painterResource(R.drawable.ic_github_dark), + contentDescription = stringResource(R.string.about_githubLogo_contentDescription), + modifier = Modifier + .clickable { onOpenUrl(author.githubLink) } + .padding(IMAGE_PADDING.dp) + ) + + Image( + painter = painterResource(R.drawable.ic_email), + contentDescription = stringResource(R.string.about_emailIcon_contentDescription), + modifier = Modifier + .clickable { onSendEmail(author.email) } + .padding(IMAGE_PADDING.dp) + ) + } } } } diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/addMedicineToPharmacy/AddMedicineToPharmacyScreen.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/addMedicineToPharmacy/AddMedicineToPharmacyScreen.kt index e9138ec..3c629bc 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/addMedicineToPharmacy/AddMedicineToPharmacyScreen.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/addMedicineToPharmacy/AddMedicineToPharmacyScreen.kt @@ -5,7 +5,8 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.Add +import androidx.compose.material.icons.rounded.AddCircleOutline +import androidx.compose.material.icons.rounded.Medication import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -65,7 +66,9 @@ fun AddMedicineToPharmacyScreen( if (selectedMedicine != null) { PharmacyMedicineEntry( - modifier = Modifier.fillMaxWidth(0.8f), + modifier = Modifier + .fillMaxWidth(0.9f) + .align(Alignment.CenterHorizontally), medicine = selectedMedicine, stock = stock, onAddStockClick = { @@ -77,27 +80,28 @@ fun AddMedicineToPharmacyScreen( ) } - IconTextButton( - onClick = createMedicine, - imageVector = Icons.Rounded.Add, - text = stringResource(R.string.create_medicine), - contentDescription = stringResource(R.string.create_medicine), - modifier = Modifier - .align(Alignment.CenterHorizontally) - ) - IconTextButton( onClick = { if (selectedMedicine != null) addMedicineToPharmacy(selectedMedicine.medicineId, stock) }, enabled = selectedMedicine != null, - imageVector = Icons.Rounded.Add, + imageVector = Icons.Rounded.AddCircleOutline, text = stringResource(R.string.add_medicine_to_pharmacy), contentDescription = stringResource(R.string.add_medicine_to_pharmacy), modifier = Modifier .align(Alignment.CenterHorizontally) ) + + IconTextButton( + onClick = createMedicine, + imageVector = Icons.Rounded.Medication, + text = stringResource(R.string.create_medicine), + contentDescription = stringResource(R.string.create_medicine), + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(bottom = 8.dp) + ) } } } diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/medicine/components/MedicinePharmacyEntry.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/medicine/components/MedicinePharmacyEntry.kt index fcd7403..ab1ca8b 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/medicine/components/MedicinePharmacyEntry.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/medicine/components/MedicinePharmacyEntry.kt @@ -1,30 +1,23 @@ package pt.ulisboa.ist.pharmacist.ui.screens.medicine.components -import android.view.MotionEvent import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.Favorite +import androidx.compose.material3.ElevatedCard import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text 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.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.input.pointer.pointerInteropFilter import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import pt.ulisboa.ist.pharmacist.R @@ -40,76 +33,68 @@ import pt.ulisboa.ist.pharmacist.ui.theme.Favorite * @param pharmacy the Pharmacy * @param onPharmacyClick function to be executed when the pharmacy is clicked */ -@OptIn(ExperimentalComposeUiApi::class) @Composable fun MedicinePharmacyEntry( pharmacy: PharmacyWithUserDataModel, onPharmacyClick: (Pharmacy) -> Unit ) { - var isHovered by remember { mutableStateOf(false) } - - Row(modifier = Modifier - .fillMaxWidth() + ElevatedCard(modifier = Modifier .height(120.dp) .padding(bottom = 8.dp) - .pointerInteropFilter { - when (it.action) { - MotionEvent.ACTION_HOVER_ENTER -> isHovered = true - MotionEvent.ACTION_HOVER_EXIT -> isHovered = false - } - false - } .background( - color = if (isHovered) Color.LightGray else MaterialTheme.colorScheme.secondary, + color = MaterialTheme.colorScheme.secondary, shape = MaterialTheme.shapes.medium ) .clickable { onPharmacyClick(pharmacy.pharmacy) - }) { - MeteredAsyncImage( - url = pharmacy.pharmacy.pictureUrl, - contentDescription = stringResource(R.string.pharmacyMap_pharmacyPicture_description), - modifier = Modifier - .width(100.dp) - .align(Alignment.CenterVertically) - .padding(start = 4.dp, end = 4.dp) - .clip(MaterialTheme.shapes.medium) - ) - Column( - modifier = Modifier - .padding(top = 8.dp) - .align(Alignment.Top) - ) { - Text( - text = pharmacy.pharmacy.name, - style = MaterialTheme.typography.titleMedium, + } + ) { + Row(modifier = Modifier.fillMaxSize()) { + MeteredAsyncImage( + url = pharmacy.pharmacy.pictureUrl, + contentDescription = stringResource(R.string.pharmacyMap_pharmacyPicture_description), modifier = Modifier + .width(100.dp) + .padding(start = 4.dp, end = 4.dp) + .align(Alignment.CenterVertically) + .clip(MaterialTheme.shapes.medium) ) - if (pharmacy.pharmacy.globalRating != null) - Row { - Text( - text = String.format("%.1f", pharmacy.pharmacy.globalRating), - style = MaterialTheme.typography.bodyMedium, - modifier = Modifier.align(Alignment.CenterVertically) - ) - StarRatingBar( - rating = pharmacy.pharmacy.globalRating.toInt(), - densityFactor = 6f - ) - } - if (pharmacy.userMarkedAsFavorite) - Row { - Icon( - imageVector = Icons.Rounded.Favorite, - contentDescription = null, - tint = Favorite, - ) - Text( - text = "Favorite Pharmacy", - style = MaterialTheme.typography.bodyMedium, - modifier = Modifier.align(Alignment.CenterVertically) - ) - } + Column( + modifier = Modifier + .padding(top = 8.dp) + .align(Alignment.Top) + ) { + Text( + text = pharmacy.pharmacy.name, + style = MaterialTheme.typography.titleMedium, + modifier = Modifier + ) + if (pharmacy.pharmacy.globalRating != null) + Row { + Text( + text = String.format("%.1f", pharmacy.pharmacy.globalRating), + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.align(Alignment.CenterVertically) + ) + StarRatingBar( + rating = pharmacy.pharmacy.globalRating.toInt(), + densityFactor = 6f + ) + } + if (pharmacy.userMarkedAsFavorite) + Row { + Icon( + imageVector = Icons.Rounded.Favorite, + contentDescription = null, + tint = Favorite, + ) + Text( + text = "Favorite Pharmacy", + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.align(Alignment.CenterVertically) + ) + } + } } } } \ No newline at end of file diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/medicineSearch/components/MedicineEntry.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/medicineSearch/components/MedicineEntry.kt index d8ae324..b1b815b 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/medicineSearch/components/MedicineEntry.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/medicineSearch/components/MedicineEntry.kt @@ -1,27 +1,21 @@ package pt.ulisboa.ist.pharmacist.ui.screens.medicineSearch.components -import android.view.MotionEvent import androidx.compose.foundation.background import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width +import androidx.compose.material3.ElevatedCard import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text 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.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.input.pointer.pointerInteropFilter import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import pt.ulisboa.ist.pharmacist.R @@ -46,22 +40,12 @@ fun MedicineEntry( onMedicineClicked: (Medicine) -> Unit, isSelected: Boolean, ) { - var isHovered by remember { mutableStateOf(false) } - - Box( + ElevatedCard( modifier = Modifier .padding(bottom = 8.dp) - .pointerInteropFilter { - when (it.action) { - MotionEvent.ACTION_HOVER_ENTER -> isHovered = true - MotionEvent.ACTION_HOVER_EXIT -> isHovered = false - } - false - } .background( when { isSelected -> Color.Gray - isHovered -> Color.LightGray else -> MaterialTheme.colorScheme.secondary }, shape = MaterialTheme.shapes.medium diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacy/PharmacyScreen.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacy/PharmacyScreen.kt index e5bcc77..055abe7 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacy/PharmacyScreen.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacy/PharmacyScreen.kt @@ -9,15 +9,13 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.Add import androidx.compose.material.icons.rounded.Favorite import androidx.compose.material.icons.rounded.FavoriteBorder import androidx.compose.material.icons.rounded.Flag +import androidx.compose.material.icons.rounded.Medication import androidx.compose.material.icons.rounded.OutlinedFlag import androidx.compose.material.icons.rounded.Share -import androidx.compose.material3.Button import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme @@ -47,6 +45,7 @@ import pt.ulisboa.ist.pharmacist.service.http.services.pharmacies.models.listAva import pt.ulisboa.ist.pharmacist.ui.screens.PharmacistScreen import pt.ulisboa.ist.pharmacist.ui.screens.pharmacy.components.PharmacyMedicineEntry import pt.ulisboa.ist.pharmacist.ui.screens.pharmacy.components.PharmacyRating +import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.IconTextButton import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.LoadingSpinner import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.MeteredAsyncImage import pt.ulisboa.ist.pharmacist.ui.theme.Favorite @@ -170,20 +169,12 @@ fun PharmacyScreen( .padding(8.dp) ) - Button( - onClick = onAddMedicineClick, - modifier = Modifier, - shape = CircleShape, - ) { - Icon( - Icons.Rounded.Add, - contentDescription = stringResource(R.string.add_medicine) - ) - Text( - text = stringResource(R.string.add_medicine), - style = MaterialTheme.typography.bodyMedium, - ) - } + IconTextButton( + imageVector = Icons.Rounded.Medication, + text = stringResource(R.string.add_medicine), + contentDescription = stringResource(R.string.add_medicine), + onClick = onAddMedicineClick + ) LazyColumn( modifier = Modifier @@ -197,7 +188,8 @@ fun PharmacyScreen( stock, onMedicineClick = onMedicineClick, onAddStockClick = onAddStockClick, - onRemoveStockClick = onRemoveStockClick + onRemoveStockClick = onRemoveStockClick, + modifier = Modifier.fillMaxWidth() ) } } diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacy/components/PharmacyMedicineEntry.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacy/components/PharmacyMedicineEntry.kt index 0f6c830..70a4934 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacy/components/PharmacyMedicineEntry.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacy/components/PharmacyMedicineEntry.kt @@ -1,31 +1,24 @@ package pt.ulisboa.ist.pharmacist.ui.screens.pharmacy.components -import android.view.MotionEvent import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.Add import androidx.compose.material.icons.rounded.Remove +import androidx.compose.material3.ElevatedCard import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text 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.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.input.pointer.pointerInteropFilter import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import pt.ulisboa.ist.pharmacist.R @@ -43,7 +36,6 @@ import kotlin.math.min * @param onAddStockClick function to be executed when the add stock button is clicked * @param onRemoveStockClick function to be executed when the remove stock button is clicked */ -@OptIn(ExperimentalComposeUiApi::class) @Composable fun PharmacyMedicineEntry( medicine: Medicine, @@ -53,32 +45,20 @@ fun PharmacyMedicineEntry( onAddStockClick: (Long) -> Unit, onRemoveStockClick: (Long) -> Unit ) { - var isHovered by remember { mutableStateOf(false) } - - Row( + ElevatedCard( modifier = Modifier - .fillMaxWidth() .height(120.dp) .padding(bottom = 8.dp) .background( color = MaterialTheme.colorScheme.secondary, shape = MaterialTheme.shapes.medium ) - .then(modifier) - ) { - Row(modifier = Modifier - .pointerInteropFilter { - when (it.action) { - MotionEvent.ACTION_HOVER_ENTER -> isHovered = true - MotionEvent.ACTION_HOVER_EXIT -> isHovered = false - } - false - } - .weight(0.9f) - .background(if (isHovered) Color.LightGray else Color.Transparent) .clickable { onMedicineClick(medicine.medicineId) - }) { + } + .then(modifier) + ) { + Row(modifier = Modifier.fillMaxSize()) { MeteredAsyncImage( url = medicine.boxPhotoUrl, contentDescription = stringResource(R.string.medicine_boxPhoto_description), @@ -90,6 +70,7 @@ fun PharmacyMedicineEntry( Column( modifier = Modifier .padding(top = 8.dp) + .weight(0.9f) .align(Alignment.CenterVertically) ) { Text( @@ -107,37 +88,37 @@ fun PharmacyMedicineEntry( modifier = Modifier.weight(0.1f) ) } - } - Column( - modifier = Modifier - .width(40.dp) - .height(200.dp) - .align(Alignment.CenterVertically) - ) { - IconButton( - onClick = { onAddStockClick(medicine.medicineId) }, - modifier = Modifier.align(Alignment.CenterHorizontally) - ) { - Icon( - Icons.Rounded.Add, - contentDescription = stringResource(R.string.add_stock), - tint = MaterialTheme.colorScheme.primary - ) - } - Text( - text = "$stock", - style = MaterialTheme.typography.bodyMedium, - modifier = Modifier.align(Alignment.CenterHorizontally) - ) - IconButton( - onClick = { onRemoveStockClick(medicine.medicineId) }, - modifier = Modifier.align(Alignment.CenterHorizontally) + Column( + modifier = Modifier + .width(40.dp) + .height(200.dp) + .align(Alignment.CenterVertically) ) { - Icon( - Icons.Rounded.Remove, - contentDescription = stringResource(R.string.remove_stock), - tint = MaterialTheme.colorScheme.primary + IconButton( + onClick = { onAddStockClick(medicine.medicineId) }, + modifier = Modifier.align(Alignment.CenterHorizontally) + ) { + Icon( + Icons.Rounded.Add, + contentDescription = stringResource(R.string.add_stock), + tint = MaterialTheme.colorScheme.primary + ) + } + Text( + text = "$stock", + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.align(Alignment.CenterHorizontally) ) + IconButton( + onClick = { onRemoveStockClick(medicine.medicineId) }, + modifier = Modifier.align(Alignment.CenterHorizontally) + ) { + Icon( + Icons.Rounded.Remove, + contentDescription = stringResource(R.string.remove_stock), + tint = MaterialTheme.colorScheme.primary + ) + } } } } diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapActivity.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapActivity.kt index cdf983e..14d8e5b 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapActivity.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapActivity.kt @@ -74,6 +74,7 @@ class PharmacyMapActivity : PharmacistActivity() { setContent { PharmacyMapScreen( followMyLocation = viewModel.followMyLocation, + zoomedInMyLocation = viewModel.zoomedInMyLocation, hasLocationPermission = viewModel.hasLocationPermission, hasCameraPermission = viewModel.hasCameraPermission, mapProperties = viewModel.mapProperties, @@ -115,6 +116,4 @@ class PharmacyMapActivity : PharmacistActivity() { viewModel.hasCameraPermission = hasCameraPermission() viewModel.loadPharmacyList() } - - } diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapScreen.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapScreen.kt index 6c9c72c..89967f2 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapScreen.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapScreen.kt @@ -46,6 +46,7 @@ import pt.ulisboa.ist.pharmacist.ui.screens.pharmacyMap.components.PermissionScr @Composable fun PharmacyMapScreen( followMyLocation: Boolean, + zoomedInMyLocation: Boolean, hasLocationPermission: Boolean, hasCameraPermission: Boolean, mapProperties: MapProperties, @@ -74,6 +75,7 @@ fun PharmacyMapScreen( MapScreen( hasCameraPermission = hasCameraPermission, followMyLocation = followMyLocation, + zoomedInMyLocation = zoomedInMyLocation, mapProperties = mapProperties, cameraPositionState = cameraPositionState, pharmacies = pharmacies, diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapViewModel.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapViewModel.kt index 60d1bf9..ec69379 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapViewModel.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/PharmacyMapViewModel.kt @@ -68,7 +68,7 @@ class PharmacyMapViewModel( private set var followMyLocation by mutableStateOf(true) - private var zoomedInMyLocation by mutableStateOf(false) + var zoomedInMyLocation by mutableStateOf(false) val mapProperties by mutableStateOf( MapProperties( @@ -194,14 +194,21 @@ class PharmacyMapViewModel( CameraPosition.fromLatLngZoom(latLng, DEFAULT_ZOOM) ) ) + Log.d(TAG, "Camera animation done") if (!zoomedInMyLocation) zoomedInMyLocation = true break } catch (e: CancellationException) { - Log.d(TAG, "Camera animation cancelled") + Log.d( + TAG, + "Camera animation cancelled: followMyLocation: $followMyLocation, zoomedInMyLocation: $zoomedInMyLocation" + ) throw e } catch (e: Exception) { - Log.d(TAG, "Camera animation failed") + Log.d( + TAG, + "Camera animation failed: followMyLocation: $followMyLocation, zoomedInMyLocation: $zoomedInMyLocation" + ) } } } diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/AddPharmacyButton.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/AddPharmacyButton.kt index 28dce4f..905b3cc 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/AddPharmacyButton.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/AddPharmacyButton.kt @@ -13,6 +13,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import pt.ulisboa.ist.pharmacist.R @@ -33,6 +34,7 @@ fun BoxScope.AddPharmacyButton( ExtendedFloatingActionButton( onClick = onClick, containerColor = MaterialTheme.colorScheme.primary, + contentColor = Color.White, modifier = Modifier .align(Alignment.BottomEnd) .padding(24.dp), diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/AddPharmacyWindow.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/AddPharmacyWindow.kt index aac8520..1511ff5 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/AddPharmacyWindow.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/AddPharmacyWindow.kt @@ -1,7 +1,9 @@ package pt.ulisboa.ist.pharmacist.ui.screens.pharmacyMap.components +import android.content.res.Configuration import androidx.compose.foundation.Image import androidx.compose.foundation.background +import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.IntrinsicSize @@ -10,7 +12,9 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.widthIn +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.Add import androidx.compose.material.icons.rounded.CameraAlt @@ -27,6 +31,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import pt.ulisboa.ist.pharmacist.R @@ -43,18 +48,27 @@ fun AddPharmacyWindow( searchQuery: String ) { var newPharmacyName by rememberSaveable { mutableStateOf("") } + val isLandscape = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE Box( modifier = Modifier - .background(Color.White, shape = RoundedCornerShape(8.dp)) .widthIn(0.dp, 300.dp) + .padding(top = 8.dp, start = if (isLandscape) 8.dp else 0.dp) .then(modifier) ) { - Column(modifier = Modifier.width(IntrinsicSize.Max)) { + Column( + modifier = Modifier + .width(IntrinsicSize.Max) + .background( + color = if (isSystemInDarkTheme()) Color.Black.copy(alpha = 0.8f) else Color.White, + shape = RoundedCornerShape(8.dp) + ) + .verticalScroll(rememberScrollState()), + horizontalAlignment = Alignment.CenterHorizontally + ) { Text( text = stringResource(R.string.pharmacy_details), - style = MaterialTheme.typography.titleMedium, - modifier = Modifier.align(Alignment.CenterHorizontally) + style = MaterialTheme.typography.titleMedium ) TextField( value = newPharmacyName, // TODO: Add validation @@ -63,14 +77,12 @@ fun AddPharmacyWindow( label = { Text(stringResource(R.string.pharmacy_name)) }, placeholder = { Text(stringResource(R.string.new_pharmacy)) }, modifier = Modifier - .align(Alignment.CenterHorizontally) .width(250.dp) .padding(8.dp) ) Text( text = searchQuery, modifier = Modifier - .align(Alignment.CenterHorizontally) .width(250.dp) .padding(8.dp) ) @@ -78,8 +90,7 @@ fun AddPharmacyWindow( onClick = { onPickOnMap() }, imageVector = Icons.Rounded.LocationOn, text = stringResource(R.string.pick_location), - contentDescription = stringResource(R.string.pick_location), - modifier = Modifier.align(Alignment.CenterHorizontally) + contentDescription = stringResource(R.string.pick_location) ) if (newPharmacyPhoto != null) Box( @@ -98,8 +109,7 @@ fun AddPharmacyWindow( onClick = { onAddPictureButtonClick() }, imageVector = Icons.Rounded.CameraAlt, text = stringResource(R.string.take_photo_select_image), - contentDescription = stringResource(R.string.take_photo_select_image), - modifier = Modifier.align(Alignment.CenterHorizontally) + contentDescription = stringResource(R.string.take_photo_select_image) ) IconTextButton( onClick = { @@ -109,8 +119,7 @@ fun AddPharmacyWindow( enabled = addPharmacyButtonEnabled && newPharmacyName.isNotBlank(), imageVector = Icons.Rounded.Add, text = stringResource(R.string.create_pharmacy), - contentDescription = stringResource(R.string.create_pharmacy), - modifier = Modifier.align(Alignment.CenterHorizontally) + contentDescription = stringResource(R.string.create_pharmacy) ) } } diff --git a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/MapScreen.kt b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/MapScreen.kt index a860df5..1b9f31a 100644 --- a/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/MapScreen.kt +++ b/src/frontend/app/src/main/kotlin/pt/ulisboa/ist/pharmacist/ui/screens/pharmacyMap/components/MapScreen.kt @@ -65,6 +65,7 @@ import pt.ulisboa.ist.pharmacist.ui.screens.pharmacyMap.PharmacyMapViewModel fun MapScreen( hasCameraPermission: Boolean, followMyLocation: Boolean, + zoomedInMyLocation: Boolean, mapProperties: MapProperties, cameraPositionState: CameraPositionState, pharmacies: SnapshotStateMap, @@ -139,12 +140,16 @@ fun MapScreen( ) } else { GoogleMap( + mergeDescendants = zoomedInMyLocation, modifier = Modifier.fillMaxSize(), cameraPositionState = cameraPositionState, uiSettings = MapUiSettings( zoomControlsEnabled = false, - scrollGesturesEnabled = !addingPharmacy || pickingOnMap, - myLocationButtonEnabled = !addingPharmacy || pickingOnMap + scrollGesturesEnabled = zoomedInMyLocation && (!addingPharmacy || pickingOnMap), + myLocationButtonEnabled = zoomedInMyLocation && (!addingPharmacy || pickingOnMap), + rotationGesturesEnabled = zoomedInMyLocation, + tiltGesturesEnabled = zoomedInMyLocation, + zoomGesturesEnabled = zoomedInMyLocation ), properties = mapProperties, onMyLocationButtonClick = { diff --git a/src/frontend/app/src/main/res/values/strings.xml b/src/frontend/app/src/main/res/values/strings.xml index ea874f7..dd019d7 100644 --- a/src/frontend/app/src/main/res/values/strings.xml +++ b/src/frontend/app/src/main/res/values/strings.xml @@ -95,7 +95,7 @@ Rating: Continue as guest Available Medicines - Create Medicine + Create New Medicine Add Medicine To Pharmacy medicines available Share