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,
|
"formatVersion": 1,
|
||||||
"database": {
|
"database": {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"identityHash": "46c4983931eaf7414e25dfd9e1a55e0f",
|
"identityHash": "7d1384a7162a98602e19c3ee54b7aee5",
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
"tableName": "prescriptions",
|
"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": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "cis",
|
"fieldPath": "cis",
|
||||||
|
@ -67,6 +67,18 @@
|
||||||
"columnName": "last_update",
|
"columnName": "last_update",
|
||||||
"affinity": "INTEGER",
|
"affinity": "INTEGER",
|
||||||
"notNull": false
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "label_group",
|
||||||
|
"columnName": "label_group",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "genetic_type",
|
||||||
|
"columnName": "genetic_type",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"primaryKey": {
|
"primaryKey": {
|
||||||
|
@ -82,7 +94,7 @@
|
||||||
"views": [],
|
"views": [],
|
||||||
"setupQueries": [
|
"setupQueries": [
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
"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) {
|
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());
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.foucry.pilldroid;
|
package net.foucry.pilldroid;
|
||||||
|
|
||||||
import androidx.room.Database;
|
|
||||||
|
|
||||||
import net.foucry.pilldroid.models.Medicine;
|
import net.foucry.pilldroid.models.Medicine;
|
||||||
import net.foucry.pilldroid.models.Prescription;
|
import net.foucry.pilldroid.models.Prescription;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package net.foucry.pilldroid.databases;
|
package net.foucry.pilldroid.databases;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.room.Database;
|
import androidx.room.Database;
|
||||||
|
import androidx.room.Room;
|
||||||
import androidx.room.RoomDatabase;
|
import androidx.room.RoomDatabase;
|
||||||
|
|
||||||
import net.foucry.pilldroid.dao.MedicinesDAO;
|
import net.foucry.pilldroid.dao.MedicinesDAO;
|
||||||
|
@ -12,5 +15,21 @@ import net.foucry.pilldroid.models.Medicine;
|
||||||
)
|
)
|
||||||
|
|
||||||
public abstract class MedicineDatabase extends RoomDatabase {
|
public abstract class MedicineDatabase extends RoomDatabase {
|
||||||
|
private static MedicineDatabase INSTANCE;
|
||||||
public abstract MedicinesDAO getMedicinesDAO();
|
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;
|
package net.foucry.pilldroid.databases;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.room.AutoMigration;
|
import androidx.room.AutoMigration;
|
||||||
import androidx.room.Database;
|
import androidx.room.Database;
|
||||||
|
import androidx.room.Room;
|
||||||
import androidx.room.RoomDatabase;
|
import androidx.room.RoomDatabase;
|
||||||
|
|
||||||
import net.foucry.pilldroid.dao.PrescriptionsDAO;
|
import net.foucry.pilldroid.dao.PrescriptionsDAO;
|
||||||
import net.foucry.pilldroid.models.Prescription;
|
import net.foucry.pilldroid.models.Prescription;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
version = 1,
|
version = 1,
|
||||||
entities = {Prescription.class}
|
entities = {Prescription.class}
|
||||||
)
|
)
|
||||||
|
|
||||||
public abstract class PrescriptionDatabase extends RoomDatabase {
|
public abstract class PrescriptionDatabase extends RoomDatabase {
|
||||||
|
private static PrescriptionDatabase INSTANCE;
|
||||||
public abstract PrescriptionsDAO getPrescriptionsDAO();
|
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 warning;
|
||||||
private Integer alert;
|
private Integer alert;
|
||||||
private Long last_update;
|
private Long last_update;
|
||||||
|
private String label_group;
|
||||||
|
private Integer genetic_type;
|
||||||
|
|
||||||
public void setCis(@NonNull String cis)
|
public void setCis(@NonNull String cis)
|
||||||
{
|
{
|
||||||
|
@ -113,7 +114,21 @@ public class Prescription implements Serializable {
|
||||||
public int getWarnThreshold() {
|
public int getWarnThreshold() {
|
||||||
return this.warning;
|
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() {
|
public Date getDateEndOfStock() {
|
||||||
int numberDayOfTake;
|
int numberDayOfTake;
|
||||||
if (this.getTake() > 0) {
|
if (this.getTake() > 0) {
|
||||||
|
|
Loading…
Reference in a new issue