From 742d7cbe1f8d9851430cd2c2d2853bf435e05579 Mon Sep 17 00:00:00 2001 From: jacques Date: Wed, 4 May 2022 19:48:19 +0200 Subject: [PATCH] fix AlarmReceiver bug, was still using the hold that should be empty. Use now the room database management --- .../net/foucry/pilldroid/AlarmReceiver.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index ffdcfd0..26265c6 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -14,6 +14,10 @@ import android.widget.Toast; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; +import net.foucry.pilldroid.dao.PrescriptionsDAO; +import net.foucry.pilldroid.databases.PrescriptionDatabase; +import net.foucry.pilldroid.models.Prescription; + import java.time.LocalTime; import java.util.Date; import java.util.List; @@ -41,24 +45,24 @@ public class AlarmReceiver extends BroadcastReceiver { if (BuildConfig.DEBUG) { Toast.makeText(context, "New stock calculated", Toast.LENGTH_LONG).show(); } createNotificationChannel(context); - DBHelper dbHelper = new DBHelper(context); // TODO use room - dbHelper.getAllDrugs(); - - List drugs = dbHelper.getAllDrugs(); - - Drug firstDrug = null; + PrescriptionDatabase prescriptions = null; + assert false; + PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); + List prescriptionList = prescriptionsDAO.getAllMedics(); + Prescription firstPrescription = null ; + //List drugs = dbHelper.getAllDrugs(); try { - firstDrug = drugs.get(0); + firstPrescription = prescriptionList.get(1); } catch (Exception e){ Log.e(TAG, e.toString()); e.printStackTrace(); } - if (firstDrug != null) { - if (firstDrug.getTake() != 0) { - if(firstDrug.getStock() <= firstDrug.getAlertThreshold()) { + if (firstPrescription != null) { + if (firstPrescription.getTake() != 0) { + if(firstPrescription.getStock() <= firstPrescription.getAlertThreshold()) { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, DrugListActivity.class); @@ -81,7 +85,7 @@ public class AlarmReceiver extends BroadcastReceiver { notificationManager.notify(notificationId, builder.build()); } else { - double dummy = (firstDrug.getStock() - firstDrug.getAlertThreshold()); + double dummy = (firstPrescription.getStock() - firstPrescription.getAlertThreshold()); Log.d(TAG, "no notification scheduled " + dummy); } }