From 3e38c7223c89d18b55f732980f2ff53d3b31b2cf Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Mon, 7 Mar 2022 18:18:55 +0100 Subject: [PATCH 01/31] Add Room dependencies --- app/build.gradle | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index cc3eb2b..cdd6735 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,6 +102,7 @@ sourceSets { } } dependencies { + def room_version = "2.4.2" implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation 'junit:junit:4.13.2' @@ -109,9 +110,13 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - + implementation "androidx:room:room-runtime:$room_version" implementation 'com.journeyapps:zxing-android-embedded:4.3.0' implementation 'androidx.core:core:1.7.0' + implementation "androidx:room:room-runtime:$room_version" + implementation "androidx.room:room-rxjava3:$room_version" + testImplementation "androidx.room:room-testing:$room_version" + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } From a98601c8b08dd716ee3481d8a5f678cd6a2149be Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Mon, 7 Mar 2022 18:19:35 +0100 Subject: [PATCH 02/31] Add Room prescription database amangement --- .../net/foucry/pilldroid/MedicDatabase.java | 13 ++++++++ .../net/foucry/pilldroid/dao/MedicDAO.java | 32 +++++++++++++++++++ .../net/foucry/pilldroid/models/Medic.java | 22 +++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 app/src/main/java/net/foucry/pilldroid/MedicDatabase.java create mode 100644 app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java create mode 100644 app/src/main/java/net/foucry/pilldroid/models/Medic.java diff --git a/app/src/main/java/net/foucry/pilldroid/MedicDatabase.java b/app/src/main/java/net/foucry/pilldroid/MedicDatabase.java new file mode 100644 index 0000000..2aaf85c --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/MedicDatabase.java @@ -0,0 +1,13 @@ +package net.foucry.pilldroid; + +import android.arch.persistence.root.Database; +import android.arch.persistence.root.RoomDatabase; + +import net.foucry.pilldroid.dao.MedicDAO; +import net.foucry.pilldroid.model.Medic; + +@Database(entities = {Medic.class}, version = 1) + +public abstract class PilldroidDatabase extends RoomDatabase { + public abstract MedicDAO getMedicDAO(); +} diff --git a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java new file mode 100644 index 0000000..56b2df5 --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java @@ -0,0 +1,32 @@ +package net.foucry.pilldroid.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Delete; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.Update; +import net.foucry.pilldroid.models.Medic; + +import android.arch.persistence.room.Query; +import java.util.list; + +@Dao +public interface MedicDAO { + @Insert + public void insert(Medic... medics); + @Upfdate + public void update(Medic... medics); + @Delete + public void delete(Medic medic); +} + +@Query("SELECT * FROM medics") +public List getMedics(); + +@Query("SELECT * FROM medics WHERE id = :id") +public Medic getMedicBy(Long id); + +@Query("SELECT * FROM medics WHERE cip13 = :cip13") +public Medic getMedicByCIP13(String cip13); + +@Query("SELECT count(*) FROM medics") +public int getMedicCount(); diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medic.java b/app/src/main/java/net/foucry/pilldroid/models/Medic.java new file mode 100644 index 0000000..3c050fb --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/models/Medic.java @@ -0,0 +1,22 @@ +package net.foucry.pilldroid.models; + +import android.arch.persitence.room.Entity; +import android.arch.persitence.room.PrimaryKey; +import android.support.annotation.NonNull; + +@Entity(tableName = "medics") +public class medic { + @PrimaryKey + @NonNull private Long id; + private String cis; + private String cip13; + private String name; + private String administration_mode; + private String presentation; + private Long stock; + private Long take; + private Int warning; + private Int alert; + private Long last_update; +} + From 0681c63c8e85d53196d1f1d1d1c9275a1fc9e2fb Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Mon, 7 Mar 2022 18:19:57 +0100 Subject: [PATCH 03/31] Add demo code for room database amanagement --- .../foucry/pilldroid/DrugListActivity.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index c9f724f..3f3bd1c 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -39,6 +39,9 @@ import java.util.Date; import java.util.List; import java.util.Locale; +import net.foucry.pilldroid.dao.MedicDAO; +import net.foucry.pilldroid.models.Medic; + /** * An activity representing a list of Drugs is activity * has different presentations for handset and tablet-size devices. On @@ -118,6 +121,11 @@ public class DrugListActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // Create Room database + PilldroidDatabase prescription = Room.databaseBuilder(this, PilldroidDatabase.class, "prescription") + .allowMainThreadQueries() + .build(); + setContentView(R.layout.activity_drug_list); dbHelper = new DBHelper(this); @@ -136,6 +144,31 @@ public class DrugListActivity extends AppCompatActivity { } if (DEMO) { + MedicDAO medicDAO = prescription.getMedicDAO(); + + final int min_stock = 5; + final int max_stock = 50; + final int min_prise = 0; + final int max_prise = 3; + + for(int i=1; i < 11; i++) { + Medic medic = new Medic(); + medic.setName=("Medicament test "+ i); + medic.setCip13=("340093000001"+i); + medic.setCis=("6000001"+i); + medic.setAdministration_mode=("oral"); + medic.setPresentation=i("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); + setStock=intRandomExclusive(min_stock,max_stock); + setTake=intRandomExclusive(min_take, max_take); + setWarning=14; + setAlert=7; + setLastDate=UtilDate.dateAtNoon(new Date()).getTime(); + + medicDAO.insert(item); + } + List prescriptions = medicDAO.getMedics(); + System.out.println(prescriptions); +/* if (dbHelper.getCount() == 0) { // String cis, String cip13, String nom, String mode_administration, @@ -177,7 +210,7 @@ public class DrugListActivity extends AppCompatActivity { dbHelper.addDrug(new Drug("60000010", "3400930000010", "Médicament test 10", "orale", "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - } + }*/ } mBarcodeScannerLauncher = registerForActivityResult(new PilldroidScanContract(), From 615d2f191425e9366635cac7a64ee198f5042974 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 7 Mar 2022 22:07:50 +0100 Subject: [PATCH 04/31] Update dependencies for room --- app/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index cdd6735..9ce3814 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,6 +102,8 @@ sourceSets { } } dependencies { + implementation 'androidx.room:room-common:2.4.2' + annotationProcessor 'androidx.room:room-compiler:2.4.2' def room_version = "2.4.2" implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation 'junit:junit:4.13.2' From bed4186bc3117bd9a4044739730537e873bbe235 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 7 Mar 2022 22:08:21 +0100 Subject: [PATCH 05/31] use correct import --- ...icDatabase.java => PilldroidDatabase.java} | 6 +-- .../net/foucry/pilldroid/dao/MedicDAO.java | 54 ++++++++++--------- 2 files changed, 32 insertions(+), 28 deletions(-) rename app/src/main/java/net/foucry/pilldroid/{MedicDatabase.java => PilldroidDatabase.java} (62%) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicDatabase.java b/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java similarity index 62% rename from app/src/main/java/net/foucry/pilldroid/MedicDatabase.java rename to app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java index 2aaf85c..9ba304a 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicDatabase.java +++ b/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java @@ -1,10 +1,10 @@ package net.foucry.pilldroid; -import android.arch.persistence.root.Database; -import android.arch.persistence.root.RoomDatabase; +import androidx.room.Database; +import androidx.room.RoomDatabase; import net.foucry.pilldroid.dao.MedicDAO; -import net.foucry.pilldroid.model.Medic; +import net.foucry.pilldroid.models.Medic; @Database(entities = {Medic.class}, version = 1) diff --git a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java index 56b2df5..bf1b3fc 100644 --- a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java +++ b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java @@ -1,32 +1,36 @@ package net.foucry.pilldroid.dao; -import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Delete; -import android.arch.persistence.room.Insert; -import android.arch.persistence.room.Update; -import net.foucry.pilldroid.models.Medic; +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; -import android.arch.persistence.room.Query; -import java.util.list; +import net.foucry.pilldroid.models.Medic; + +import java.util.List; @Dao public interface MedicDAO { - @Insert - public void insert(Medic... medics); - @Upfdate - public void update(Medic... medics); - @Delete - public void delete(Medic medic); + @Insert + void insert(Medic... medics); + + @Update + void update(Medic... medics); + + @Delete + void delete(Medic medic); + + + @Query("SELECT * FROM medics") + List getMedics(); + + @Query("SELECT * FROM medics WHERE id = :id") + Medic getMedicBy(Long id); + + @Query("SELECT * FROM medics WHERE cip13 = :cip13") + Medic getMedicByCIP13(String cip13); + + @Query("SELECT count(*) FROM medics") + int getMedicCount(); } - -@Query("SELECT * FROM medics") -public List getMedics(); - -@Query("SELECT * FROM medics WHERE id = :id") -public Medic getMedicBy(Long id); - -@Query("SELECT * FROM medics WHERE cip13 = :cip13") -public Medic getMedicByCIP13(String cip13); - -@Query("SELECT count(*) FROM medics") -public int getMedicCount(); From 88c534e71968258aa0bcf54dfed46529456eef80 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 7 Mar 2022 22:09:23 +0100 Subject: [PATCH 06/31] use correct import add getters and setters --- .../net/foucry/pilldroid/models/Medic.java | 108 ++++++++++++++++-- 1 file changed, 101 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medic.java b/app/src/main/java/net/foucry/pilldroid/models/Medic.java index 3c050fb..f245a4b 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Medic.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Medic.java @@ -1,13 +1,13 @@ package net.foucry.pilldroid.models; -import android.arch.persitence.room.Entity; -import android.arch.persitence.room.PrimaryKey; -import android.support.annotation.NonNull; +import androidx.room.Entity; +import androidx.room.PrimaryKey; +import androidx.annotation.NonNull; @Entity(tableName = "medics") -public class medic { +public class Medic { @PrimaryKey - @NonNull private Long id; + @NonNull private final Integer id; private String cis; private String cip13; private String name; @@ -15,8 +15,102 @@ public class medic { private String presentation; private Long stock; private Long take; - private Int warning; - private Int alert; + private Integer warning; + private Integer alert; private Long last_update; + + public Medic(@NonNull Integer id) { + this.id = id; + } + + public void setCis(String cis) +{ + this.cis = cis; } + + public void setCip13(String cip13) { + this.cip13 = cip13; + } + + public void setName(String name) { + this.name = name; + } + +public void setAdministration_mode(String administration_mode) { + + this.administration_mode = administration_mode; +} + +public void setPresentation(String presentation) { + this.presentation = presentation; +} +public void setStock(Long stock) { + this.stock = stock; +} + +public void setTake(Long take) { + this.take = take; +} + +public void setWarning(Integer warning) { + this.warning = warning; +} + +public void setAlert(Integer alert) { + this.alert = alert; +} + +public void setLast_update(Long last_update) { + this.last_update = last_update; +} + +@NonNull +Integer getId() { + return this.id; +} + +String getCis() { + return this.cis; +} + + public Integer getWarning() { + return warning; + } + + public String getCip13() { + return cip13; + } + + public String getName() { + return name; + } + + public String getAdministration_mode() { + return administration_mode; + } + + public String getPresentation() { + return presentation; + } + + public Long getStock() { + return stock; + } + + public Long getTake() { + return take; + } + + public Integer getAlert() { + return alert; + } + + public Long getLast_update() { + return last_update; + } +} + + + + From be85f8c69daec4989af1475b48a5965b1587ab06 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 7 Mar 2022 22:10:20 +0100 Subject: [PATCH 07/31] use correct import use getters and setters --- .../foucry/pilldroid/DrugListActivity.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 3f3bd1c..86b91a3 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -30,6 +30,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.RecyclerView; +import androidx.room.Room; import com.google.zxing.client.android.Intents; import com.journeyapps.barcodescanner.ScanOptions; @@ -122,10 +123,12 @@ public class DrugListActivity extends AppCompatActivity { super.onCreate(savedInstanceState); // Create Room database - PilldroidDatabase prescription = Room.databaseBuilder(this, PilldroidDatabase.class, "prescription") - .allowMainThreadQueries() - .build(); + PilldroidDatabase prescription = Room + .databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "prescriptions") + .allowMainThreadQueries() + .build(); + // Set view content setContentView(R.layout.activity_drug_list); dbHelper = new DBHelper(this); @@ -148,23 +151,23 @@ public class DrugListActivity extends AppCompatActivity { final int min_stock = 5; final int max_stock = 50; - final int min_prise = 0; - final int max_prise = 3; + final int min_take = 0; + final int max_take = 3; for(int i=1; i < 11; i++) { - Medic medic = new Medic(); - medic.setName=("Medicament test "+ i); - medic.setCip13=("340093000001"+i); - medic.setCis=("6000001"+i); - medic.setAdministration_mode=("oral"); - medic.setPresentation=i("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); - setStock=intRandomExclusive(min_stock,max_stock); - setTake=intRandomExclusive(min_take, max_take); - setWarning=14; - setAlert=7; - setLastDate=UtilDate.dateAtNoon(new Date()).getTime(); + Medic medic = new Medic(i); + medic.setName("Medicament test " + i); + medic.setCip13("340093000001" + i); + medic.setCis("6000001" + i); + medic.setAdministration_mode("oral"); + medic.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); + medic.setStock((long) intRandomExclusive(min_stock, max_stock)); + medic.setTake((long) intRandomExclusive(min_take, max_take)); + medic.setWarning(14); + medic.setAlert(7); + medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime()); - medicDAO.insert(item); + medicDAO.insert(medic); } List prescriptions = medicDAO.getMedics(); System.out.println(prescriptions); From c43e5d18800161fda8350bb7b7d1b5d8ce5b16df Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 8 Mar 2022 19:46:20 +0100 Subject: [PATCH 08/31] Add generated json database schema --- app/build.gradle | 19 ++-- .../1.json | 88 +++++++++++++++++++ 2 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 app/schemas/net.foucry.pilldroid.PilldroidDatabase/1.json diff --git a/app/build.gradle b/app/build.gradle index 9ce3814..dded18e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,6 +39,11 @@ android { versionCode 100 versionName "v0.100-beta" multiDexEnabled true + javaCompileOptions { + annotationProcessorOptions { + arguments += ["room.schemaLocation": "$projectDir/schemas".toString()] + } + } } buildTypes { @@ -102,9 +107,12 @@ sourceSets { } } dependencies { - implementation 'androidx.room:room-common:2.4.2' - annotationProcessor 'androidx.room:room-compiler:2.4.2' - def room_version = "2.4.2" + implementation "androidx.room:room-common:2.4.2" + annotationProcessor "androidx.room:room-compiler:2.4.2" + implementation "androidx.room:room-testing:2.4.2" + implementation "androidx.room:room-rxjava3:2.4.2" + implementation "androidx.room:room-runtime:2.4.2" + implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation 'junit:junit:4.13.2' @@ -112,13 +120,8 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation "androidx:room:room-runtime:$room_version" implementation 'com.journeyapps:zxing-android-embedded:4.3.0' implementation 'androidx.core:core:1.7.0' - implementation "androidx:room:room-runtime:$room_version" - implementation "androidx.room:room-rxjava3:$room_version" - testImplementation "androidx.room:room-testing:$room_version" - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/app/schemas/net.foucry.pilldroid.PilldroidDatabase/1.json b/app/schemas/net.foucry.pilldroid.PilldroidDatabase/1.json new file mode 100644 index 0000000..d4fe768 --- /dev/null +++ b/app/schemas/net.foucry.pilldroid.PilldroidDatabase/1.json @@ -0,0 +1,88 @@ +{ + "formatVersion": 1, + "database": { + "version": 1, + "identityHash": "5ac4c79044120e5fa2716c6a89eff9bf", + "entities": [ + { + "tableName": "medics", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cis` TEXT NOT NULL, `cip13` TEXT, `name` TEXT, `administration_mode` TEXT, `presentation` TEXT, `stock` INTEGER, `take` INTEGER, `warning` INTEGER, `alert` INTEGER, `last_update` INTEGER, PRIMARY KEY(`cis`))", + "fields": [ + { + "fieldPath": "cis", + "columnName": "cis", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "cip13", + "columnName": "cip13", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "administration_mode", + "columnName": "administration_mode", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "presentation", + "columnName": "presentation", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "stock", + "columnName": "stock", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "take", + "columnName": "take", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "warning", + "columnName": "warning", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "alert", + "columnName": "alert", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "last_update", + "columnName": "last_update", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "cis" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "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, '5ac4c79044120e5fa2716c6a89eff9bf')" + ] + } +} \ No newline at end of file From 14f481175b742ee8f4d9d9b14f6d8a22f123a612 Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 8 Mar 2022 19:47:27 +0100 Subject: [PATCH 09/31] Minor change in calling Room --- .../main/java/net/foucry/pilldroid/DrugListActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 86b91a3..3285b7d 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -58,7 +58,7 @@ public class DrugListActivity extends AppCompatActivity { */ // TODO: Change DEMO/DBDEMO form static to non-static. In order to create fake data at only at launch time - final Boolean DEMO = false; + final Boolean DEMO = true; final Boolean DBDEMO = false; public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff; @@ -155,7 +155,7 @@ public class DrugListActivity extends AppCompatActivity { final int max_take = 3; for(int i=1; i < 11; i++) { - Medic medic = new Medic(i); + Medic medic = new Medic(); medic.setName("Medicament test " + i); medic.setCip13("340093000001" + i); medic.setCis("6000001" + i); @@ -167,7 +167,7 @@ public class DrugListActivity extends AppCompatActivity { medic.setAlert(7); medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime()); - medicDAO.insert(medic); + medicDAO.insertAll(medic); } List prescriptions = medicDAO.getMedics(); System.out.println(prescriptions); From bbec058a6a9dee381cfc3153f8c461c989aef42e Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 8 Mar 2022 19:48:07 +0100 Subject: [PATCH 10/31] Remove id form columns --- .../java/net/foucry/pilldroid/models/Medic.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medic.java b/app/src/main/java/net/foucry/pilldroid/models/Medic.java index f245a4b..477e699 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Medic.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Medic.java @@ -7,8 +7,7 @@ import androidx.annotation.NonNull; @Entity(tableName = "medics") public class Medic { @PrimaryKey - @NonNull private final Integer id; - private String cis; + @NonNull private String cis; private String cip13; private String name; private String administration_mode; @@ -19,9 +18,10 @@ public class Medic { private Integer alert; private Long last_update; - public Medic(@NonNull Integer id) { + +/* public Medic(@NonNull Integer id) { this.id = id; - } + }*/ public void setCis(String cis) { @@ -65,12 +65,12 @@ public void setLast_update(Long last_update) { this.last_update = last_update; } -@NonNull -Integer getId() { +//@NonNull +/*public Integer getId() { return this.id; -} +}*/ -String getCis() { +public String getCis() { return this.cis; } From 35085f19c766cdbfb68094e7bcb167c695ba76ef Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 8 Mar 2022 19:48:47 +0100 Subject: [PATCH 11/31] Change insert to insertAll. --- app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java index bf1b3fc..147d566 100644 --- a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java +++ b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java @@ -13,7 +13,7 @@ import java.util.List; @Dao public interface MedicDAO { @Insert - void insert(Medic... medics); + void insertAll(Medic... medics); @Update void update(Medic... medics); @@ -25,8 +25,8 @@ public interface MedicDAO { @Query("SELECT * FROM medics") List getMedics(); - @Query("SELECT * FROM medics WHERE id = :id") - Medic getMedicBy(Long id); +/* @Query("SELECT * FROM medics WHERE id = :id") + Medic getMedicBy(Long id);*/ @Query("SELECT * FROM medics WHERE cip13 = :cip13") Medic getMedicByCIP13(String cip13); From 9fa217d587a94209530cf6043a8401ab3f1dbfc2 Mon Sep 17 00:00:00 2001 From: jacques Date: Fri, 11 Mar 2022 21:45:43 +0100 Subject: [PATCH 12/31] Use new Medic object for both presciptions (the list of medications user take, and medications, the complete database; Need a migration between version 1 an 2 of the database schema --- .../2.json | 88 +++++++++++ .../foucry/pilldroid/DrugDetailActivity.java | 39 +++-- .../foucry/pilldroid/DrugListActivity.java | 141 +++++++++--------- .../foucry/pilldroid/PilldroidDatabase.java | 2 +- .../java/net/foucry/pilldroid/UtilDate.java | 4 +- .../net/foucry/pilldroid/dao/MedicDAO.java | 11 +- .../net/foucry/pilldroid/models/Medic.java | 60 ++++++-- 7 files changed, 241 insertions(+), 104 deletions(-) create mode 100644 app/schemas/net.foucry.pilldroid.PilldroidDatabase/2.json diff --git a/app/schemas/net.foucry.pilldroid.PilldroidDatabase/2.json b/app/schemas/net.foucry.pilldroid.PilldroidDatabase/2.json new file mode 100644 index 0000000..b18c00f --- /dev/null +++ b/app/schemas/net.foucry.pilldroid.PilldroidDatabase/2.json @@ -0,0 +1,88 @@ +{ + "formatVersion": 1, + "database": { + "version": 2, + "identityHash": "ed6d0a13273d73ba9fcec1f374251efa", + "entities": [ + { + "tableName": "medics", + "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`))", + "fields": [ + { + "fieldPath": "cis", + "columnName": "cis", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "cip13", + "columnName": "cip13", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "administration_mode", + "columnName": "administration_mode", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "presentation", + "columnName": "presentation", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "stock", + "columnName": "stock", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "take", + "columnName": "take", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "warning", + "columnName": "warning", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "alert", + "columnName": "alert", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "last_update", + "columnName": "last_update", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "cis" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "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, 'ed6d0a13273d73ba9fcec1f374251efa')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index 21061a6..bf6e138 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -17,6 +17,9 @@ import java.util.Date; import static net.foucry.pilldroid.R.id.detail_toolbar; +import net.foucry.pilldroid.dao.MedicDAO; +import net.foucry.pilldroid.models.Medic; + /** * An activity representing a single Drug detail screen. This * activity is only used narrow width devices. On tablet-size devices, @@ -27,7 +30,7 @@ public class DrugDetailActivity extends AppCompatActivity { private static final String TAG = DrugDetailActivity.class.getName(); - Drug drug; + Medic aMedic; @Override protected void onCreate(Bundle savedInstanceState) { @@ -38,10 +41,10 @@ public class DrugDetailActivity extends AppCompatActivity { /* fetching the string passed with intent using ‘extras’*/ assert bundle != null; - drug = (Drug) bundle.getSerializable("drug"); + aMedic = (Medic) bundle.getSerializable("medic"); - assert drug != null; - Log.d(TAG, "drug == " + drug); + assert aMedic != null; + Log.d(TAG, "aMedic == " + aMedic); /* fetching the string passed with intent using ‘bundle’*/ @@ -69,7 +72,7 @@ public class DrugDetailActivity extends AppCompatActivity { ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(false); - actionBar.setTitle(drug.getName()); + actionBar.setTitle(aMedic.getName()); } // savedInstanceState is non-null when there is fragment state @@ -114,9 +117,12 @@ public class DrugDetailActivity extends AppCompatActivity { private void getMDrugChanges() { Log.d(TAG, "Time to save new values"); + PilldroidDatabase prescriptions = null; DBHelper dbHelper = new DBHelper(this); + assert false; + MedicDAO medicDAO = prescriptions.getMedicDAO(); - Drug newDrug = dbHelper.getDrugByCIP13(drug.getCip13()); + Medic newMedic = medicDAO.getMedicByCIP13(aMedic.getCip13()); View stockView; View takeView; @@ -139,18 +145,19 @@ public class DrugDetailActivity extends AppCompatActivity { TextView warningTextView = warningView.findViewById(R.id.value); String warningValue = warningTextView.getText().toString(); - newDrug.setStock(Double.parseDouble(stockValue)); - newDrug.setTake(Double.parseDouble(takeValue)); - newDrug.setWarnThreshold(Integer.parseInt(warningValue)); - newDrug.setAlertThreshold(Integer.parseInt(alertValue)); - newDrug.setDateEndOfStock(); + newMedic.setStock(Double.parseDouble(stockValue)); + newMedic.setTake(Double.parseDouble(takeValue)); + newMedic.setWarning(Integer.parseInt(warningValue)); + newMedic.setAlert(Integer.parseInt(alertValue)); + newMedic.getDateEndOfStock(); - if (drug.equals(newDrug)) { - Log.d(TAG, "drug and newDrug are Equals"); + if (aMedic.equals(newMedic)) { + Log.d(TAG, "medic and newMedic are Equals"); } else { - Log.d(TAG, "drug and newDrug are NOT Equals"); - newDrug.setDateLastUpdate(new Date().getTime()); - dbHelper.updateDrug(newDrug); + Log.d(TAG, "medic and newMedic are NOT Equals"); + newMedic.setLast_update(new Date().getTime()); + medicDAO.update(newMedic); + //dbHelper.updateDrug(newDrug); } } } diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 3285b7d..897e6e5 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -10,6 +10,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; +import android.os.Parcelable; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; @@ -52,12 +53,7 @@ import net.foucry.pilldroid.models.Medic; * item details side-by-side using two vertical panes. */ public class DrugListActivity extends AppCompatActivity { - /** - * Whether or not the activity is in two-pane mode, i.e. running on a tablet - * device. - */ - - // TODO: Change DEMO/DBDEMO form static to non-static. In order to create fake data at only at launch time + // Used for dev and debug final Boolean DEMO = true; final Boolean DBDEMO = false; @@ -66,24 +62,34 @@ public class DrugListActivity extends AppCompatActivity { public final String BARCODE_CONTENT = "Barcode Content"; private ActivityResultLauncher mBarcodeScannerLauncher; + private static final String TAG = DrugListActivity.class.getName(); + private DBHelper dbHelper; + private DBDrugs dbDrug; + public PilldroidDatabase prescriptions; + public PilldroidDatabase medications; - /** - * Start tutorial - */ + private List medics; // used for prescriptions + private SimpleItemRecyclerViewAdapter mAdapter; @Override public void onStart() { super.onStart(); + medications = Room + .databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "medications") + .createFromAsset("drugs.db") + .build(); + + // remove old notification Log.d(TAG, "Remove old notification and old job"); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (nm != null) { nm.cancelAll(); } - // tutorial + // start tutorial Log.i(TAG, "Launch tutorial"); startActivity(new Intent(this, WelcomeActivity.class)); } @@ -93,37 +99,13 @@ public class DrugListActivity extends AppCompatActivity { super.onStop(); } - private static final String TAG = DrugListActivity.class.getName(); - - private DBHelper dbHelper; - private DBDrugs dbDrug; - - private List drugs; - - private SimpleItemRecyclerViewAdapter mAdapter; - - public void constructDrugsList() { - dbHelper = new DBHelper(getApplicationContext()); - - if (!(drugs == null)) { - if (!drugs.isEmpty()) { - drugs.clear(); - } - } - drugs = dbHelper.getAllDrugs(); - - View mRecyclerView = findViewById(R.id.drug_list); - assert mRecyclerView != null; - setupRecyclerView((RecyclerView) mRecyclerView); - } - @SuppressLint("NotifyDataSetChanged") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create Room database - PilldroidDatabase prescription = Room + prescriptions = Room .databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "prescriptions") .allowMainThreadQueries() .build(); @@ -147,7 +129,7 @@ public class DrugListActivity extends AppCompatActivity { } if (DEMO) { - MedicDAO medicDAO = prescription.getMedicDAO(); + MedicDAO medicDAO = prescriptions.getMedicDAO(); final int min_stock = 5; final int max_stock = 50; @@ -161,16 +143,17 @@ public class DrugListActivity extends AppCompatActivity { medic.setCis("6000001" + i); medic.setAdministration_mode("oral"); medic.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); - medic.setStock((long) intRandomExclusive(min_stock, max_stock)); - medic.setTake((long) intRandomExclusive(min_take, max_take)); + medic.setStock((double) intRandomExclusive(min_stock, max_stock)); + medic.setTake((double) intRandomExclusive(min_take, max_take)); medic.setWarning(14); medic.setAlert(7); medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime()); - medicDAO.insertAll(medic); + medicDAO.insert(medic); } - List prescriptions = medicDAO.getMedics(); + List prescriptions = medicDAO.getAllMedics(); System.out.println(prescriptions); + Log.d(TAG, "prescriptions ==" + prescriptions); /* if (dbHelper.getCount() == 0) { @@ -269,10 +252,12 @@ public class DrugListActivity extends AppCompatActivity { } // Get Drug from database - final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13); + //final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13); + MedicDAO medicationDAO = medications.getMedicDAO(); + final Medic scannedMedication = medicationDAO.getMedicByCIP13(cip13); // add Drug to prescription database - askToAddInDB(scannedDrug); + askToAddInDB(scannedMedication); } } } @@ -281,6 +266,24 @@ public class DrugListActivity extends AppCompatActivity { constructDrugsList(); } + public void constructDrugsList() { + + MedicDAO medicDAO = prescriptions.getMedicDAO(); + medics = medicDAO.getAllMedics(); + + /*dbHelper = new DBHelper(getApplicationContext()); + + if (!(drugs == null)) { + if (!drugs.isEmpty()) { + drugs.clear(); + } + } + drugs = dbHelper.getAllDrugs();*/ + + View mRecyclerView = findViewById(R.id.drug_list); + assert mRecyclerView != null; + setupRecyclerView((RecyclerView) mRecyclerView); + } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); @@ -369,8 +372,10 @@ public class DrugListActivity extends AppCompatActivity { .setPositiveButton("OK", (dialog, id) -> { String cip13 = editText.getText().toString(); - Drug aDrug = dbDrug.getDrugByCIP13(cip13); - askToAddInDB(aDrug); + MedicDAO medicationsDAO = medications.getMedicDAO(); + Medic aMedic = medicationsDAO.getMedicByCIP13(cip13); + //Medic aMedic = medications.getDrugByCIP13(cip13); + askToAddInDB(aMedic); }) .setNegativeButton("Cancel", (dialog, id) -> dialog.cancel()); @@ -401,14 +406,14 @@ public class DrugListActivity extends AppCompatActivity { * Ask if the drug found in the database should be include in the * user database * - * @param aDrug Drug- drug to be added + * @param aMedic Medic- medication to be added */ - private void askToAddInDB(Drug aDrug) { + private void askToAddInDB(Medic aMedic) { AlertDialog.Builder dlg = new AlertDialog.Builder(this); dlg.setTitle(getString(R.string.app_name)); - if (aDrug != null) { - String msg = aDrug.getName() + " " + getString(R.string.msgFound); + if (aMedic != null) { + String msg = aMedic.getName() + " " + getString(R.string.msgFound); dlg.setMessage(msg); dlg.setNegativeButton(getString(R.string.button_cancel), (dialog, which) -> { @@ -416,7 +421,7 @@ public class DrugListActivity extends AppCompatActivity { }); dlg.setPositiveButton(getString(R.string.button_ok), (dialog, which) -> { // Add Drug to DB then try to show it - addDrugToList(aDrug); + addDrugToList(aMedic); }); } else { dlg.setMessage(getString(R.string.msgNotFound)); @@ -444,18 +449,18 @@ public class DrugListActivity extends AppCompatActivity { /** * Add New drug to the user database * - * @param aDrug Drug - drug to be added + * @param aMedic Medic - medication to be added */ @SuppressWarnings("deprecation") - private void addDrugToList(Drug aDrug) { - aDrug.setDateEndOfStock(); - mAdapter.addItem(aDrug); + private void addDrugToList(Medic aMedic) { + aMedic.getDateEndOfStock(); + mAdapter.addItem(aMedic); Log.d(TAG, "Call DrugDetailActivity"); Context context = this; Intent intent = new Intent(context, DrugDetailActivity.class); - intent.putExtra("drug", aDrug); + intent.putExtra("medic", (Parcelable) aMedic); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); @@ -478,27 +483,29 @@ public class DrugListActivity extends AppCompatActivity { */ private void setupRecyclerView(@NonNull RecyclerView recyclerView) { recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext())); - mAdapter = new SimpleItemRecyclerViewAdapter(drugs); + mAdapter = new SimpleItemRecyclerViewAdapter(medics); recyclerView.setAdapter(mAdapter); } /** * SimpleItemRecyclerViewAdapter */ - public class SimpleItemRecyclerViewAdapter extends RecyclerView.Adapter { + public class SimpleItemRecyclerViewAdapter extends + RecyclerView.Adapter { - private final List mValues; + private final List mValues; - SimpleItemRecyclerViewAdapter(List items) { + SimpleItemRecyclerViewAdapter(List items) { mValues = items; } - void addItem(Drug scannedDrug) { - if (!dbHelper.isDrugExist(scannedDrug.getCip13())) { - mValues.add(scannedDrug); + void addItem(Medic scannedMedic) { + MedicDAO medicDAO = prescriptions.getMedicDAO(); + if (medicDAO.getMedicByCIP13(scannedMedic.getCip13()) == null) { + mValues.add(scannedMedic); //notifyDataSetChanged(); notifyItemInserted(mValues.size()); - dbHelper.addDrug(scannedDrug); + medicDAO.insert(scannedMedic); } else { Toast.makeText(getApplicationContext(), "already in the database", Toast.LENGTH_LONG).show(); } @@ -539,10 +546,10 @@ public class DrugListActivity extends AppCompatActivity { holder.mView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Drug drug = mValues.get(position); + Medic aMedic = mValues.get(position); Context context = v.getContext(); Intent intent = new Intent(context, DrugDetailActivity.class); - intent.putExtra("drug", drug); + intent.putExtra("medic", (Parcelable) aMedic); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); @@ -565,10 +572,10 @@ public class DrugListActivity extends AppCompatActivity { holder.mView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Drug drug = mValues.get(position); + Medic medic = mValues.get(position); Context context = v.getContext(); Intent intent = new Intent(context, DrugDetailActivity.class); - intent.putExtra("drug", drug); + intent.putExtra("medic", (Parcelable) medic); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); @@ -588,7 +595,7 @@ public class DrugListActivity extends AppCompatActivity { final TextView mContentView; final TextView mEndOfStock; final ImageView mIconView; - public Drug mItem; + public Medic mItem; ViewHolder(View view) { super(view); diff --git a/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java b/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java index 9ba304a..8cb1415 100644 --- a/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java +++ b/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java @@ -6,7 +6,7 @@ import androidx.room.RoomDatabase; import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.models.Medic; -@Database(entities = {Medic.class}, version = 1) +@Database(entities = {Medic.class}, version = 2) public abstract class PilldroidDatabase extends RoomDatabase { public abstract MedicDAO getMedicDAO(); diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index bafb822..4aa1c29 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -12,7 +12,7 @@ import java.util.Locale; /** * Created by jacques on 05/05/16. */ -class UtilDate { +public class UtilDate { private static final String TAG = UtilDate.class.getName(); @@ -21,7 +21,7 @@ class UtilDate { * @return date the same date as input but at noon (12:00:00 PM) * set date time at Noon */ - static Date dateAtNoon(Date aDate) { + public static Date dateAtNoon(Date aDate) { Log.d(TAG, "dateAtNoon " + aDate); diff --git a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java index 147d566..5d0c9e1 100644 --- a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java +++ b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java @@ -1,5 +1,7 @@ package net.foucry.pilldroid.dao; +import static net.foucry.pilldroid.UtilDate.dateAtNoon; + import androidx.room.Dao; import androidx.room.Delete; import androidx.room.Insert; @@ -8,12 +10,15 @@ import androidx.room.Update; import net.foucry.pilldroid.models.Medic; +import java.util.Calendar; +import java.util.Date; import java.util.List; @Dao public interface MedicDAO { @Insert - void insertAll(Medic... medics); + void insert(Medic... medics); + @Update void update(Medic... medics); @@ -23,7 +28,7 @@ public interface MedicDAO { @Query("SELECT * FROM medics") - List getMedics(); + List getAllMedics(); /* @Query("SELECT * FROM medics WHERE id = :id") Medic getMedicBy(Long id);*/ @@ -34,3 +39,5 @@ public interface MedicDAO { @Query("SELECT count(*) FROM medics") int getMedicCount(); } + + diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medic.java b/app/src/main/java/net/foucry/pilldroid/models/Medic.java index 477e699..6b344a3 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Medic.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Medic.java @@ -1,8 +1,13 @@ package net.foucry.pilldroid.models; +import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.PrimaryKey; -import androidx.annotation.NonNull; + +import net.foucry.pilldroid.UtilDate; + +import java.util.Calendar; +import java.util.Date; @Entity(tableName = "medics") public class Medic { @@ -12,8 +17,8 @@ public class Medic { private String name; private String administration_mode; private String presentation; - private Long stock; - private Long take; + private Double stock; + private Double take; private Integer warning; private Integer alert; private Long last_update; @@ -28,7 +33,6 @@ public class Medic { this.cis = cis; } - public void setCip13(String cip13) { this.cip13 = cip13; } @@ -37,31 +41,30 @@ public class Medic { this.name = name; } -public void setAdministration_mode(String administration_mode) { - + public void setAdministration_mode(String administration_mode) { this.administration_mode = administration_mode; -} + } -public void setPresentation(String presentation) { + public void setPresentation(String presentation) { this.presentation = presentation; } -public void setStock(Long stock) { + public void setStock(Double stock) { this.stock = stock; } -public void setTake(Long take) { + public void setTake(Double take) { this.take = take; } -public void setWarning(Integer warning) { + public void setWarning(Integer warning) { this.warning = warning; } -public void setAlert(Integer alert) { + public void setAlert(Integer alert) { this.alert = alert; } -public void setLast_update(Long last_update) { + public void setLast_update(Long last_update) { this.last_update = last_update; } @@ -70,7 +73,8 @@ public void setLast_update(Long last_update) { return this.id; }*/ -public String getCis() { +@NonNull + public String getCis() { return this.cis; } @@ -94,11 +98,11 @@ public String getCis() { return presentation; } - public Long getStock() { + public Double getStock() { return stock; } - public Long getTake() { + public Double getTake() { return take; } @@ -109,6 +113,30 @@ public String getCis() { public Long getLast_update() { return last_update; } + + public int getAlertThreshold() { + return this.alert; + } + + public int getWarnThreshold() { + return this.warning; + } + + public Date getDateEndOfStock() { + int numberDayOfTake; + if (this.getTake() > 0) { + numberDayOfTake = (int) Math.floor(this.getStock() / this.getTake()); + } else { + numberDayOfTake = 0; + } + + Date aDate = UtilDate.dateAtNoon(new Date()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(aDate); + calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake); + + return calendar.getTime(); + } } From 6bf1d82318759bd9d4a7c8d6dd043933d1f253e9 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:18:44 +0100 Subject: [PATCH 13/31] Add format string method --- app/src/main/java/net/foucry/pilldroid/Utils.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index 0db4c80..bff52ba 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -8,6 +8,7 @@ import android.util.Log; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.Locale; import java.util.Random; public class Utils { @@ -45,4 +46,12 @@ public class Utils { Random r = new Random(); return r.nextInt(max - min) +max; } + + public static String fmt(double d) + { + if(d == (long) d) + return String.format(Locale.getDefault(),"%d",(long)d); + else + return String.format("%s",d); + } } From 8728c799092650598cb51b20853993dd19efda00 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:28:11 +0100 Subject: [PATCH 14/31] Migration use Double instead of Long Migration use Float instead of Double --- .../net/foucry/pilldroid/PilldroidDatabase.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java b/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java index 8cb1415..0b11ddf 100644 --- a/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java +++ b/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java @@ -1,13 +1,24 @@ package net.foucry.pilldroid; +import androidx.room.AutoMigration; import androidx.room.Database; import androidx.room.RoomDatabase; +import androidx.room.migration.Migration; +import androidx.sqlite.db.SupportSQLiteDatabase; import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.models.Medic; -@Database(entities = {Medic.class}, version = 2) +@Database( + version = 3, + entities = {Medic.class}, + autoMigrations = { + @AutoMigration(from = 1, to = 2), + @AutoMigration(from = 2, to = 3), + }, + exportSchema = true +) public abstract class PilldroidDatabase extends RoomDatabase { - public abstract MedicDAO getMedicDAO(); + public abstract MedicDAO getMedicDAO(); } From af71f54796ff7624ea64e3af2efa8df339fcb75a Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:29:26 +0100 Subject: [PATCH 15/31] Remove unuse query optimize import --- app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java index 5d0c9e1..f91ca0d 100644 --- a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java +++ b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java @@ -19,20 +19,15 @@ public interface MedicDAO { @Insert void insert(Medic... medics); - @Update void update(Medic... medics); @Delete void delete(Medic medic); - @Query("SELECT * FROM medics") List getAllMedics(); -/* @Query("SELECT * FROM medics WHERE id = :id") - Medic getMedicBy(Long id);*/ - @Query("SELECT * FROM medics WHERE cip13 = :cip13") Medic getMedicByCIP13(String cip13); From 9d19b6dec7c5b7bf8ecba656963645f79684c5dd Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:30:54 +0100 Subject: [PATCH 16/31] Use Float instead of Double Make class serializable --- .../java/net/foucry/pilldroid/models/Medic.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medic.java b/app/src/main/java/net/foucry/pilldroid/models/Medic.java index 6b344a3..ca4dd4e 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Medic.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Medic.java @@ -6,19 +6,20 @@ import androidx.room.PrimaryKey; import net.foucry.pilldroid.UtilDate; +import java.io.Serializable; import java.util.Calendar; import java.util.Date; @Entity(tableName = "medics") -public class Medic { +public class Medic implements Serializable { @PrimaryKey @NonNull private String cis; private String cip13; private String name; private String administration_mode; private String presentation; - private Double stock; - private Double take; + private Float stock; + private Float take; private Integer warning; private Integer alert; private Long last_update; @@ -48,11 +49,11 @@ public class Medic { public void setPresentation(String presentation) { this.presentation = presentation; } - public void setStock(Double stock) { + public void setStock(Float stock) { this.stock = stock; } - public void setTake(Double take) { + public void setTake(Float take) { this.take = take; } @@ -98,11 +99,11 @@ public class Medic { return presentation; } - public Double getStock() { + public Float getStock() { return stock; } - public Double getTake() { + public Float getTake() { return take; } From 426092bbadd417a87e6bdda59d51b8bc60127482 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:32:17 +0100 Subject: [PATCH 17/31] Make DrugDetailActivity call more clear --- .../foucry/pilldroid/DrugListActivity.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 897e6e5..3b471c2 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -36,6 +36,7 @@ import androidx.room.Room; import com.google.zxing.client.android.Intents; import com.journeyapps.barcodescanner.ScanOptions; +import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -131,29 +132,31 @@ public class DrugListActivity extends AppCompatActivity { if (DEMO) { MedicDAO medicDAO = prescriptions.getMedicDAO(); - final int min_stock = 5; - final int max_stock = 50; - final int min_take = 0; - final int max_take = 3; + if (medicDAO.getMedicCount() == 0) { + final int min_stock = 5; + final int max_stock = 50; + final int min_take = 0; + final int max_take = 3; - for(int i=1; i < 11; i++) { - Medic medic = new Medic(); - medic.setName("Medicament test " + i); - medic.setCip13("340093000001" + i); - medic.setCis("6000001" + i); - medic.setAdministration_mode("oral"); - medic.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); - medic.setStock((double) intRandomExclusive(min_stock, max_stock)); - medic.setTake((double) intRandomExclusive(min_take, max_take)); - medic.setWarning(14); - medic.setAlert(7); - medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime()); + for (int i = 1; i < 9; i++) { + Medic medic = new Medic(); + medic.setName("Medicament test " + i); + medic.setCip13("340093000001" + i); + medic.setCis("6000001" + i); + medic.setAdministration_mode("oral"); + medic.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); + medic.setStock((float) intRandomExclusive(min_stock, max_stock)); + medic.setTake((float) intRandomExclusive(min_take, max_take)); + medic.setWarning(14); + medic.setAlert(7); + medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime()); - medicDAO.insert(medic); + medicDAO.insert(medic); + } + List prescriptions = medicDAO.getAllMedics(); + System.out.println(prescriptions); + Log.d(TAG, "prescriptions ==" + prescriptions); } - List prescriptions = medicDAO.getAllMedics(); - System.out.println(prescriptions); - Log.d(TAG, "prescriptions ==" + prescriptions); /* if (dbHelper.getCount() == 0) { @@ -575,7 +578,7 @@ public class DrugListActivity extends AppCompatActivity { Medic medic = mValues.get(position); Context context = v.getContext(); Intent intent = new Intent(context, DrugDetailActivity.class); - intent.putExtra("medic", (Parcelable) medic); + intent.putExtra("medic", medic); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); From 8257f5477a3273b5c506568d337e5a229582f502 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:32:57 +0100 Subject: [PATCH 18/31] Use Medic instead of Drug --- .../foucry/pilldroid/DrugDetailActivity.java | 20 ++++------ .../foucry/pilldroid/DrugDetailFragment.java | 39 +++++++++++-------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index bf6e138..bafe995 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -13,6 +13,7 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import java.io.Serializable; import java.util.Date; import static net.foucry.pilldroid.R.id.detail_toolbar; @@ -37,17 +38,10 @@ public class DrugDetailActivity extends AppCompatActivity { super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); - - /* fetching the string passed with intent using ‘extras’*/ - assert bundle != null; - aMedic = (Medic) bundle.getSerializable("medic"); - - assert aMedic != null; + aMedic = (Medic) bundle.get("medic"); Log.d(TAG, "aMedic == " + aMedic); - /* fetching the string passed with intent using ‘bundle’*/ - setContentView(R.layout.activity_drug_detail); Toolbar toolbar = findViewById(detail_toolbar); @@ -87,9 +81,11 @@ public class DrugDetailActivity extends AppCompatActivity { if (savedInstanceState == null) { // Create the detail fragment and add it to the activity // using a fragment transaction. + /*Bundle arguments = new Bundle(); + arguments.putSerializable("medic", + getIntent().getExtras());*/ Bundle arguments = new Bundle(); - arguments.putSerializable("drug", - getIntent().getSerializableExtra("drug")); + arguments.putSerializable("medic", aMedic); DrugDetailFragment fragment = new DrugDetailFragment(); fragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() @@ -145,8 +141,8 @@ public class DrugDetailActivity extends AppCompatActivity { TextView warningTextView = warningView.findViewById(R.id.value); String warningValue = warningTextView.getText().toString(); - newMedic.setStock(Double.parseDouble(stockValue)); - newMedic.setTake(Double.parseDouble(takeValue)); + newMedic.setStock(Float.parseFloat(stockValue)); + newMedic.setTake(Float.parseFloat(takeValue)); newMedic.setWarning(Integer.parseInt(warningValue)); newMedic.setAlert(Integer.parseInt(alertValue)); newMedic.getDateEndOfStock(); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java index 04a74e1..52169da 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java @@ -11,6 +11,8 @@ import androidx.fragment.app.Fragment; import com.google.android.material.appbar.CollapsingToolbarLayout; +import net.foucry.pilldroid.models.Medic; + /** * A fragment representing a single Drug detail screen. * This fragment is either contained in a {@link DrugListActivity} @@ -23,12 +25,12 @@ public class DrugDetailFragment extends Fragment { * The fragment argument representing the item ID that this fragment * represents. */ - public static final String ARG_ITEM_ID = "drug"; + public static final String ARG_ITEM_ID = "medic"; /** * The dummy content this fragment is presenting. */ - private Drug drug; + private Medic medic; /** * Mandatory empty constructor for the fragment manager to instantiate the @@ -46,13 +48,13 @@ public class DrugDetailFragment extends Fragment { // Load the dummy content specified by the fragment // arguments. In a real-world scenario, use a Loader // to load content from a content provider. - drug = (Drug) getArguments().getSerializable(ARG_ITEM_ID); + medic = (Medic) getArguments().getSerializable(ARG_ITEM_ID); Activity activity = this.getActivity(); assert activity != null; CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout); if (appBarLayout != null) { - appBarLayout.setTitle(drug.getName()); + appBarLayout.setTitle(medic.getName()); } } } @@ -69,47 +71,49 @@ public class DrugDetailFragment extends Fragment { View alertView; // Show the dummy content as text in a TextView. - if (drug != null) { + if (medic != null) { // Find each component of rootView nameView = detailView.findViewById(R.id.name_cell); TextView nameLabel = nameView.findViewById(R.id.label); TextView nameValue = nameView.findViewById(R.id.value); nameLabel.setText(R.string.drug_name_label); - nameValue.setText(drug.getName()); + nameValue.setText(medic.getName()); presentationView = detailView.findViewById(R.id.presentation_cell); TextView presentationLabel = presentationView.findViewById(R.id.label); TextView presentationValue = presentationView.findViewById(R.id.value); presentationLabel.setText(R.string.drug_presentation_label); - presentationValue.setText(drug.getPresentation()); + presentationValue.setText(medic.getPresentation()); adminModeView = detailView.findViewById(R.id.administration_cell); TextView adminModeLabel = adminModeView.findViewById(R.id.label); TextView adminModeValue = adminModeView.findViewById(R.id.value); adminModeLabel.setText(R.string.drug_administrationMode_label); - adminModeValue.setText(drug.getAdministration_mode()); + adminModeValue.setText(medic.getAdministration_mode()); stockView = detailView.findViewById(R.id.stock_cell); TextView stockLibelle = (stockView.findViewById(R.id.label)); TextView stockValue = stockView.findViewById(R.id.value); stockLibelle.setText(R.string.drug_current_stock_label); - stockValue.setText(Double.toString(drug.getStock())); + stockValue.setText(Utils.fmt(medic.getStock())); stockValue.setHint(R.string.drug_current_stock_label); stockValue.setSelectAllOnFocus(true); takeView = detailView.findViewById(R.id.take_cell); - TextView priseLabel = takeView.findViewById(R.id.label); - TextView priseValue = (takeView.findViewById(R.id.value)); - priseLabel.setText(R.string.drug_take_label); - priseValue.setText(Double.toString(drug.getTake())); - priseValue.setHint(R.string.drug_take_label); - priseValue.setSelectAllOnFocus(true); + TextView takeLabel = takeView.findViewById(R.id.label); + TextView takeValue = (takeView.findViewById(R.id.value)); + takeLabel.setText(R.string.drug_take_label); + //takeValue.setText(Double.toString(medic.getTake())); + takeValue.setText(Utils.fmt(medic.getTake())); + takeValue.setHint(R.string.drug_take_label); + takeValue.setSelectAllOnFocus(true); warningView = detailView.findViewById(R.id.warning_cell); TextView warningLibelle = warningView.findViewById(R.id.label); TextView warningValue = warningView.findViewById(R.id.value); warningLibelle.setText(R.string.drug_warningThreshold_label); - warningValue.setText(Integer.toString(drug.getWarnThreshold())); + //warningValue.setText(Integer.toString(medic.getWarnThreshold())); + warningValue.setText(Utils.fmt(medic.getWarning())); warningValue.setHint(R.string.drug_warningThreshold_label); warningValue.setSelectAllOnFocus(true); @@ -117,7 +121,8 @@ public class DrugDetailFragment extends Fragment { TextView alertLibelle = alertView.findViewById(R.id.label); TextView alertValue = alertView.findViewById(R.id.value); alertLibelle.setText(R.string.drug_alertThreshold_label); - alertValue.setText(Integer.toString(drug.getAlertThreshold())); + //alertValue.setText(Integer.toString(medic.getAlertThreshold())); + alertValue.setText(Utils.fmt(medic.getAlert())); alertValue.setHint(R.string.drug_alertThreshold_label); alertValue.setSelectAllOnFocus(true); } From 2f2c31b1c9306ff1c5cf9888cbf0af0f79dec36b Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:43:02 +0100 Subject: [PATCH 19/31] Add Migration json --- .../3.json | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 app/schemas/net.foucry.pilldroid.PilldroidDatabase/3.json diff --git a/app/schemas/net.foucry.pilldroid.PilldroidDatabase/3.json b/app/schemas/net.foucry.pilldroid.PilldroidDatabase/3.json new file mode 100644 index 0000000..1483f81 --- /dev/null +++ b/app/schemas/net.foucry.pilldroid.PilldroidDatabase/3.json @@ -0,0 +1,88 @@ +{ + "formatVersion": 1, + "database": { + "version": 3, + "identityHash": "ed6d0a13273d73ba9fcec1f374251efa", + "entities": [ + { + "tableName": "medics", + "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`))", + "fields": [ + { + "fieldPath": "cis", + "columnName": "cis", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "cip13", + "columnName": "cip13", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "administration_mode", + "columnName": "administration_mode", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "presentation", + "columnName": "presentation", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "stock", + "columnName": "stock", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "take", + "columnName": "take", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "warning", + "columnName": "warning", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "alert", + "columnName": "alert", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "last_update", + "columnName": "last_update", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "cis" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "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, 'ed6d0a13273d73ba9fcec1f374251efa')" + ] + } +} \ No newline at end of file From dc71f57a73252a62e05e8727e501a5780df62cac Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:43:30 +0100 Subject: [PATCH 20/31] optimize import and clean dead code --- .../foucry/pilldroid/DrugDetailActivity.java | 13 ++-- .../foucry/pilldroid/DrugListActivity.java | 67 ++----------------- .../foucry/pilldroid/PilldroidDatabase.java | 5 +- .../main/java/net/foucry/pilldroid/Utils.java | 30 --------- .../net/foucry/pilldroid/dao/MedicDAO.java | 4 -- .../net/foucry/pilldroid/models/Medic.java | 13 +--- 6 files changed, 11 insertions(+), 121 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index bafe995..d1ed288 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -1,5 +1,7 @@ package net.foucry.pilldroid; +import static net.foucry.pilldroid.R.id.detail_toolbar; + import android.content.Intent; import android.os.Bundle; import android.util.Log; @@ -13,14 +15,11 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; -import java.io.Serializable; -import java.util.Date; - -import static net.foucry.pilldroid.R.id.detail_toolbar; - import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.models.Medic; +import java.util.Date; + /** * An activity representing a single Drug detail screen. This * activity is only used narrow width devices. On tablet-size devices, @@ -81,9 +80,6 @@ public class DrugDetailActivity extends AppCompatActivity { if (savedInstanceState == null) { // Create the detail fragment and add it to the activity // using a fragment transaction. - /*Bundle arguments = new Bundle(); - arguments.putSerializable("medic", - getIntent().getExtras());*/ Bundle arguments = new Bundle(); arguments.putSerializable("medic", aMedic); DrugDetailFragment fragment = new DrugDetailFragment(); @@ -114,7 +110,6 @@ public class DrugDetailActivity extends AppCompatActivity { Log.d(TAG, "Time to save new values"); PilldroidDatabase prescriptions = null; - DBHelper dbHelper = new DBHelper(this); assert false; MedicDAO medicDAO = prescriptions.getMedicDAO(); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 3b471c2..75ec274 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -36,15 +36,14 @@ import androidx.room.Room; import com.google.zxing.client.android.Intents; import com.journeyapps.barcodescanner.ScanOptions; -import java.io.Serializable; +import net.foucry.pilldroid.dao.MedicDAO; +import net.foucry.pilldroid.models.Medic; + import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Locale; -import net.foucry.pilldroid.dao.MedicDAO; -import net.foucry.pilldroid.models.Medic; - /** * An activity representing a list of Drugs is activity * has different presentations for handset and tablet-size devices. On @@ -65,7 +64,6 @@ public class DrugListActivity extends AppCompatActivity { private ActivityResultLauncher mBarcodeScannerLauncher; private static final String TAG = DrugListActivity.class.getName(); - private DBHelper dbHelper; private DBDrugs dbDrug; public PilldroidDatabase prescriptions; public PilldroidDatabase medications; @@ -114,7 +112,7 @@ public class DrugListActivity extends AppCompatActivity { // Set view content setContentView(R.layout.activity_drug_list); - dbHelper = new DBHelper(this); + DBHelper dbHelper = new DBHelper(this); dbDrug = new DBDrugs(this); Toolbar toolbar = findViewById(R.id.toolbar); @@ -157,49 +155,6 @@ public class DrugListActivity extends AppCompatActivity { System.out.println(prescriptions); Log.d(TAG, "prescriptions ==" + prescriptions); } -/* - if (dbHelper.getCount() == 0) { - - // String cis, String cip13, String nom, String mode_administration, - // String presentation,double stock, double prise, int warn, int alert - - // Limit for randoms generator - final int min_stock = 5; - final int max_stock = 50; - final int min_prise = 0; - final int max_prise = 3; - - dbHelper.addDrug(new Drug("60000011", "3400930000011", "Médicament test 01", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000012", "3400930000012", "Médicament test 02", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000013", "3400930000013", "Médicament test 03", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000014", "3400930000014", "Médicament test 04", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000015", "3400930000015", "Médicament test 05", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000016", "3400930000016", "Médicament test 06", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000017", "3400930000017", "Médicament test 07", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000018", "3400930000018", "Médicament test 08", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000019", "3400930000019", "Médicament test 09", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - dbHelper.addDrug(new Drug("60000010", "3400930000010", "Médicament test 10", "orale", - "plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)", - intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime())); - }*/ } mBarcodeScannerLauncher = registerForActivityResult(new PilldroidScanContract(), @@ -274,15 +229,6 @@ public class DrugListActivity extends AppCompatActivity { MedicDAO medicDAO = prescriptions.getMedicDAO(); medics = medicDAO.getAllMedics(); - /*dbHelper = new DBHelper(getApplicationContext()); - - if (!(drugs == null)) { - if (!drugs.isEmpty()) { - drugs.clear(); - } - } - drugs = dbHelper.getAllDrugs();*/ - View mRecyclerView = findViewById(R.id.drug_list); assert mRecyclerView != null; setupRecyclerView((RecyclerView) mRecyclerView); @@ -312,11 +258,6 @@ public class DrugListActivity extends AppCompatActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - /*if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) { - // This is important, otherwise the result will not be passed to the fragment - super.onActivityResult(requestCode, resultCode, data); - return; - }*/ if (requestCode == CUSTOMIZED_REQUEST_CODE) { if (BuildConfig.DEBUG) { Toast.makeText(this, "REQUEST_CODE = " + requestCode + diff --git a/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java b/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java index 0b11ddf..359f731 100644 --- a/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java +++ b/app/src/main/java/net/foucry/pilldroid/PilldroidDatabase.java @@ -3,8 +3,6 @@ package net.foucry.pilldroid; import androidx.room.AutoMigration; import androidx.room.Database; import androidx.room.RoomDatabase; -import androidx.room.migration.Migration; -import androidx.sqlite.db.SupportSQLiteDatabase; import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.models.Medic; @@ -15,8 +13,7 @@ import net.foucry.pilldroid.models.Medic; autoMigrations = { @AutoMigration(from = 1, to = 2), @AutoMigration(from = 2, to = 3), - }, - exportSchema = true + } ) public abstract class PilldroidDatabase extends RoomDatabase { diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index bff52ba..9cf2125 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -1,41 +1,11 @@ package net.foucry.pilldroid; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.util.Locale; import java.util.Random; public class Utils { private static final String TAG = Utils.class.getName(); - public static final int SELECT_BARCODE_REQUEST = 2; - public static final int BARCODE_SCAN = 3; - - public static void CopyStream(InputStream is, OutputStream os) - { - final int buffer_size=1024; - try - { - byte[] bytes=new byte[buffer_size]; - for(;;) - { - int count=is.read(bytes, 0, buffer_size); - if(count==-1) - break; - os.write(bytes, 0, count); - } - } catch (IOException e) { - e.printStackTrace(); - } - - } - /** * Return a random number between twovalues - use to gənerate a false demo DB * @param min minimal value accepted diff --git a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java index f91ca0d..6b1fb0a 100644 --- a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java +++ b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java @@ -1,7 +1,5 @@ package net.foucry.pilldroid.dao; -import static net.foucry.pilldroid.UtilDate.dateAtNoon; - import androidx.room.Dao; import androidx.room.Delete; import androidx.room.Insert; @@ -10,8 +8,6 @@ import androidx.room.Update; import net.foucry.pilldroid.models.Medic; -import java.util.Calendar; -import java.util.Date; import java.util.List; @Dao diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medic.java b/app/src/main/java/net/foucry/pilldroid/models/Medic.java index ca4dd4e..cb66220 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Medic.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Medic.java @@ -25,11 +25,7 @@ public class Medic implements Serializable { private Long last_update; -/* public Medic(@NonNull Integer id) { - this.id = id; - }*/ - - public void setCis(String cis) + public void setCis(@NonNull String cis) { this.cis = cis; } @@ -69,12 +65,7 @@ public class Medic implements Serializable { this.last_update = last_update; } -//@NonNull -/*public Integer getId() { - return this.id; -}*/ - -@NonNull + @NonNull public String getCis() { return this.cis; } From 0304eb27b16424537a938b0c5257b47b0bb77eff Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 12:47:10 +0100 Subject: [PATCH 21/31] Renamed according to the java class Do some cleaning --- .../{activity_custom_scanner.xml => CustomScannerActivty.xml} | 0 .../{activity_drug_detail.xml => DrugDetailActivity.xml} | 0 .../layout/{activity_drug_list.xml => DrugListActivity.xml} | 3 ++- 3 files changed, 2 insertions(+), 1 deletion(-) rename app/src/main/res/layout/{activity_custom_scanner.xml => CustomScannerActivty.xml} (100%) rename app/src/main/res/layout/{activity_drug_detail.xml => DrugDetailActivity.xml} (100%) rename app/src/main/res/layout/{activity_drug_list.xml => DrugListActivity.xml} (95%) diff --git a/app/src/main/res/layout/activity_custom_scanner.xml b/app/src/main/res/layout/CustomScannerActivty.xml similarity index 100% rename from app/src/main/res/layout/activity_custom_scanner.xml rename to app/src/main/res/layout/CustomScannerActivty.xml diff --git a/app/src/main/res/layout/activity_drug_detail.xml b/app/src/main/res/layout/DrugDetailActivity.xml similarity index 100% rename from app/src/main/res/layout/activity_drug_detail.xml rename to app/src/main/res/layout/DrugDetailActivity.xml diff --git a/app/src/main/res/layout/activity_drug_list.xml b/app/src/main/res/layout/DrugListActivity.xml similarity index 95% rename from app/src/main/res/layout/activity_drug_list.xml rename to app/src/main/res/layout/DrugListActivity.xml index 6ded56d..0664590 100644 --- a/app/src/main/res/layout/activity_drug_list.xml +++ b/app/src/main/res/layout/DrugListActivity.xml @@ -50,5 +50,6 @@ app:backgroundTint="@android:color/darker_gray" app:fabCustomSize="60dp" app:maxImageSize="60dp" - android:contentDescription="@string/add_button" /> + android:contentDescription="@string/add_button" + tools:ignore="OnClick" /> From da79ff480ed160a4787e18cf5eefaab6c52a2070 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 12:47:52 +0100 Subject: [PATCH 22/31] Optimize according to IDE --- app/src/main/AndroidManifest.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a70a432..dca5e89 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,7 +18,6 @@ android:allowBackup="true"> From 24ec947239e7a207ddf6f7930371b04d248d29cd Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 12:49:06 +0100 Subject: [PATCH 23/31] Change resource name --- .../pilldroid/CustomScannerActivity.java | 2 +- .../foucry/pilldroid/DrugDetailActivity.java | 2 +- .../foucry/pilldroid/DrugDetailContract.java | 1 - .../foucry/pilldroid/DrugListActivity.java | 29 ++----------------- 4 files changed, 5 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java index b3ff7c1..5a55f4e 100644 --- a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java @@ -38,7 +38,7 @@ public class CustomScannerActivity extends Activity implements DecoratedBarcodeV public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_custom_scanner); + setContentView(R.layout.CustomScannerActivty); //barcodeScannerView.setTorchListener(this); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index d1ed288..b205f36 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -41,7 +41,7 @@ public class DrugDetailActivity extends AppCompatActivity { aMedic = (Medic) bundle.get("medic"); Log.d(TAG, "aMedic == " + aMedic); - setContentView(R.layout.activity_drug_detail); + setContentView(R.layout.DrugDetailActivity); Toolbar toolbar = findViewById(detail_toolbar); if (toolbar != null) { diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java index 7059816..1dcef08 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java @@ -3,7 +3,6 @@ package net.foucry.pilldroid; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.os.Bundle; import androidx.activity.result.contract.ActivityResultContract; import androidx.annotation.NonNull; diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 75ec274..dad6084 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -55,7 +55,6 @@ import java.util.Locale; public class DrugListActivity extends AppCompatActivity { // Used for dev and debug final Boolean DEMO = true; - final Boolean DBDEMO = false; public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff; public final String BARCODE_FORMAT_NAME = "Barcode Format name"; @@ -64,7 +63,6 @@ public class DrugListActivity extends AppCompatActivity { private ActivityResultLauncher mBarcodeScannerLauncher; private static final String TAG = DrugListActivity.class.getName(); - private DBDrugs dbDrug; public PilldroidDatabase prescriptions; public PilldroidDatabase medications; @@ -110,10 +108,7 @@ public class DrugListActivity extends AppCompatActivity { .build(); // Set view content - setContentView(R.layout.activity_drug_list); - - DBHelper dbHelper = new DBHelper(this); - dbDrug = new DBDrugs(this); + setContentView(R.layout.DrugListActivity); Toolbar toolbar = findViewById(R.id.toolbar); @@ -122,11 +117,6 @@ public class DrugListActivity extends AppCompatActivity { toolbar.setTitle(getTitle()); } - // Added to drop database each the app is launch. - if (DBDEMO) { - dbHelper.dropDrug(); - } - if (DEMO) { MedicDAO medicDAO = prescriptions.getMedicDAO(); @@ -190,7 +180,6 @@ public class DrugListActivity extends AppCompatActivity { String cip13; // Handle successful scan - Log.d(TAG, "formatName = " + bundle.getString(BARCODE_FORMAT_NAME)); switch (bundle.getString(BARCODE_FORMAT_NAME)) { @@ -198,9 +187,6 @@ public class DrugListActivity extends AppCompatActivity { case "EAN_13": //CODE_128 || EAN 13 cip13 = bundle.getString(BARCODE_CONTENT); break; - case "CODE_39": - cip13 = dbDrug.getCIP13FromCIP7(bundle.getString(BARCODE_CONTENT)); - break; case "DATA_MATRIX": cip13 = bundle.getString(BARCODE_CONTENT).substring(4, 17); break; @@ -210,7 +196,6 @@ public class DrugListActivity extends AppCompatActivity { } // Get Drug from database - //final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13); MedicDAO medicationDAO = medications.getMedicDAO(); final Medic scannedMedication = medicationDAO.getMedicByCIP13(cip13); @@ -258,14 +243,7 @@ public class DrugListActivity extends AppCompatActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == CUSTOMIZED_REQUEST_CODE) { - if (BuildConfig.DEBUG) { - Toast.makeText(this, "REQUEST_CODE = " + requestCode + - "RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show(); - } - Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode); - constructDrugsList(); - } + constructDrugsList(); } public void onPause() { @@ -283,8 +261,7 @@ public class DrugListActivity extends AppCompatActivity { public void onButtonClick() { Log.d(TAG, "add medication"); ScanOptions options = new ScanOptions(); - options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_39, - ScanOptions.CODE_128); + options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_128); options.setCameraId(0); // Use a specific camera of the device options.setBeepEnabled(true); options.setBarcodeImageEnabled(true); From 0a4d2c0517ac109f09c22d24162ad80f3dd7bdaa Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 12:49:22 +0100 Subject: [PATCH 24/31] Fix typos --- fastlane/metadata/android/en-US/full_description.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastlane/metadata/android/en-US/full_description.txt b/fastlane/metadata/android/en-US/full_description.txt index ef3fa4b..8c5bcde 100644 --- a/fastlane/metadata/android/en-US/full_description.txt +++ b/fastlane/metadata/android/en-US/full_description.txt @@ -1,9 +1,9 @@ <<<<<<< HEAD -Pilldroid is a theorical medics manager. It for French people +Pilldroid is a theoretical medics manager. It for French people only. Why for french people only? -

Pilldroid use a medics databases that come from French governement website, with +

Pilldroid use a medics databases that come from French government website, with Pilldroid is a theoretical medics manager. It for French people only. From d1e04bab7a93b80479855f2ee115d6ee7b90c7bb Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 12:49:46 +0100 Subject: [PATCH 25/31] Use modern call for resource --- .../net/foucry/pilldroid/SimpleDividerItemDecoration.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java b/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java index ea424b5..e6fa4c4 100644 --- a/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java +++ b/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java @@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable; import android.view.View; import androidx.annotation.NonNull; +import androidx.appcompat.content.res.AppCompatResources; import androidx.recyclerview.widget.RecyclerView; /** @@ -15,7 +16,8 @@ public class SimpleDividerItemDecoration extends RecyclerView.ItemDecoration { private final Drawable mDivider; SimpleDividerItemDecoration(Context context) { - mDivider = context.getDrawable(R.drawable.line_divider); + //mDivider = context.getDrawable(R.drawable.line_divider); + mDivider = AppCompatResources.getDrawable(context, R.drawable.line_divider); } @Override From 9f816764b89989ac4bbc93b3ceccc17e579d9870 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 12:50:13 +0100 Subject: [PATCH 26/31] fix typos --- app/src/main/java/net/foucry/pilldroid/UtilDate.java | 4 ++-- app/src/main/java/net/foucry/pilldroid/Utils.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index 4aa1c29..fe7075a 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -41,7 +41,7 @@ public class UtilDate { * @param days number of days to remove to the ate * @param date date before day removing * @return date - * Substract days to date and return a new date + * Subtract days to date and return a new date */ static Date removeDaysToDate(int days, Date date) { Calendar calendar = Calendar.getInstance(); @@ -90,7 +90,7 @@ public class UtilDate { } /** - * Convert dateInMilliseconds into string formated date + * Convert dateInMilliseconds into string formatted date * @param dateInMilliseconds long * @return formatted Date String */ diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index 9cf2125..647d793 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -7,7 +7,7 @@ public class Utils { private static final String TAG = Utils.class.getName(); /** - * Return a random number between twovalues - use to gənerate a false demo DB + * Return a random number between two values - use to generate a false demo DB * @param min minimal value accepted * @param max maximum value accepted * @return int random number From 6390b7977c861829764d9c444880bb80e71e76d7 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 12:50:40 +0100 Subject: [PATCH 27/31] change file names --- app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java | 2 +- .../res/layout/{activity_welcome.xml => WelcomeActivity.xml} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/src/main/res/layout/{activity_welcome.xml => WelcomeActivity.xml} (97%) diff --git a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java index fe0946a..3ee81f3 100644 --- a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java @@ -45,7 +45,7 @@ public class WelcomeActivity extends AppCompatActivity { } prefManager.setFirstTimeLaunch(false); - setContentView(R.layout.activity_welcome); + setContentView(R.layout.WelcomeActivity); setFullScreen(); diff --git a/app/src/main/res/layout/activity_welcome.xml b/app/src/main/res/layout/WelcomeActivity.xml similarity index 97% rename from app/src/main/res/layout/activity_welcome.xml rename to app/src/main/res/layout/WelcomeActivity.xml index 9819b77..6245fe4 100644 --- a/app/src/main/res/layout/activity_welcome.xml +++ b/app/src/main/res/layout/WelcomeActivity.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:showIn="@layout/activity_welcome"> + tools:showIn="@layout/WelcomeActivity"> Date: Sun, 13 Mar 2022 18:06:27 +0100 Subject: [PATCH 28/31] rename layout, names must content only [a-z][0-9] and underscore --- .../main/java/net/foucry/pilldroid/CustomScannerActivity.java | 2 +- app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java | 2 +- app/src/main/java/net/foucry/pilldroid/DrugListActivity.java | 2 +- app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java | 2 +- .../{CustomScannerActivty.xml => custom_scanner_activty.xml} | 0 .../layout/{DrugDetailActivity.xml => drug_detail_activity.xml} | 0 .../res/layout/{DrugListActivity.xml => drug_list_activity.xml} | 0 .../res/layout/{WelcomeActivity.xml => welcome_activity.xml} | 0 8 files changed, 4 insertions(+), 4 deletions(-) rename app/src/main/res/layout/{CustomScannerActivty.xml => custom_scanner_activty.xml} (100%) rename app/src/main/res/layout/{DrugDetailActivity.xml => drug_detail_activity.xml} (100%) rename app/src/main/res/layout/{DrugListActivity.xml => drug_list_activity.xml} (100%) rename app/src/main/res/layout/{WelcomeActivity.xml => welcome_activity.xml} (100%) diff --git a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java index 5a55f4e..5d08003 100644 --- a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java @@ -38,7 +38,7 @@ public class CustomScannerActivity extends Activity implements DecoratedBarcodeV public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.CustomScannerActivty); + setContentView(R.layout.custom_scanner_activty); //barcodeScannerView.setTorchListener(this); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index b205f36..d5315ef 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -41,7 +41,7 @@ public class DrugDetailActivity extends AppCompatActivity { aMedic = (Medic) bundle.get("medic"); Log.d(TAG, "aMedic == " + aMedic); - setContentView(R.layout.DrugDetailActivity); + setContentView(R.layout.drug_detail_activity); Toolbar toolbar = findViewById(detail_toolbar); if (toolbar != null) { diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index dad6084..06d2523 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -108,7 +108,7 @@ public class DrugListActivity extends AppCompatActivity { .build(); // Set view content - setContentView(R.layout.DrugListActivity); + setContentView(R.layout.drug_list_activity); Toolbar toolbar = findViewById(R.id.toolbar); diff --git a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java index 3ee81f3..1816f83 100644 --- a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java @@ -45,7 +45,7 @@ public class WelcomeActivity extends AppCompatActivity { } prefManager.setFirstTimeLaunch(false); - setContentView(R.layout.WelcomeActivity); + setContentView(R.layout.welcome_activity); setFullScreen(); diff --git a/app/src/main/res/layout/CustomScannerActivty.xml b/app/src/main/res/layout/custom_scanner_activty.xml similarity index 100% rename from app/src/main/res/layout/CustomScannerActivty.xml rename to app/src/main/res/layout/custom_scanner_activty.xml diff --git a/app/src/main/res/layout/DrugDetailActivity.xml b/app/src/main/res/layout/drug_detail_activity.xml similarity index 100% rename from app/src/main/res/layout/DrugDetailActivity.xml rename to app/src/main/res/layout/drug_detail_activity.xml diff --git a/app/src/main/res/layout/DrugListActivity.xml b/app/src/main/res/layout/drug_list_activity.xml similarity index 100% rename from app/src/main/res/layout/DrugListActivity.xml rename to app/src/main/res/layout/drug_list_activity.xml diff --git a/app/src/main/res/layout/WelcomeActivity.xml b/app/src/main/res/layout/welcome_activity.xml similarity index 100% rename from app/src/main/res/layout/WelcomeActivity.xml rename to app/src/main/res/layout/welcome_activity.xml From 10f2bf2c34b18025b588844efd5f15b4a4cf14b4 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 19:50:18 +0100 Subject: [PATCH 29/31] Add old prescriptions database migration to room presciptions database Fix some annoying warning about gradle 8.0 --- .../foucry/pilldroid/DrugListActivity.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 06d2523..0b57879 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -79,6 +79,36 @@ public class DrugListActivity extends AppCompatActivity { .createFromAsset("drugs.db") .build(); + // Manually migrate old database to room + MedicDAO medicDAO = prescriptions.getMedicDAO(); + DBHelper dbHelper = new DBHelper(this); + if (dbHelper.getCount() !=0) { + List drugs=dbHelper.getAllDrugs(); + + for (int count=1; count==dbHelper.getCount(); count++) { + Drug drug = drugs.get(count); + Medic medic = new Medic(); + + if(medicDAO.getMedicByCIP13(drug.getCip13()) == null) { + medic.setName(drug.getName()); + medic.setCip13(drug.getCip13()); + medic.setCis(drug.getCis()); + medic.setPresentation(drug.getPresentation()); + medic.setAdministration_mode(drug.getAdministration_mode()); + medic.setStock((float) drug.getStock()); + medic.setTake((float) drug.getTake()); + medic.setWarning(drug.getWarnThreshold()); + medic.setAlert(drug.getAlertThreshold()); + medic.setLast_update(drug.getDateLastUpdate()); + + medicDAO.insert(medic); + } + else { + Log.i(TAG, "Already in the database"); + } + } + dbHelper.dropDrug(); + } // remove old notification Log.d(TAG, "Remove old notification and old job"); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); @@ -226,7 +256,18 @@ public class DrugListActivity extends AppCompatActivity { } public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { + int id = item.getItemId(); + if (id == R.id.about) { + startActivity(new Intent(this, About.class)); + return true; + } else if (id == R.id.help) { + PrefManager prefManager = new PrefManager(this); + prefManager.setFirstTimeLaunch(true); + + startActivity(new Intent(this, WelcomeActivity.class)); + return true; + } + /*switch (item.getItemId()) { case R.id.about: startActivity(new Intent(this, About.class)); return true; @@ -236,7 +277,7 @@ public class DrugListActivity extends AppCompatActivity { startActivity(new Intent(this, WelcomeActivity.class)); return true; - } + }*/ return super.onOptionsItemSelected(item); } From b260220039bd2518cbc97c3995e693994bc13f83 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 13 Mar 2022 19:51:26 +0100 Subject: [PATCH 30/31] use correct filename --- app/src/main/res/layout/welcome_activity.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/res/layout/welcome_activity.xml b/app/src/main/res/layout/welcome_activity.xml index 6245fe4..2004232 100644 --- a/app/src/main/res/layout/welcome_activity.xml +++ b/app/src/main/res/layout/welcome_activity.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:showIn="@layout/WelcomeActivity"> + tools:showIn="@layout/welcome_activity"> - \ No newline at end of file From 3754b3bb22211399b4b5619eb2f3a3d8d617ab84 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 14 Mar 2022 10:19:55 +0100 Subject: [PATCH 31/31] Fix for loop and small bug in onButtonClick --- .../net/foucry/pilldroid/DrugListActivity.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 0b57879..3df9b96 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -54,7 +54,7 @@ import java.util.Locale; */ public class DrugListActivity extends AppCompatActivity { // Used for dev and debug - final Boolean DEMO = true; + final Boolean DEMO = false; public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff; public final String BARCODE_FORMAT_NAME = "Barcode Format name"; @@ -84,8 +84,7 @@ public class DrugListActivity extends AppCompatActivity { DBHelper dbHelper = new DBHelper(this); if (dbHelper.getCount() !=0) { List drugs=dbHelper.getAllDrugs(); - - for (int count=1; count==dbHelper.getCount(); count++) { + for (int count=0; count < dbHelper.getCount(); count++) { Drug drug = drugs.get(count); Medic medic = new Medic(); @@ -267,17 +266,6 @@ public class DrugListActivity extends AppCompatActivity { startActivity(new Intent(this, WelcomeActivity.class)); return true; } - /*switch (item.getItemId()) { - case R.id.about: - startActivity(new Intent(this, About.class)); - return true; - case R.id.help: - PrefManager prefManager = new PrefManager(this); - prefManager.setFirstTimeLaunch(true); - - startActivity(new Intent(this, WelcomeActivity.class)); - return true; - }*/ return super.onOptionsItemSelected(item); } @@ -299,7 +287,7 @@ public class DrugListActivity extends AppCompatActivity { // Launch scan - public void onButtonClick() { + public void onButtonClick(View v) { Log.d(TAG, "add medication"); ScanOptions options = new ScanOptions(); options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_128);