fix AlarmReceiver bug, was still using the hold that should be empty. Use now the room database management

This commit is contained in:
jacques 2022-05-04 19:48:19 +02:00
parent b5c9336bfc
commit 742d7cbe1f

View file

@ -14,6 +14,10 @@ import android.widget.Toast;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; 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.time.LocalTime;
import java.util.Date; import java.util.Date;
import java.util.List; 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(); } if (BuildConfig.DEBUG) { Toast.makeText(context, "New stock calculated", Toast.LENGTH_LONG).show(); }
createNotificationChannel(context); createNotificationChannel(context);
DBHelper dbHelper = new DBHelper(context); // TODO use room PrescriptionDatabase prescriptions = null;
dbHelper.getAllDrugs(); assert false;
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
List<Drug> drugs = dbHelper.getAllDrugs(); List<Prescription> prescriptionList = prescriptionsDAO.getAllMedics();
Prescription firstPrescription = null ;
Drug firstDrug = null; //List<Drug> drugs = dbHelper.getAllDrugs();
try { try {
firstDrug = drugs.get(0); firstPrescription = prescriptionList.get(1);
} }
catch (Exception e){ catch (Exception e){
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
} }
if (firstDrug != null) { if (firstPrescription != null) {
if (firstDrug.getTake() != 0) { if (firstPrescription.getTake() != 0) {
if(firstDrug.getStock() <= firstDrug.getAlertThreshold()) { if(firstPrescription.getStock() <= firstPrescription.getAlertThreshold()) {
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, DrugListActivity.class); Intent notificationIntent = new Intent(context, DrugListActivity.class);
@ -81,7 +85,7 @@ public class AlarmReceiver extends BroadcastReceiver {
notificationManager.notify(notificationId, builder.build()); notificationManager.notify(notificationId, builder.build());
} else } else
{ {
double dummy = (firstDrug.getStock() - firstDrug.getAlertThreshold()); double dummy = (firstPrescription.getStock() - firstPrescription.getAlertThreshold());
Log.d(TAG, "no notification scheduled " + dummy); Log.d(TAG, "no notification scheduled " + dummy);
} }
} }