mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Merge branch 'bugfix/fix_save' into develop
This commit is contained in:
commit
8a95e2ee95
7 changed files with 77 additions and 19 deletions
|
@ -2,11 +2,11 @@
|
|||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "46c4983931eaf7414e25dfd9e1a55e0f",
|
||||
"identityHash": "7d1384a7162a98602e19c3ee54b7aee5",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "prescriptions",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cis` TEXT NOT NULL, `cip13` TEXT, `name` TEXT, `administration_mode` TEXT, `presentation` TEXT, `stock` REAL, `take` REAL, `warning` INTEGER, `alert` INTEGER, `last_update` INTEGER, PRIMARY KEY(`cis`))",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cis` TEXT NOT NULL, `cip13` TEXT, `name` TEXT, `administration_mode` TEXT, `presentation` TEXT, `stock` REAL, `take` REAL, `warning` INTEGER, `alert` INTEGER, `last_update` INTEGER, `label_group` TEXT, `genetic_type` INTEGER, PRIMARY KEY(`cis`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "cis",
|
||||
|
@ -67,6 +67,18 @@
|
|||
"columnName": "last_update",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "label_group",
|
||||
"columnName": "label_group",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "genetic_type",
|
||||
"columnName": "genetic_type",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
|
@ -82,7 +94,7 @@
|
|||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '46c4983931eaf7414e25dfd9e1a55e0f')"
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7d1384a7162a98602e19c3ee54b7aee5')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package net.foucry.pilldroid;
|
||||
|
||||
import androidx.room.Database;
|
||||
|
||||
import net.foucry.pilldroid.models.Medicine;
|
||||
import net.foucry.pilldroid.models.Prescription;
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package net.foucry.pilldroid.databases;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import net.foucry.pilldroid.dao.MedicinesDAO;
|
||||
|
@ -12,5 +15,21 @@ import net.foucry.pilldroid.models.Medicine;
|
|||
)
|
||||
|
||||
public abstract class MedicineDatabase extends RoomDatabase {
|
||||
private static MedicineDatabase INSTANCE;
|
||||
public abstract MedicinesDAO getMedicinesDAO();
|
||||
public static MedicineDatabase getInstanceDatabase(Context context) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE =
|
||||
Room
|
||||
.databaseBuilder(context.getApplicationContext(), MedicineDatabase.class, "medicines")
|
||||
.createFromAsset("drugs.db")
|
||||
.allowMainThreadQueries()
|
||||
.build();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void destroyInstance() {
|
||||
INSTANCE = null;
|
||||
}
|
||||
}
|
|
@ -1,17 +1,39 @@
|
|||
package net.foucry.pilldroid.databases;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.room.AutoMigration;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import net.foucry.pilldroid.dao.PrescriptionsDAO;
|
||||
import net.foucry.pilldroid.models.Prescription;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Database(
|
||||
version = 1,
|
||||
entities = {Prescription.class}
|
||||
)
|
||||
|
||||
public abstract class PrescriptionDatabase extends RoomDatabase {
|
||||
private static PrescriptionDatabase INSTANCE;
|
||||
public abstract PrescriptionsDAO getPrescriptionsDAO();
|
||||
public static PrescriptionDatabase getInstanceDatabase(Context context) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE =
|
||||
Room
|
||||
.databaseBuilder(context.getApplicationContext(),
|
||||
PrescriptionDatabase.class, "prescriptions")
|
||||
.allowMainThreadQueries()
|
||||
.build();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void destroyInstance() {
|
||||
INSTANCE = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ public class Prescription implements Serializable {
|
|||
private Integer warning;
|
||||
private Integer alert;
|
||||
private Long last_update;
|
||||
|
||||
private String label_group;
|
||||
private Integer genetic_type;
|
||||
|
||||
public void setCis(@NonNull String cis)
|
||||
{
|
||||
|
@ -113,7 +114,21 @@ public class Prescription implements Serializable {
|
|||
public int getWarnThreshold() {
|
||||
return this.warning;
|
||||
}
|
||||
public String getLabel_group() {
|
||||
return label_group;
|
||||
}
|
||||
|
||||
public void setLabel_group(String label_group) {
|
||||
this.label_group = label_group;
|
||||
}
|
||||
|
||||
public Integer getGenetic_type() {
|
||||
return genetic_type;
|
||||
}
|
||||
|
||||
public void setGenetic_type(Integer genetic_type) {
|
||||
this.genetic_type = genetic_type;
|
||||
}
|
||||
public Date getDateEndOfStock() {
|
||||
int numberDayOfTake;
|
||||
if (this.getTake() > 0) {
|
||||
|
|
Loading…
Reference in a new issue