Skip to content

Commit

Permalink
Added map with pharmacy location in the pharmacy information panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-j3sus committed May 6, 2024
1 parent 1ec07ff commit 34d3b05
Show file tree
Hide file tree
Showing 25 changed files with 85 additions and 45 deletions.
3 changes: 3 additions & 0 deletions src/frontend/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ dependencies {
implementation(libs.paging)
implementation(libs.pagingCompose)
implementation(libs.coil)

implementation(libs.google.accompanist.pager)
implementation(libs.accompanist.pager.indicators)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import androidx.annotation.RequiresApi
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import okhttp3.OkHttpClient
import pt.ulisboa.ist.pharmacist.service.real_time_updates.RealTimeUpdatesBackgroundService
import pt.ulisboa.ist.pharmacist.service.http.PharmacistService
import pt.ulisboa.ist.pharmacist.service.real_time_updates.RealTimeUpdatesBackgroundService
import pt.ulisboa.ist.pharmacist.session.SessionManager
import pt.ulisboa.ist.pharmacist.session.SessionManagerSharedPrefs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.content.Context
import android.content.Intent
import com.google.gson.JsonSyntaxException
import com.google.gson.stream.JsonReader
import java.io.IOException
import java.net.HttpURLConnection
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
Expand All @@ -22,6 +20,8 @@ import pt.ulisboa.ist.pharmacist.service.http.utils.fromJson
import pt.ulisboa.ist.pharmacist.session.SessionManager
import pt.ulisboa.ist.pharmacist.ui.screens.home.HomeActivity
import pt.ulisboa.ist.pharmacist.ui.screens.shared.navigateTo
import java.io.IOException
import java.net.HttpURLConnection

/**
* A service that communicates with a HTTP server.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pt.ulisboa.ist.pharmacist.service.http.connection

import pt.ulisboa.ist.pharmacist.service.http.media.Problem
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import pt.ulisboa.ist.pharmacist.service.http.media.Problem

/**
* API Response result.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package pt.ulisboa.ist.pharmacist.service.http.connection

import java.io.IOException
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import java.io.IOException
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

/**
* Sends a request through the HTTP client and parses the response into a [T].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pt.ulisboa.ist.pharmacist.service.http.media

import java.net.URI
import okhttp3.MediaType.Companion.toMediaType
import java.net.URI

/**
* A problem that occurred during the processing of a request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import okhttp3.Response
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import okio.ByteString
import pt.ulisboa.ist.pharmacist.service.real_time_updates.RealTimeUpdate
import pt.ulisboa.ist.pharmacist.service.http.utils.Uris
import pt.ulisboa.ist.pharmacist.service.http.utils.fromJson
import pt.ulisboa.ist.pharmacist.service.real_time_updates.RealTimeUpdate
import pt.ulisboa.ist.pharmacist.service.real_time_updates.RealTimeUpdatesBackgroundService.Companion.TAG
import pt.ulisboa.ist.pharmacist.session.SessionManager
import java.net.HttpURLConnection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pt.ulisboa.ist.pharmacist.service.http.services.users

import android.content.Context
import java.io.IOException
import okhttp3.OkHttpClient
import pt.ulisboa.ist.pharmacist.service.http.HTTPService
import pt.ulisboa.ist.pharmacist.service.http.connection.APIResult
Expand All @@ -11,6 +10,7 @@ import pt.ulisboa.ist.pharmacist.service.http.services.users.models.register.Reg
import pt.ulisboa.ist.pharmacist.service.http.services.users.models.register.RegisterOutput
import pt.ulisboa.ist.pharmacist.service.http.utils.Uris
import pt.ulisboa.ist.pharmacist.session.SessionManager
import java.io.IOException

/**
* The service that handles the users requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import pt.ulisboa.ist.pharmacist.domain.medicines.Medicine
import pt.ulisboa.ist.pharmacist.domain.pharmacies.Location
import pt.ulisboa.ist.pharmacist.service.LocationService
import pt.ulisboa.ist.pharmacist.service.http.PharmacistService
import pt.ulisboa.ist.pharmacist.service.http.connection.isFailure
import pt.ulisboa.ist.pharmacist.service.LocationService

import pt.ulisboa.ist.pharmacist.session.SessionManager
import pt.ulisboa.ist.pharmacist.ui.screens.PharmacistViewModel
import pt.ulisboa.ist.pharmacist.ui.screens.medicineSearch.MedicinePagingSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.viewModelScope
import java.util.UUID
import kotlinx.coroutines.launch
import pt.ulisboa.ist.pharmacist.service.http.PharmacistService
import pt.ulisboa.ist.pharmacist.service.http.connection.isSuccess
import pt.ulisboa.ist.pharmacist.session.SessionManager
import pt.ulisboa.ist.pharmacist.ui.screens.PharmacistViewModel
import java.util.UUID

/**
* View model for the [HomeActivity].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class MedicineViewModel(
if (result.isSuccess())
medicine = medicine?.copy(notificationsActive = true)
} else {
val result = pharmacistService.medicinesService.removeMedicineNotification(medicineId)
val result =
pharmacistService.medicinesService.removeMedicineNotification(medicineId)
if (result.isSuccess())
medicine = medicine?.copy(notificationsActive = false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package pt.ulisboa.ist.pharmacist.ui.screens.medicine

import androidx.paging.PagingSource
import androidx.paging.PagingState
import kotlin.math.max
import pt.ulisboa.ist.pharmacist.domain.pharmacies.Pharmacy
import pt.ulisboa.ist.pharmacist.service.http.connection.isSuccess
import pt.ulisboa.ist.pharmacist.service.http.services.pharmacies.PharmaciesService
import kotlin.math.max

class PharmaciesPagingSource(
private val pharmaciesService: PharmaciesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package pt.ulisboa.ist.pharmacist.ui.screens.medicineSearch
import android.util.Log
import androidx.paging.PagingSource
import androidx.paging.PagingState
import kotlin.math.max
import pt.ulisboa.ist.pharmacist.domain.pharmacies.Location
import pt.ulisboa.ist.pharmacist.service.http.connection.isSuccess
import pt.ulisboa.ist.pharmacist.service.http.services.medicines.MedicinesService
import pt.ulisboa.ist.pharmacist.service.http.services.medicines.models.getMedicinesWithClosestPharmacy.MedicineWithClosestPharmacyOutputModel
import kotlin.math.max

class MedicinePagingSource(
private val medicinesService: MedicinesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ fun MedicineSearch(
modifier = Modifier.align(Alignment.CenterVertically),
onClick = { onSearch(query) }
) {
Icon(Icons.Rounded.Search, contentDescription = stringResource(R.string.search_button))
Icon(
Icons.Rounded.Search,
contentDescription = stringResource(R.string.search_button)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import pt.ulisboa.ist.pharmacist.domain.pharmacies.Location
import pt.ulisboa.ist.pharmacist.service.http.PharmacistService
import pt.ulisboa.ist.pharmacist.service.LocationService

import pt.ulisboa.ist.pharmacist.service.http.PharmacistService
import pt.ulisboa.ist.pharmacist.session.SessionManager
import pt.ulisboa.ist.pharmacist.ui.screens.PharmacistViewModel
import pt.ulisboa.ist.pharmacist.ui.screens.shared.hasLocationPermission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ 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
import kotlin.math.min
import pt.ulisboa.ist.pharmacist.domain.medicines.Medicine
import pt.ulisboa.ist.pharmacist.domain.pharmacies.Pharmacy
import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.MeteredAsyncImage
import kotlin.math.min

/**
* A medicine entry in the search medicine result list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package pt.ulisboa.ist.pharmacist.ui.screens.pharmacy

import androidx.paging.PagingSource
import androidx.paging.PagingState
import kotlin.math.max
import pt.ulisboa.ist.pharmacist.service.http.connection.isSuccess
import pt.ulisboa.ist.pharmacist.service.http.services.pharmacies.PharmaciesService
import pt.ulisboa.ist.pharmacist.service.http.services.pharmacies.models.listAvailableMedicines.MedicineStockModel
import kotlin.math.max

class PharmacyMedicinesPagingSource(
private val pharmaciesService: PharmaciesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
Expand All @@ -13,7 +14,6 @@ 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.LocationOn
import androidx.compose.material.icons.rounded.OutlinedFlag
import androidx.compose.material.icons.rounded.Share
import androidx.compose.material3.Button
Expand All @@ -29,6 +29,16 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.paging.PagingData
import androidx.paging.compose.collectAsLazyPagingItems
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.HorizontalPagerIndicator
import com.google.accompanist.pager.rememberPagerState
import com.google.android.gms.maps.model.CameraPosition
import com.google.maps.android.compose.CameraPositionState
import com.google.maps.android.compose.GoogleMap
import com.google.maps.android.compose.MapUiSettings
import com.google.maps.android.compose.Marker
import com.google.maps.android.compose.MarkerState
import kotlinx.coroutines.flow.Flow
import pt.ulisboa.ist.pharmacist.R
import pt.ulisboa.ist.pharmacist.domain.pharmacies.Location
Expand All @@ -46,6 +56,7 @@ import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.MeteredAsyncImage
* @param pharmacy The pharmacy to display.
* @param loadingState The loading state of the pharmacy.
*/
@OptIn(ExperimentalPagerApi::class)
@Composable
fun PharmacyScreen(
pharmacy: PharmacyWithUserDataModel?,
Expand All @@ -63,31 +74,60 @@ fun PharmacyScreen(
) {
val medicinesStock = medicinesState.collectAsLazyPagingItems()

val pagerState = rememberPagerState(initialPage = 0)

PharmacistScreen {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
if (loadingState == PharmacyViewModel.PharmacyLoadingState.LOADED && pharmacy != null) {
MeteredAsyncImage(
url = pharmacy.pharmacy.pictureUrl,
contentDescription = stringResource(R.string.pharmacyMap_pharmacyPicture_description),
HorizontalPager(
count = 2,
state = pagerState,
modifier = Modifier
.fillMaxWidth(0.6f)
.padding(top = 16.dp, bottom = 8.dp)
)
.height(200.dp),
) { page ->
if (page == 0)
MeteredAsyncImage(
url = pharmacy.pharmacy.pictureUrl,
contentDescription = stringResource(R.string.pharmacyMap_pharmacyPicture_description),
modifier = Modifier.fillMaxSize()
)
else
GoogleMap(
modifier = Modifier.fillMaxSize(),
//onMapClick = { onNavigateToPharmacyClick(pharmacy.pharmacy.location) },
cameraPositionState = CameraPositionState(
position = CameraPosition(
pharmacy.pharmacy.location.toLatLng(),
15f,
0f,
0f
)
),
uiSettings = MapUiSettings(
myLocationButtonEnabled = false,
rotationGesturesEnabled = false,
scrollGesturesEnabled = false,
tiltGesturesEnabled = false
)
) {
Marker(
state = MarkerState(position = pharmacy.pharmacy.location.toLatLng()),
title = pharmacy.pharmacy.name
)
}
}
HorizontalPagerIndicator(pagerState = pagerState)

Text(
text = pharmacy.pharmacy.name,
style = MaterialTheme.typography.titleLarge
)
Row {
IconButton(onClick = { onNavigateToPharmacyClick(pharmacy.pharmacy.location) }) {
Icon(
Icons.Rounded.LocationOn,
contentDescription = stringResource(R.string.open_in_maps),
tint = MaterialTheme.colorScheme.primary
)
}
IconButton(onClick = onFavoriteClick) {
Icon(
if (pharmacy.userMarkedAsFavorite) Icons.Rounded.Favorite else Icons.Rounded.FavoriteBorder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ 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
import kotlin.math.min
import pt.ulisboa.ist.pharmacist.domain.medicines.Medicine
import pt.ulisboa.ist.pharmacist.ui.screens.shared.components.MeteredAsyncImage
import kotlin.math.min

/**
* A medicine entry in the pharmacy medicine list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package pt.ulisboa.ist.pharmacist.ui.screens.pharmacyMap

import android.graphics.Bitmap
import android.location.Geocoder
import android.os.Build
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.lifecycle.lifecycleScope
import com.google.android.libraries.places.api.Places
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package pt.ulisboa.ist.pharmacist.ui.screens.pharmacyMap
import android.annotation.SuppressLint
import android.content.Context
import android.location.Geocoder
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
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.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.content.Context
import android.os.Build
import android.widget.Toast
import androidx.annotation.RequiresApi
import kotlin.coroutines.resume
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume

/**
* Defines the duration of a [Toast] message.
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[versions]
agp = "8.3.2"
accompanistPagerVersion = "0.28.0"
agp = "8.4.0"
gson = "2.9.1"
kotlin = "1.9.0"
coreKtx = "1.10.1"
Expand All @@ -22,8 +23,10 @@ pagingComposeVersion = "3.3.0-beta01"


[libraries]
accompanist-pager-indicators = { module = "com.google.accompanist:accompanist-pager-indicators", version.ref = "accompanistPagerVersion" }
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "materialIconsExtended" }
google-accompanist-pager = { module = "com.google.accompanist:accompanist-pager", version.ref = "accompanistPagerVersion" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
Expand Down
Loading

0 comments on commit 34d3b05

Please sign in to comment.