From d6bd1590e836b0724db92a000613b833a21329b5 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 27 Mar 2022 18:08:41 +0200 Subject: [PATCH] change a method new; use singleton for the database access. --- .../java/net/foucry/pilldroid/DrugDetailActivity.java | 7 +++---- .../java/net/foucry/pilldroid/DrugListActivity.java | 11 ++--------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index eea98e9..5e7cd07 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -55,7 +55,7 @@ public class DrugDetailActivity extends AppCompatActivity { public void onClick(View view) { Log.d(TAG, "Click on save icon"); - getMDrugChanges(); + getDrugChanges(); setResult(1); finish(); overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right); @@ -107,11 +107,10 @@ public class DrugDetailActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } - private void getMDrugChanges() { + private void getDrugChanges() { Log.d(TAG, "Time to save new values"); - PrescriptionDatabase prescriptions = null; - assert false; + PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(this); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); Prescription newPrescription = prescriptionsDAO.getMedicByCIP13(aPrescription.getCip13()); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 6906407..628f7fb 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -93,17 +93,10 @@ public class DrugListActivity extends AppCompatActivity { } // Create medicines Room database from drugs.db files - medicines = Room - .databaseBuilder(getApplicationContext(), MedicineDatabase.class, "medicines") - .createFromAsset("drugs.db") - .allowMainThreadQueries() - .build(); + medicines = MedicineDatabase.getInstanceDatabase(this); // Create prescriptions Room database - prescriptions = Room - .databaseBuilder(getApplicationContext(), PrescriptionDatabase.class, "prescriptions") - .allowMainThreadQueries() - .build(); + prescriptions = PrescriptionDatabase.getInstanceDatabase(this); // Manually migrate old database to room PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();