Skip to content

Commit

Permalink
Fixed pharmacy notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-j3sus committed May 31, 2024
1 parent 35498e4 commit fe29cbc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import coil.request.CachePolicy
import coil.util.DebugLogger
import com.google.gson.Gson
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
Expand All @@ -30,6 +29,7 @@ import pt.ulisboa.ist.pharmacist.service.PharmacyNotificationWork
import pt.ulisboa.ist.pharmacist.service.real_time_updates.MedicineNotificationsBackgroundService
import pt.ulisboa.ist.pharmacist.service.real_time_updates.RealTimeUpdatesService
import pt.ulisboa.ist.pharmacist.session.SessionManager
import javax.inject.Inject


/**
Expand Down Expand Up @@ -106,26 +106,6 @@ class PharmacistApplication : DependenciesContainer, Application(), ImageLoaderF
notificationManager.createNotificationChannel(channel)
}

companion object {
const val MEDICINE_NOTIFICATION_CHANNEL = "MedicineNotifications"

private const val API_ENDPOINT_TYPE = "render"
val API_ENDPOINT = when (API_ENDPOINT_TYPE) {
"localhost" -> "http://10.0.2.2:8080"
"ngrok" -> "https://2b02-2001-818-e871-b700-c937-8172-33bf-a88.ngrok-free.app"
"render" -> "https://pharmacist-e9t4.onrender.com"
"domain" -> "https://thepharmacist.online"
else -> {
throw IllegalStateException("Invalid API_ENDPOINT_TYPE")
}
}
const val TAG = "PharmacistApp"
private const val PERIODIC_PHARMACY_NOTIFICATION_INTERVAL = 15L
private const val PHARMACY_NOTIFICATIONS_DELAY = 5000L


}

override fun newImageLoader(): ImageLoader {
return ImageLoader.Builder(this)
.memoryCachePolicy(CachePolicy.ENABLED)
Expand All @@ -151,4 +131,21 @@ class PharmacistApplication : DependenciesContainer, Application(), ImageLoaderF
.setWorkerFactory(workerFactory)
.build()

companion object {
const val MEDICINE_NOTIFICATION_CHANNEL = "MedicineNotifications"

private const val API_ENDPOINT_TYPE = "render"
val API_ENDPOINT = when (API_ENDPOINT_TYPE) {
"localhost" -> "http://10.0.2.2:8080"
"ngrok" -> "https://2b02-2001-818-e871-b700-c937-8172-33bf-a88.ngrok-free.app"
"render" -> "https://pharmacist-e9t4.onrender.com"
"domain" -> "https://thepharmacist.online"
else -> {
throw IllegalStateException("Invalid API_ENDPOINT_TYPE")
}
}
const val TAG = "PharmacistApp"
private const val PERIODIC_PHARMACY_NOTIFICATION_INTERVAL = 15L
private const val PHARMACY_NOTIFICATIONS_DELAY = 30_000L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.core.app.NotificationManagerCompat
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.location.Priority
import kotlin.coroutines.resume
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
Expand All @@ -22,6 +21,7 @@ import pt.ulisboa.ist.pharmacist.R
import pt.ulisboa.ist.pharmacist.repository.local.PharmacistDatabase
import pt.ulisboa.ist.pharmacist.repository.local.pharmacies.PharmacyEntity
import pt.ulisboa.ist.pharmacist.ui.screens.pharmacy.PharmacyActivity
import kotlin.coroutines.resume


class PharmacyNotificationService(
Expand Down Expand Up @@ -92,7 +92,6 @@ class PharmacyNotificationService(
pharmacyId
)

//TODO: Check what happens when the user clicks on the back button in the MedicineActivity after clicking on the notification
notificationIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK

val pendingNotiIntent: PendingIntent = PendingIntent.getActivity(
Expand All @@ -103,10 +102,7 @@ class PharmacyNotificationService(
)


val message = applicationContext.getString(
R.string.pharmacy_notification_message,
pharmacyName,
)
val message = applicationContext.getString(R.string.pharmacy_notification_message)

// Show notification to the user
val notificationCompat = NotificationCompat.Builder(
Expand All @@ -116,7 +112,7 @@ class PharmacyNotificationService(
.setSmallIcon(R.drawable.pharmacy_logo)
.setContentTitle(
applicationContext.getString(
R.string.pharmacy_notification_message,
R.string.pharmacy_notification_title,
pharmacyName
)
)
Expand Down Expand Up @@ -148,6 +144,6 @@ class PharmacyNotificationService(

companion object {
private const val PHARMACY_NOTIFICATION_ID = 1
private const val MAX_DISTANCE_METERS = 100
private const val MAX_DISTANCE_METERS = 500
}
}
7 changes: 4 additions & 3 deletions src/frontend/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@
<string name="pick_location">Elegir Ubicación</string>
<string name="medicine_available">medicamento disponible</string>
<string name="medicine_availableIn1Pharmacy_text">Disponible en 1 farmacia</string>
<string name="loading_pharmacy">Cargando farmacia...</string>
<string name="loading_pharmacy">Cargando farmacia</string>
<string name="no_medicine_selected">Ningún medicamento seleccionado</string>
<string name="star">Estrella</string>
<string name="favorite_pharmacy">Farmacia Favorita</string>
<string name="loading_medicine">Cargando medicamento...</string>
<string name="pharmacy_notification_message">Farmacia %1$s cerca de ti</string>
<string name="loading_medicine">Cargando medicamento…</string>
<string name="pharmacy_notification_title">Farmacia %1$s cerca de ti</string>
<string name="pharmacy_notification_message">Haz clic para ver más detalles</string>
</resources>
7 changes: 4 additions & 3 deletions src/frontend/app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@
<string name="pick_location">Escolher Localização</string>
<string name="medicine_available">medicamento disponível</string>
<string name="medicine_availableIn1Pharmacy_text">Disponível em 1 farmácia</string>
<string name="loading_pharmacy">Carregando farmácia...</string>
<string name="loading_pharmacy">Carregando farmácia</string>
<string name="no_medicine_selected">Nenhum medicamento selecionado</string>
<string name="star">Estrela</string>
<string name="favorite_pharmacy">Farmácia Favorita</string>
<string name="loading_medicine">Carregando medicamento...</string>
<string name="pharmacy_notification_message">Farmácia %1$s perto de ti</string>
<string name="loading_medicine">Carregando medicamento…</string>
<string name="pharmacy_notification_title">Farmácia %1$s perto de ti</string>
<string name="pharmacy_notification_message">Clique para ver mais detalhes</string>
</resources>
7 changes: 4 additions & 3 deletions src/frontend/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@
<string name="pick_location">Pick Location</string>
<string name="medicine_available">medicine available</string>
<string name="medicine_availableIn1Pharmacy_text">Available in 1 pharmacy</string>
<string name="loading_pharmacy">Loading pharmacy...</string>
<string name="loading_pharmacy">Loading pharmacy</string>
<string name="no_medicine_selected">No medicine selected.</string>
<string name="star">Star</string>
<string name="favorite_pharmacy">Favorite Pharmacy</string>
<string name="loading_medicine">Loading medicine...</string>
<string name="pharmacy_notification_message">Pharmacy %1$s near you</string>
<string name="loading_medicine">Loading medicine…</string>
<string name="pharmacy_notification_title">Pharmacy %1$s near you</string>
<string name="pharmacy_notification_message">Click here to navigate to the pharmacy information panel</string>
</resources>

0 comments on commit fe29cbc

Please sign in to comment.