Skip to content

Commit

Permalink
Fixed bug on map - crash being loaded.
Browse files Browse the repository at this point in the history
Improvements on frontend responsiveness.
  • Loading branch information
andre-j3sus committed May 8, 2024
1 parent dbdfd9d commit a9af2ca
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit a9af2ca

Please sign in to comment.