change a method new;

use singleton for the database access.
This commit is contained in:
jacques 2022-03-27 18:08:41 +02:00
parent dfaed88a56
commit d6bd1590e8
2 changed files with 5 additions and 13 deletions

View file

@ -55,7 +55,7 @@ public class DrugDetailActivity extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
Log.d(TAG, "Click on save icon"); Log.d(TAG, "Click on save icon");
getMDrugChanges(); getDrugChanges();
setResult(1); setResult(1);
finish(); finish();
overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right); overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right);
@ -107,11 +107,10 @@ public class DrugDetailActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void getMDrugChanges() { private void getDrugChanges() {
Log.d(TAG, "Time to save new values"); Log.d(TAG, "Time to save new values");
PrescriptionDatabase prescriptions = null; PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(this);
assert false;
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
Prescription newPrescription = prescriptionsDAO.getMedicByCIP13(aPrescription.getCip13()); Prescription newPrescription = prescriptionsDAO.getMedicByCIP13(aPrescription.getCip13());

View file

@ -93,17 +93,10 @@ public class DrugListActivity extends AppCompatActivity {
} }
// Create medicines Room database from drugs.db files // Create medicines Room database from drugs.db files
medicines = Room medicines = MedicineDatabase.getInstanceDatabase(this);
.databaseBuilder(getApplicationContext(), MedicineDatabase.class, "medicines")
.createFromAsset("drugs.db")
.allowMainThreadQueries()
.build();
// Create prescriptions Room database // Create prescriptions Room database
prescriptions = Room prescriptions = PrescriptionDatabase.getInstanceDatabase(this);
.databaseBuilder(getApplicationContext(), PrescriptionDatabase.class, "prescriptions")
.allowMainThreadQueries()
.build();
// Manually migrate old database to room // Manually migrate old database to room
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();