Skip to content

Commit

Permalink
Medicine information panel now can be rotated.
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-j3sus committed May 9, 2024
1 parent 93ce599 commit e10baaa
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PharmacistApplication : DependenciesContainer, Application() {

companion object {
const val MEDICINE_NOTIFICATION_CHANNEL = "MedicineNotifications"
const val API_ENDPOINT = "http://10.0.2.2:8080" // "https://pharmacist-e9t4.onrender.com"
const val API_ENDPOINT = "https://pharmacist-e9t4.onrender.com"
const val TAG = "PharmacistApp"
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package pt.ulisboa.ist.pharmacist.ui.screens.medicine

import android.Manifest
import android.content.res.Configuration
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.NotificationsActive
import androidx.compose.material.icons.rounded.NotificationsOff
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.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.paging.PagingData
import androidx.paging.compose.collectAsLazyPagingItems
import kotlinx.coroutines.flow.Flow
Expand All @@ -31,10 +23,10 @@ import pt.ulisboa.ist.pharmacist.domain.medicines.GetMedicineOutputModel
import pt.ulisboa.ist.pharmacist.domain.pharmacies.Pharmacy
import pt.ulisboa.ist.pharmacist.service.http.services.pharmacies.models.getPharmacyById.PharmacyWithUserDataModel
import pt.ulisboa.ist.pharmacist.ui.screens.PharmacistScreen
import pt.ulisboa.ist.pharmacist.ui.screens.medicine.components.MedicinePharmacyEntry
import pt.ulisboa.ist.pharmacist.ui.screens.medicine.components.MedicineHeader
import pt.ulisboa.ist.pharmacist.ui.screens.medicine.components.MedicinePharmacyList
import pt.ulisboa.ist.pharmacist.ui.screens.pharmacyMap.components.PermissionScreen
import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.LoadingSpinner
import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.MeteredAsyncImage


/**
Expand All @@ -58,9 +50,10 @@ fun MedicineScreen(
val (medicine, notificationsActive) = medicineModel

val pharmacies = pharmaciesState.collectAsLazyPagingItems()
var hasPermission by remember {
mutableStateOf(hasLocationPermission)
}
var hasPermission by remember { mutableStateOf(hasLocationPermission) }

val isLandscape =
LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE

PharmacistScreen {
if (!hasPermission) {
Expand All @@ -78,65 +71,22 @@ fun MedicineScreen(
return@PharmacistScreen
}

Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
MeteredAsyncImage(
url = medicine.boxPhotoUrl,
contentDescription = stringResource(R.string.medicine_boxPhoto_description),
modifier = Modifier
.fillMaxWidth(0.6f)
.padding(top = 16.dp)
)

Text(
text = medicine.name,
style = MaterialTheme.typography.titleLarge,
modifier = Modifier
.padding(8.dp),
)

Text(
text = medicine.description,
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier
)

IconButton(
modifier = Modifier,
onClick = toggleMedicineNotification,
if (isLandscape)
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxSize()
) {
Icon(
if (notificationsActive) Icons.Rounded.NotificationsActive else Icons.Rounded.NotificationsOff,
contentDescription = stringResource(R.string.medicine_addToNotifications_button_description),
tint = MaterialTheme.colorScheme.primary
)
MedicineHeader(medicine, toggleMedicineNotification, notificationsActive)
MedicinePharmacyList(pharmacies, onPharmacyClick)
}

Text(
text = if (pharmacies.itemCount != 1) stringResource(
R.string.medicine_availableInXPharmacies_text,
pharmacies.itemCount
) else
stringResource(R.string.medicine_availableIn1Pharmacy_text),
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier
.padding(8.dp)
)
LazyColumn(
modifier = Modifier
.padding(10.dp)
else
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
items(pharmacies.itemCount) { index ->
val pharmacy = pharmacies[index]!!
MedicinePharmacyEntry(
pharmacy,
onPharmacyClick = onPharmacyClick
)
}
MedicineHeader(medicine, toggleMedicineNotification, notificationsActive)
MedicinePharmacyList(pharmacies, onPharmacyClick)
}
}
}
} else
Box {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package pt.ulisboa.ist.pharmacist.ui.screens.medicine.components

import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.NotificationsActive
import androidx.compose.material.icons.rounded.NotificationsOff
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import pt.ulisboa.ist.pharmacist.R
import pt.ulisboa.ist.pharmacist.domain.medicines.Medicine
import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.MeteredAsyncImage

@Composable
fun MedicineHeader(
medicine: Medicine,
toggleMedicineNotification: () -> Unit,
notificationsActive: Boolean
) {
val isLandscape =
LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE

Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(if (isLandscape) 0.5f else 1f)
) {
MeteredAsyncImage(
url = medicine.boxPhotoUrl,
contentDescription = stringResource(R.string.medicine_boxPhoto_description),
modifier = Modifier
.fillMaxWidth(if (isLandscape) 0.5f else 0.6f)
.padding(top = 16.dp)
)

Text(
text = medicine.name,
style = MaterialTheme.typography.titleLarge,
modifier = Modifier.padding(8.dp),
)

Text(
text = medicine.description,
style = MaterialTheme.typography.bodyLarge
)

IconButton(
modifier = Modifier,
onClick = toggleMedicineNotification,
) {
Icon(
if (notificationsActive) Icons.Rounded.NotificationsActive else Icons.Rounded.NotificationsOff,
contentDescription = stringResource(R.string.medicine_addToNotifications_button_description),
tint = MaterialTheme.colorScheme.primary
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package pt.ulisboa.ist.pharmacist.ui.screens.medicine.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.paging.compose.LazyPagingItems
import pt.ulisboa.ist.pharmacist.R
import pt.ulisboa.ist.pharmacist.domain.pharmacies.Pharmacy
import pt.ulisboa.ist.pharmacist.service.http.services.pharmacies.models.getPharmacyById.PharmacyWithUserDataModel

@Composable
fun MedicinePharmacyList(
pharmacies: LazyPagingItems<PharmacyWithUserDataModel>,
onPharmacyClick: (Pharmacy) -> Unit
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = if (pharmacies.itemCount != 1) stringResource(
R.string.medicine_availableInXPharmacies_text,
pharmacies.itemCount
) else
stringResource(R.string.medicine_availableIn1Pharmacy_text),
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier
.padding(8.dp)
)
LazyColumn(
modifier = Modifier
.padding(10.dp)
) {
items(pharmacies.itemCount) { index ->
val pharmacy = pharmacies[index]!!
MedicinePharmacyEntry(
pharmacy,
onPharmacyClick = onPharmacyClick
)
}
}
}
}

0 comments on commit e10baaa

Please sign in to comment.