diff --git a/app/build.gradle b/app/build.gradle
index 9b82228..55b2ec4 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -18,6 +18,7 @@ android {
targetSdkVersion defaultTargetSdkVersion
versionCode generateVersionCode() // 190010203
versionName generateVersionName() // 1.2.3-SNAPSHOT
+ multiDexEnabled true
}
buildTypes {
@@ -29,6 +30,8 @@ android {
productFlavors {
}
compileOptions {
+ coreLibraryDesugaringEnabled true
+
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
@@ -45,6 +48,7 @@ android {
repositories {
jcenter()
+ mavenCentral()
}
sourceSets {
main {
@@ -67,6 +71,8 @@ dependencies {
implementation 'androidx.core:core:1.3.2'
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
+
+ coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
private Integer generateVersionCode() {
diff --git a/app/src/androidTest/java/net/foucry/pilldroid/ApplicationTest.java b/app/src/androidTest/java/net/foucry/pilldroid/ApplicationTest.java
index 3129e2c..f33f8bd 100644
--- a/app/src/androidTest/java/net/foucry/pilldroid/ApplicationTest.java
+++ b/app/src/androidTest/java/net/foucry/pilldroid/ApplicationTest.java
@@ -3,6 +3,7 @@ package net.foucry.pilldroid;
import android.app.Application;
import android.test.ApplicationTestCase;
+
/**
* Testing Fundamentals
*/
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9bcd77d..372171f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -16,7 +16,7 @@
android:theme="@style/AppTheme"
android:allowBackup="true">
@@ -25,27 +25,27 @@
+ android:value="net.foucry.pilldroid.DrugListActivity" />
+ android:value="net.foucry.pilldroid.DrugListActivity" />
medicaments = dbHelper.getAllDrugs();
+ List drugs = dbHelper.getAllDrugs();
- Medicament firstMedicament = null;
+ Drug firstDrug = null;
try {
- firstMedicament = medicaments.get(0);
+ firstDrug = drugs.get(0);
}
catch (Exception e){
Log.e(TAG, e.toString());
e.printStackTrace();
}
- if (firstMedicament != null) {
- if (firstMedicament.getPrise() != 0) {
- if(firstMedicament.getStock() < firstMedicament.getAlertThreshold()) {
+ if (firstDrug != null) {
+ if (firstDrug.getTake() != 0) {
+ if(firstDrug.getStock() < firstDrug.getAlertThreshold()) {
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
@@ -68,7 +68,7 @@ public class AlarmReceiver extends BroadcastReceiver {
notificationManager.notify(notificationId, builder.build());
} else
{
- double dummy = (firstMedicament.getStock() - firstMedicament.getAlertThreshold());
+ double dummy = (firstDrug.getStock() - firstDrug.getAlertThreshold());
Log.d(TAG, "no notification scheduled " + dummy);
}
}
diff --git a/app/src/main/java/net/foucry/pilldroid/DBMedoc.java b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java
similarity index 64%
rename from app/src/main/java/net/foucry/pilldroid/DBMedoc.java
rename to app/src/main/java/net/foucry/pilldroid/DBDrugs.java
index 76b30e3..832e7b3 100644
--- a/app/src/main/java/net/foucry/pilldroid/DBMedoc.java
+++ b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java
@@ -16,37 +16,51 @@ import java.io.OutputStream;
/**
* Created by jfoucry on 5/25/16.
*/
-class DBMedoc extends SQLiteOpenHelper {
+class DBDrugs extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
- private static final String dbName = "medicaments.db";
+ private static final String dbName = "drugs.db";
private final Context myContext;
private final SQLiteDatabase myDataBase = null;
- private static final String TABLE_NAME = "medicaments";
- private static final String MEDOC_CIS = "cis";
- private static final String MEDOC_CIP13 = "cip13";
- private static final String MEDOC_ADMIN = "mode_administration";
- private static final String MEDOC_NOM = "nom";
- private static final String MEDOC_PRES = "presentation";
+ private static final String TABLE_NAME = "drugs";
+ private static final String DRUG_CIS = "cis";
+ private static final String DRUG_CIP13 = "cip13";
+ private static final String DRUG_ADMIN = "administration_mode";
+ private static final String DRUG_NAME = "name";
+ private static final String DRUG_PRES = "presentation";
- private static final String[] COLUMNS_NAMES = {MEDOC_CIS, MEDOC_CIP13, MEDOC_ADMIN, MEDOC_NOM, MEDOC_PRES};
+ private static final String[] COLUMNS_NAMES = {DRUG_CIS, DRUG_CIP13, DRUG_ADMIN, DRUG_NAME, DRUG_PRES};
- private static final String TAG = DBMedoc.class.getName();
+ private static final String TAG = DBDrugs.class.getName();
- DBMedoc(Context context) {
+ DBDrugs(Context context) {
super(context, dbName, null, DATABASE_VERSION);
this.myContext = context;
}
+ public boolean isDBFileExist(File database)
+ {
+ try {
+ myContext.getDatabasePath(String.valueOf(database));
+ } catch (final Exception exception) {
+ return false;
+ }
+ return true;
+/* if (myContext.getDatabasePath(String.valueOf(database)) != null)
+ return true;
+ else
+ return false;*/
+ }
+
@Override
public synchronized SQLiteDatabase getWritableDatabase() {
File dbFile = myContext.getDatabasePath(dbName);
- if (!dbFile.exists()) {
+ if (!isDBFileExist(dbFile)) {
copyDatabase(dbFile.getPath());
}
@@ -57,8 +71,6 @@ class DBMedoc extends SQLiteOpenHelper {
public synchronized SQLiteDatabase getReadableDatabase() {
File dbFile = myContext.getDatabasePath(dbName);
- //if (dbFile.exists()) return super.getReadableDatabase();
-
PrefManager prefManager = new PrefManager(myContext);
int oldVersion = prefManager.getDatabaseVersion();
@@ -95,13 +107,6 @@ class DBMedoc extends SQLiteOpenHelper {
}
}
-/* void openDatabase() throws SQLiteException {
- Log.e(TAG, "openDatabase called");
- String myPath = myContext.getDatabasePath(dbName).getPath();
-
- myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
- }*/
-
@Override
public synchronized void close() {
if (myDataBase != null) {
@@ -113,9 +118,9 @@ class DBMedoc extends SQLiteOpenHelper {
* Lookup in the DB for a record corresponding to cip13
*
* @param cip13 string representing the object we're looking for
- * @return return a medicament object
+ * @return return a drug object
*/
- Medicament getMedocByCIP13(String cip13) {
+ Drug getDrugByCIP13(String cip13) {
Log.e(TAG, "CIP13 - " + cip13);
SQLiteDatabase db = this.getReadableDatabase();
@@ -134,28 +139,28 @@ class DBMedoc extends SQLiteOpenHelper {
cursor.moveToFirst();
- // Build medicament object
- Medicament medicament = new Medicament();
- // medicament.setId(Integer.parseInt(cursor.getString(0)));
- medicament.setCis(cursor.getString(0));
- medicament.setCip13(cursor.getString(1));
- medicament.setMode_administration(cursor.getString(2));
- medicament.setNom(cursor.getString(3));
- medicament.setPresentation(cursor.getString(4));
+ // Build drug object
+ Drug drug = new Drug();
+ // drug.setId(Integer.parseInt(cursor.getString(0)));
+ drug.setCis(cursor.getString(0));
+ drug.setCip13(cursor.getString(1));
+ drug.setAdministration_mode(cursor.getString(2));
+ drug.setNama(cursor.getString(3));
+ drug.setPresentation(cursor.getString(4));
// Set default values
- medicament.setStock(0);
- medicament.setPrise(0);
- medicament.setWarnThreshold(14);
- medicament.setAlertThreshold(7);
+ drug.setStock(0);
+ drug.setTake(0);
+ drug.setWarnThreshold(14);
+ drug.setAlertThreshold(7);
// Log
- Log.d(TAG, "getDrug(" + cip13 + ")" + medicament.toString());
+ Log.d(TAG, "getDrug(" + cip13 + ")" + drug.toString());
- // Return medicament
+ // Return drug
cursor.close();
- return medicament;
+ return drug;
} else
return null;
}
diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java
index 09d65ed..1ea8d26 100644
--- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java
+++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java
@@ -6,12 +6,14 @@ import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
+import android.os.Build;
+import android.text.format.DateUtils;
import android.util.Log;
+import androidx.annotation.RequiresApi;
+
import java.util.ArrayList;
import java.util.Comparator;
-import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
/**
@@ -19,25 +21,26 @@ import java.util.List;
*/
+
class DBHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
- private static final ThreadLocal DATABASE_NAME = ThreadLocal.withInitial(() -> "ordonnance.db");
+ private static final String DATABASE_NAME = "prescription.db";
private static final String TABLE_DRUG = "drug";
private static final String KEY_ID = "id";
private static final String KEY_CIS = "cis";
private static final String KEY_CIP13 = "cip13";
- private static final String KEY_NAME = "nom";
- private static final String KEY_ADMIN = "mode_administration";
+ private static final String KEY_NAME = "name";
+ private static final String KEY_ADMIN = "administration_mode";
private static final String KEY_PRES = "presentation";
private static final String KEY_STOCK = "stock";
- private static final String KEY_PRISE = "prise";
+ private static final String KEY_PRISE = "take";
private static final String KEY_SEUIL_WARN = "warning";
- private static final String KEY_SEUIL_ALERT = "alerte";
+ private static final String KEY_SEUIL_ALERT = "alert";
private static final String KEY_LAST_UPDATE = "last_update";
- final List medicaments = new ArrayList<>();
+ final List drugs = new ArrayList<>();
private static final String TAG = DBHelper.class.getName();
@@ -45,7 +48,7 @@ class DBHelper extends SQLiteOpenHelper {
KEY_SEUIL_WARN, KEY_SEUIL_ALERT, KEY_LAST_UPDATE};
DBHelper(Context context) {
- super(context, DATABASE_NAME.get(), null, DATABASE_VERSION);
+ super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
@@ -54,13 +57,13 @@ class DBHelper extends SQLiteOpenHelper {
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"cis TEXT, " +
"cip13 TEXT, " +
- "nom TEXT, " +
- "mode_administration TEXT, " +
+ "name TEXT, " +
+ "administration_mode TEXT, " +
"presentation TEXT, " +
"stock REAL, " +
- "prise REAL, " +
+ "take REAL, " +
"warning INT, " +
- "alerte INT, " +
+ "alert INT, " +
"last_update LONG)";
db.execSQL(CREATE_DRUG_TABLE);
@@ -87,30 +90,30 @@ class DBHelper extends SQLiteOpenHelper {
}
/**
- * Split medicament values into database record and record it to the DB
- * @param medicament the medicament object to be saved
+ * Split drug values into database record and record it to the DB
+ * @param drug the drug object to be saved
*/
- void addDrug(Medicament medicament) {
+ void addDrug(Drug drug) {
// Logging
- Log.d(TAG, medicament.toString());
+ Log.d(TAG, drug.toString());
// Get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();
// Create ContentValues to add key "column"/value
ContentValues values = new ContentValues();
- values.put(KEY_CIS, medicament.getCis());
- values.put(KEY_CIP13, medicament.getCip13());
- values.put(KEY_NAME, medicament.getNom());
- values.put(KEY_ADMIN, medicament.getMode_administration());
- values.put(KEY_PRES, medicament.getPresentation());
- values.put(KEY_STOCK, medicament.getStock());
- values.put(KEY_PRISE, medicament.getPrise());
- values.put(KEY_SEUIL_WARN, medicament.getWarnThreshold());
- values.put(KEY_SEUIL_ALERT, medicament.getAlertThreshold());
- values.put(KEY_LAST_UPDATE, medicament.getDateLastUpdate());
+ values.put(KEY_CIS, drug.getCis());
+ values.put(KEY_CIP13, drug.getCip13());
+ values.put(KEY_NAME, drug.getName());
+ values.put(KEY_ADMIN, drug.getAdministration_mode());
+ values.put(KEY_PRES, drug.getPresentation());
+ values.put(KEY_STOCK, drug.getStock());
+ values.put(KEY_PRISE, drug.getTake());
+ values.put(KEY_SEUIL_WARN, drug.getWarnThreshold());
+ values.put(KEY_SEUIL_ALERT, drug.getAlertThreshold());
+ values.put(KEY_LAST_UPDATE, drug.getDateLastUpdate());
- // Calculate some medicament's fields
+ // Calculate some drug's fields
// Insert
db.insert(TABLE_DRUG, // table
@@ -122,61 +125,61 @@ class DBHelper extends SQLiteOpenHelper {
}
/**
- * return a medicament from the DB with is id
- * @param id of the medicament we looking for (not used)
- * @return return the found medicament of null
+ * return a drug from the DB with is id
+ * @param id of the drug we looking for (not used)
+ * @return return the found drug of null
*/
- public Medicament getDrug(int id) {
+ public Drug getDrug(int id) {
// Get reference to readable DB
SQLiteDatabase db = this.getReadableDatabase();
// Build query
- Cursor cursor = db.query(TABLE_DRUG, // Which table
- COLUMS, // column names
- " id = ?", // selections
- new String[] { String.valueOf(id) }, // selections args
+ Cursor cursor = db.query(TABLE_DRUG, // Which table
+ COLUMS, // column names
+ " id = ?", // selections
+ new String[] { String.valueOf(id) }, // selections args
null, // group by
- null, // having
+ null, // having
null, // order by
- null); // limits
+ null); // limits
Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(cursor));
// if case we got result, go to the first one
- Medicament medicament = new Medicament();
+ Drug drug = new Drug();
if (cursor != null) {
cursor.moveToFirst();
- // Build medicament object
- medicament.setId(Integer.parseInt(cursor.getString(0)));
- medicament.setCis(cursor.getString(1));
- medicament.setCip13(cursor.getString(2));
- medicament.setNom(cursor.getString(3));
- medicament.setMode_administration(cursor.getString(4));
- medicament.setPresentation(cursor.getString(5));
- medicament.setStock(Double.parseDouble(cursor.getString(6)));
- medicament.setPrise(Double.parseDouble(cursor.getString(7)));
- medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
- medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
- medicament.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
+ // Build drug object
+ drug.setId(Integer.parseInt(cursor.getString(0)));
+ drug.setCis(cursor.getString(1));
+ drug.setCip13(cursor.getString(2));
+ drug.setNama(cursor.getString(3));
+ drug.setAdministration_mode(cursor.getString(4));
+ drug.setPresentation(cursor.getString(5));
+ drug.setStock(Double.parseDouble(cursor.getString(6)));
+ drug.setTake(Double.parseDouble(cursor.getString(7)));
+ drug.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
+ drug.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
+ drug.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
}
// Log
- Log.d(TAG, "getDrug("+id+")" + medicament.toString());
+ Log.d(TAG, "getDrug("+id+")" + drug.toString());
assert cursor != null;
cursor.close();
db.close();
- // Return medicament
+ // Return drug
- return medicament;
+ return drug;
}
/**
*
* @param cip13 drug id in French nomemclature
- * @return the medicament object found in DB or null
+ * @return the drug object found in DB or null
*/
- public Medicament getDrugByCIP13(String cip13) {
+ public Drug getDrugByCIP13(String cip13) {
// Get reference to readable DB
SQLiteDatabase db = this.getReadableDatabase();
@@ -191,30 +194,30 @@ class DBHelper extends SQLiteOpenHelper {
null); // limits
// if case we got result, go to the first one
- Medicament medicament = new Medicament();
+ Drug drug = new Drug();
if (cursor != null) {
cursor.moveToFirst();
- // Build medicament object
- medicament.setId(Integer.parseInt(cursor.getString(0)));
- medicament.setCis(cursor.getString(1));
- medicament.setCip13(cursor.getString(2));
- medicament.setNom(cursor.getString(3));
- medicament.setMode_administration(cursor.getString(4));
- medicament.setPresentation(cursor.getString(5));
- medicament.setStock(Double.parseDouble(cursor.getString(6)));
- medicament.setPrise(Double.parseDouble(cursor.getString(7)));
- medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
- medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
- medicament.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
+ // Build drug object
+ drug.setId(Integer.parseInt(cursor.getString(0)));
+ drug.setCis(cursor.getString(1));
+ drug.setCip13(cursor.getString(2));
+ drug.setNama(cursor.getString(3));
+ drug.setAdministration_mode(cursor.getString(4));
+ drug.setPresentation(cursor.getString(5));
+ drug.setStock(Double.parseDouble(cursor.getString(6)));
+ drug.setTake(Double.parseDouble(cursor.getString(7)));
+ drug.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
+ drug.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
+ drug.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
}
assert cursor != null;
cursor.close();
- Log.d(TAG, "getDrug(" + cip13 + ")" + medicament.toString());
+ Log.d(TAG, "getDrug(" + cip13 + ")" + drug.toString());
- return medicament;
+ return drug;
}
/**
@@ -222,7 +225,7 @@ class DBHelper extends SQLiteOpenHelper {
* @return a Sorted and updated by dateEndOfStock List of All medicaments presents in database
*/
- List getAllDrugs() {
+ List getAllDrugs() {
// Build the query
String query = "SELECT * FROM " + TABLE_DRUG;
@@ -233,92 +236,92 @@ class DBHelper extends SQLiteOpenHelper {
Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(cursor));
- // For Each row, build a medicament and add it to the list
- Medicament medicament;
+ // For Each row, build a drug and add it to the list
+ Drug drug;
if (cursor.moveToFirst()) {
do {
- medicament = new Medicament();
- medicament.setId(Integer.parseInt(cursor.getString(0)));
- medicament.setCis(cursor.getString(1));
- medicament.setCip13(cursor.getString(2));
- medicament.setNom(cursor.getString(3));
- medicament.setMode_administration(cursor.getString(4));
- medicament.setPresentation(cursor.getString(5));
- medicament.setStock(Double.parseDouble(cursor.getString(6)));
- medicament.setPrise(Double.parseDouble(cursor.getString(7)));
- medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
- medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
- medicament.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
+ drug = new Drug();
+ drug.setId(Integer.parseInt(cursor.getString(0)));
+ drug.setCis(cursor.getString(1));
+ drug.setCip13(cursor.getString(2));
+ drug.setNama(cursor.getString(3));
+ drug.setAdministration_mode(cursor.getString(4));
+ drug.setPresentation(cursor.getString(5));
+ drug.setStock(Double.parseDouble(cursor.getString(6)));
+ drug.setTake(Double.parseDouble(cursor.getString(7)));
+ drug.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
+ drug.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
+ drug.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
// Call calcul method
- medicament.setDateEndOfStock();
+ drug.setDateEndOfStock();
- // Add medicament to medicaments
- medicaments.add(medicament);
+ // Add drug to medicaments
+ drugs.add(drug);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
- Medicament currentMedicament;
+ Drug currentDrug;
for (int position = 0 ; position < getCount() ; position++ ) {
- currentMedicament = getItem(position);
+ currentDrug = getItem(position);
-// if (!DateUtils.isToday(currentMedicament.getDateLastUpdate()))
-// {
- currentMedicament.newStock();
- updateDrug(currentMedicament);
- //}
+ if (!DateUtils.isToday(currentDrug.getDateLastUpdate()))
+ {
+ currentDrug.newStock();
+ updateDrug(currentDrug);
+ }
}
- medicaments.sort(new Comparator() {
+ drugs.sort(new Comparator() {
@Override
- public int compare(Medicament lhs, Medicament rhs) {
+ public int compare(Drug lhs, Drug rhs) {
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
}
});
- // Move medicament with prise = 0 at the end of the list
+ // Move drug with prise = 0 at the end of the list
for (int position = 0 ; position < getCount() ; position++ ) {
- currentMedicament = getItem(position);
- double currentPrise = currentMedicament.getPrise();
- if (currentPrise == 0)
+ currentDrug = getItem(position);
+ double currentTake = currentDrug.getTake();
+ if (currentTake == 0)
{
- medicament = medicaments.remove(position);
- medicaments.add(medicaments.size(), medicament);
+ drug = drugs.remove(position);
+ drugs.add(drugs.size(), drug);
}
}
- Log.d(TAG, "getAllDrugs " + medicaments.toString());
+ Log.d(TAG, "getAllDrugs " + drugs.toString());
- return medicaments;
+ return drugs;
}
/**
*
- * @param medicament object to be updated in DB
+ * @param drug object to be updated in DB
*/
- public void updateDrug(Medicament medicament) {
+ public void updateDrug(Drug drug) {
- Log.d(TAG, "Update Drug == " + medicament);
+ Log.d(TAG, "Update Drug == " + drug);
// Get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();
// Create ContentValues to add columnm/value
ContentValues values = new ContentValues();
- values.put(KEY_ID, medicament.getId());
- values.put(KEY_CIS, medicament.getCis());
- values.put(KEY_CIP13, medicament.getCip13());
- values.put(KEY_NAME, medicament.getNom());
- values.put(KEY_ADMIN, medicament.getMode_administration());
- values.put(KEY_PRES, medicament.getPresentation());
- values.put(KEY_STOCK, medicament.getStock());
- values.put(KEY_PRISE, medicament.getPrise());
- values.put(KEY_LAST_UPDATE, medicament.getDateLastUpdate());
+ values.put(KEY_ID, drug.getId());
+ values.put(KEY_CIS, drug.getCis());
+ values.put(KEY_CIP13, drug.getCip13());
+ values.put(KEY_NAME, drug.getName());
+ values.put(KEY_ADMIN, drug.getAdministration_mode());
+ values.put(KEY_PRES, drug.getPresentation());
+ values.put(KEY_STOCK, drug.getStock());
+ values.put(KEY_PRISE, drug.getTake());
+ values.put(KEY_LAST_UPDATE, drug.getDateLastUpdate());
- String[] selectionArgs = { String.valueOf(medicament.getId()) };
+ String[] selectionArgs = { String.valueOf(drug.getId()) };
db.update(TABLE_DRUG, // table
values, // column/value
@@ -330,28 +333,28 @@ class DBHelper extends SQLiteOpenHelper {
}
/**
- * Delete a medicament object in database
- * @param medicament object to be delete in the DB
+ * Delete a drug object in database
+ * @param drug object to be delete in the DB
*/
- public void deleteDrug(Medicament medicament) {
+ public void deleteDrug(Drug drug) {
// Get writable database
SQLiteDatabase db = this.getWritableDatabase();
// Delete record
db.delete(TABLE_DRUG, // table
KEY_ID+ " = ?", // selections
- new String[] { String.valueOf(medicament.getId()) } ); // selections args
+ new String[] { String.valueOf(drug.getId()) } ); // selections args
// Close DB
db.close();
// log
- Log.d(TAG, "delete drug "+medicament);
+ Log.d(TAG, "delete drug "+ drug);
}
/**
- * Get count of all medicament present in database
- * @return number of medicament in DB
+ * Get count of all drug present in database
+ * @return number of drug in DB
*/
int getCount() {
@@ -368,11 +371,11 @@ class DBHelper extends SQLiteOpenHelper {
return count;
}
- public Medicament getItem(int position) {
- return medicaments.get(position);
+ public Drug getItem(int position) {
+ return drugs.get(position);
}
- boolean isMedicamentExist(String cip13) {
+ boolean isDrugExist(String cip13) {
boolean value = false;
try {
Cursor c = this.getReadableDatabase().rawQuery("SELECT * FROM "+ TABLE_DRUG + " where cip13 = "+cip13, null);
diff --git a/app/src/main/java/net/foucry/pilldroid/Medicament.java b/app/src/main/java/net/foucry/pilldroid/Drug.java
similarity index 74%
rename from app/src/main/java/net/foucry/pilldroid/Medicament.java
rename to app/src/main/java/net/foucry/pilldroid/Drug.java
index 93749a2..b23ecce 100644
--- a/app/src/main/java/net/foucry/pilldroid/Medicament.java
+++ b/app/src/main/java/net/foucry/pilldroid/Drug.java
@@ -10,17 +10,17 @@ import static net.foucry.pilldroid.UtilDate.*;
/**
* Created by jacques on 26/11/15.
*/
-public class Medicament implements Serializable {
+public class Drug implements Serializable {
/* part read form database */
private int id;
- private String nom;
+ private String nama;
private String cip13;
private String cis;
- private String mode_administration;
+ private String administration_mode;
private String presentation;
private double stock;
- private double prise;
+ private double take;
private int warnThreshold;
private int alertThreshold;
private long dateLastUpdate;
@@ -28,20 +28,20 @@ public class Medicament implements Serializable {
/* calculate part */
private Date dateEndOfStock;
- Medicament() {
+ Drug() {
}
- Medicament(final String cis, final String cip13, final String nom, final String mode_administration, final String presentation,
- double stock, double prise, int warn, int alert, long dateLastUpdate) {
+ Drug(final String cis, final String cip13, final String nama, final String administration_mode, final String presentation,
+ double stock, double take, int warn, int alert, long dateLastUpdate) {
super();
this.cis = cis;
this.cip13 = cip13;
- this.nom = nom;
- this.mode_administration = mode_administration;
+ this.nama = nama;
+ this.administration_mode = administration_mode;
this.presentation = presentation;
this.stock = stock;
- this.prise = prise;
+ this.take = take;
this.warnThreshold = warn;
this.alertThreshold = alert;
this.dateLastUpdate = dateLastUpdate;
@@ -52,8 +52,8 @@ public class Medicament implements Serializable {
return id;
}
- String getNom() {
- return nom;
+ String getName() {
+ return nama;
}
String getCip13() {
@@ -64,8 +64,8 @@ public class Medicament implements Serializable {
return cis;
}
- String getMode_administration() {
- return mode_administration;
+ String getAdministration_mode() {
+ return administration_mode;
}
String getPresentation() {
@@ -76,8 +76,8 @@ public class Medicament implements Serializable {
return stock;
}
- double getPrise() {
- return prise;
+ double getTake() {
+ return take;
}
int getAlertThreshold() {
@@ -100,8 +100,8 @@ public class Medicament implements Serializable {
this.id = id;
}
- void setNom(String nom) {
- this.nom = nom;
+ void setNama(String nama) {
+ this.nama = nama;
}
void setCip13(String cip13) {
@@ -112,8 +112,8 @@ public class Medicament implements Serializable {
this.cis = cis;
}
- void setMode_administration(String mode_administration) {
- this.mode_administration = mode_administration;
+ void setAdministration_mode(String administration_mode) {
+ this.administration_mode = administration_mode;
}
void setPresentation(String presentation) {
@@ -124,8 +124,8 @@ public class Medicament implements Serializable {
this.stock = stock;
}
- void setPrise(double prise) {
- this.prise = prise;
+ void setTake(double take) {
+ this.take = take;
}
void setWarnThreshold(int warn) {
@@ -146,8 +146,8 @@ public class Medicament implements Serializable {
void setDateEndOfStock() {
int numberDayOfPrise;
- if (this.prise > 0) {
- numberDayOfPrise = (int) Math.floor(this.stock / this.prise);
+ if (this.take > 0) {
+ numberDayOfPrise = (int) Math.floor(this.stock / this.take);
} else {
numberDayOfPrise = 0;
}
@@ -164,7 +164,7 @@ public class Medicament implements Serializable {
Date lastUpdate = new Date(getDateLastUpdate());
int numberOfDays = nbOfDaysBetweenDateAndToday(lastUpdate);
if (numberOfDays > 0) {
- double takeDuringPeriod = this.prise * numberOfDays;
+ double takeDuringPeriod = this.take * numberOfDays;
setStock(getStock() - takeDuringPeriod);
setDateLastUpdate(new Date().getTime());
}
diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java
similarity index 70%
rename from app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java
rename to app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java
index 2ee19df..5d13a93 100644
--- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java
@@ -18,16 +18,16 @@ import java.util.Date;
import static net.foucry.pilldroid.R.id.detail_toolbar;
/**
- * An activity representing a single Medicament detail screen. This
+ * An activity representing a single Drug detail screen. This
* activity is only used narrow width devices. On tablet-size devices,
* item details are presented side-by-side with a list of items
- * in a {@link MedicamentListActivity}.
+ * in a {@link DrugListActivity}.
*/
-public class MedicamentDetailActivity extends AppCompatActivity {
+public class DrugDetailActivity extends AppCompatActivity {
- private static final String TAG = MedicamentDetailActivity.class.getName();
+ private static final String TAG = DrugDetailActivity.class.getName();
- Medicament medicament;
+ Drug drug;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -37,10 +37,10 @@ public class MedicamentDetailActivity extends AppCompatActivity {
/* fetching the string passed with intent using ‘extras’*/
assert extras != null;
- medicament = (Medicament) extras.getSerializable("medicament");
+ drug = (Drug) extras.getSerializable("drug");
- assert medicament != null;
- Log.d(TAG, "medicament == " + medicament.toString());
+ assert drug != null;
+ Log.d(TAG, "drug == " + drug.toString());
setContentView(R.layout.activity_medicament_detail);
Toolbar toolbar = findViewById(detail_toolbar);
@@ -67,7 +67,7 @@ public class MedicamentDetailActivity extends AppCompatActivity {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setTitle(medicament.getNom());
+ actionBar.setTitle(drug.getName());
}
// savedInstanceState is non-null when there is fragment state
@@ -83,9 +83,9 @@ public class MedicamentDetailActivity extends AppCompatActivity {
// Create the detail fragment and add it to the activity
// using a fragment transaction.
Bundle arguments = new Bundle();
- arguments.putSerializable("medicament",
- getIntent().getSerializableExtra("medicament"));
- MedicamentDetailFragment fragment = new MedicamentDetailFragment();
+ arguments.putSerializable("drug",
+ getIntent().getSerializableExtra("drug"));
+ DrugDetailFragment fragment = new DrugDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction()
.add(R.id.medicament_detail_container, fragment)
@@ -103,7 +103,7 @@ public class MedicamentDetailActivity extends AppCompatActivity {
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
- navigateUpTo(new Intent(this, MedicamentListActivity.class));
+ navigateUpTo(new Intent(this, DrugListActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
@@ -115,45 +115,45 @@ public class MedicamentDetailActivity extends AppCompatActivity {
DBHelper dbHelper = new DBHelper(this);
- Medicament newMedicament = dbHelper.getDrugByCIP13(medicament.getCip13());
+ Drug newDrug = dbHelper.getDrugByCIP13(drug.getCip13());
View stockView;
- View priseView;
+ View takeView;
View warningView;
View alertView;
stockView = findViewById(R.id.stock_cell);
- EditText stockTextView = stockView.findViewById(R.id.valeur);
+ EditText stockTextView = stockView.findViewById(R.id.value);
String stockValue = stockTextView.getText().toString();
- priseView = findViewById(R.id.prise_cell);
- TextView priseTextView = priseView.findViewById(R.id.valeur);
- String priseValue = priseTextView.getText().toString();
+ takeView = findViewById(R.id.take_cell);
+ TextView takeTextView = takeView.findViewById(R.id.value);
+ String takeValue = takeTextView.getText().toString();
alertView = findViewById(R.id.alert_cell);
- TextView alertTextView = alertView.findViewById(R.id.valeur);
+ TextView alertTextView = alertView.findViewById(R.id.value);
String alertValue = alertTextView.getText().toString();
warningView = findViewById(R.id.warning_cell);
- TextView warningTextView = warningView.findViewById(R.id.valeur);
+ TextView warningTextView = warningView.findViewById(R.id.value);
String warningValue = warningTextView.getText().toString();
Log.d(TAG, "StockValue == "+ stockValue);
- Log.d(TAG, "PriseValue == "+ priseValue);
+ Log.d(TAG, "TakeValue == "+ takeValue);
Log.d(TAG, "AlertValue == "+ alertValue);
Log.d(TAG, "WarningValue == "+ warningValue);
- Log.d(TAG, "medicamentID == "+ medicament.getId());
- Log.d(TAG, "medicament == "+ medicament.toString());
+ Log.d(TAG, "medicamentID == "+ drug.getId());
+ Log.d(TAG, "drug == "+ drug.toString());
- newMedicament.setStock(Double.parseDouble(stockValue));
- newMedicament.setPrise(Double.parseDouble(priseValue));
- newMedicament.setWarnThreshold(Integer.parseInt(warningValue));
- newMedicament.setAlertThreshold(Integer.parseInt(alertValue));
- // newMedicament.setDateLastUpdate(UtilDate.dateAtNoon(new Date()).getTime());
- newMedicament.setDateLastUpdate(new Date().getTime());
- newMedicament.setDateEndOfStock();
+ newDrug.setStock(Double.parseDouble(stockValue));
+ newDrug.setTake(Double.parseDouble(takeValue));
+ newDrug.setWarnThreshold(Integer.parseInt(warningValue));
+ newDrug.setAlertThreshold(Integer.parseInt(alertValue));
+ // newDrug.setDateLastUpdate(UtilDate.dateAtNoon(new Date()).getTime());
+ newDrug.setDateLastUpdate(new Date().getTime());
+ newDrug.setDateEndOfStock();
- dbHelper.updateDrug(newMedicament);
+ dbHelper.updateDrug(newDrug);
}
}
diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java
similarity index 69%
rename from app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java
rename to app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java
index 787fe2f..97f4b7e 100644
--- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java
+++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java
@@ -12,29 +12,29 @@ import android.view.ViewGroup;
import android.widget.TextView;
/**
- * A fragment representing a single Medicament detail screen.
- * This fragment is either contained in a {@link MedicamentListActivity}
- * in two-pane mode (on tablets) or a {@link MedicamentDetailActivity}
+ * A fragment representing a single Drug detail screen.
+ * This fragment is either contained in a {@link DrugListActivity}
+ * in two-pane mode (on tablets) or a {@link DrugDetailActivity}
* on handsets.
*/
-public class MedicamentDetailFragment extends Fragment {
+public class DrugDetailFragment extends Fragment {
/**
* The fragment argument representing the item ID that this fragment
* represents.
*/
- public static final String ARG_ITEM_ID = "medicament";
+ public static final String ARG_ITEM_ID = "drug";
/**
* The dummy content this fragment is presenting.
*/
- private Medicament medicament;
+ private Drug drug;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
- public MedicamentDetailFragment() {
+ public DrugDetailFragment() {
}
@Override
@@ -46,13 +46,13 @@ public class MedicamentDetailFragment 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.
- medicament = (Medicament) getArguments().getSerializable(ARG_ITEM_ID);
+ drug = (Drug) 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(medicament.getNom());
+ appBarLayout.setTitle(drug.getName());
}
}
}
@@ -64,60 +64,60 @@ public class MedicamentDetailFragment extends Fragment {
View adminModeView;
View presentationView;
View stockView;
- View priseView;
+ View takeView;
View warningView;
View alertView;
// Show the dummy content as text in a TextView.
- if (medicament != null) {
+ if (drug != null) {
// Find each conponment of rootView
nameView = detailView.findViewById(R.id.name_cell);
TextView nameLabel = nameView.findViewById(R.id.label);
- TextView nameValeur = nameView.findViewById(R.id.valeur);
+ TextView nameValue = nameView.findViewById(R.id.value);
nameLabel.setText(R.string.med_name_label);
- nameValeur.setText(medicament.getNom());
+ nameValue.setText(drug.getName());
presentationView = detailView.findViewById(R.id.presentation_cell);
TextView presentationLabel = presentationView.findViewById(R.id.label);
- TextView presentationValeur = presentationView.findViewById(R.id.valeur);
+ TextView presentationValue = presentationView.findViewById(R.id.value);
presentationLabel.setText(R.string.med_presention_labal);
- presentationValeur.setText(medicament.getPresentation());
+ presentationValue.setText(drug.getPresentation());
adminModeView = detailView.findViewById(R.id.administration_cell);
TextView adminModeLabel = adminModeView.findViewById(R.id.label);
- TextView adminModeValeur = adminModeView.findViewById(R.id.valeur);
+ TextView adminModeValue = adminModeView.findViewById(R.id.value);
adminModeLabel.setText(R.string.med_administationMode_label);
- adminModeValeur.setText(medicament.getMode_administration());
+ adminModeValue.setText(drug.getAdministration_mode());
stockView = detailView.findViewById(R.id.stock_cell);
- TextView stockLibelle = (stockView.findViewById(R.id.libelle));
- TextView stockValue = stockView.findViewById(R.id.valeur);
+ TextView stockLibelle = (stockView.findViewById(R.id.label));
+ TextView stockValue = stockView.findViewById(R.id.value);
stockLibelle.setText(R.string.med_current_stock_label);
- stockValue.setText(Double.toString(medicament.getStock()));
+ stockValue.setText(Double.toString(drug.getStock()));
stockValue.setHint(R.string.med_current_stock_label);
stockValue.setSelectAllOnFocus(true);
- priseView = detailView.findViewById(R.id.prise_cell);
- TextView priseLibelle = priseView.findViewById(R.id.libelle);
- TextView priseValue = (priseView.findViewById(R.id.valeur));
- priseLibelle.setText(R.string.med_take_label);
- priseValue.setText(Double.toString(medicament.getPrise()));
+ 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.med_take_label);
+ priseValue.setText(Double.toString(drug.getTake()));
priseValue.setHint(R.string.med_take_label);
priseValue.setSelectAllOnFocus(true);
warningView = detailView.findViewById(R.id.warning_cell);
- TextView warningLibelle = warningView.findViewById(R.id.libelle);
- TextView warningValue = warningView.findViewById(R.id.valeur);
+ TextView warningLibelle = warningView.findViewById(R.id.label);
+ TextView warningValue = warningView.findViewById(R.id.value);
warningLibelle.setText(R.string.med_warningTherehold_label);
- warningValue.setText(Integer.toString(medicament.getWarnThreshold()));
+ warningValue.setText(Integer.toString(drug.getWarnThreshold()));
warningValue.setHint(R.string.med_warningTherehold_label);
warningValue.setSelectAllOnFocus(true);
alertView = detailView.findViewById(R.id.alert_cell);
- TextView alertLibelle = alertView.findViewById(R.id.libelle);
- TextView alertValue = alertView.findViewById(R.id.valeur);
+ TextView alertLibelle = alertView.findViewById(R.id.label);
+ TextView alertValue = alertView.findViewById(R.id.value);
alertLibelle.setText(R.string.med_alertTherehold_label);
- alertValue.setText(Integer.toString(medicament.getAlertThreshold()));
+ alertValue.setText(Integer.toString(drug.getAlertThreshold()));
alertValue.setHint(R.string.med_alertTherehold_label);
alertValue.setSelectAllOnFocus(true);
}
diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
similarity index 83%
rename from app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java
rename to app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
index f29394e..950a5f8 100644
--- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
@@ -8,6 +8,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.icu.util.Calendar;
+import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@@ -46,11 +47,11 @@ import static net.foucry.pilldroid.Utils.intRandomExclusive;
* An activity representing a list of Medicaments. This activity
* has different presentations for handset and tablet-size devices. On
* handsets, the activity presents a list of items, which when touched,
- * lead to a {@link MedicamentDetailActivity} representing
+ * lead to a {@link DrugDetailActivity} representing
* item details. On tablets, the activity presents the list of items and
* item details side-by-side using two vertical panes.
*/
-public class MedicamentListActivity extends AppCompatActivity {
+public class DrugListActivity extends AppCompatActivity {
/**
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
* device.
@@ -86,33 +87,33 @@ public class MedicamentListActivity extends AppCompatActivity {
super.onStop();
}
- private static final String TAG = MedicamentListActivity.class.getName();
+ private static final String TAG = DrugListActivity.class.getName();
private DBHelper dbHelper;
- private DBMedoc dbMedoc;
+ private DBDrugs dbDrug;
- private List medicaments;
+ private List drugs;
private SimpleItemRecyclerViewAdapter mAdapter;
public int getCount() {
- return medicaments.size();
+ return drugs.size();
}
- public Medicament getItem(int position) {
- return medicaments.get(position);
+ public Drug getItem(int position) {
+ return drugs.get(position);
}
- public void constructMedsList()
+ public void constructDrugsList()
{
dbHelper = new DBHelper(getApplicationContext());
- if (!(medicaments == null)) {
- if (!medicaments.isEmpty()) {
- medicaments.clear();
+ if (!(drugs == null)) {
+ if (!drugs.isEmpty()) {
+ drugs.clear();
}
}
- medicaments = dbHelper.getAllDrugs();
+ drugs = dbHelper.getAllDrugs();
View mRecyclerView = findViewById(R.id.medicament_list);
assert mRecyclerView != null;
@@ -125,8 +126,10 @@ public class MedicamentListActivity extends AppCompatActivity {
setContentView(R.layout.activity_medicament_list);
- dbHelper = new DBHelper(this);
- dbMedoc = new DBMedoc(this);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ dbHelper = new DBHelper(this);
+ }
+ dbDrug = new DBDrugs(this);
Toolbar toolbar = findViewById(R.id.toolbar);
@@ -152,40 +155,40 @@ public class MedicamentListActivity extends AppCompatActivity {
final int min_prise=0;
final int max_prise=3;
- dbHelper.addDrug(new Medicament("60000011", "3400930000011", "Médicament test 01", "orale",
+ 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 Medicament("60000012", "3400930000012", "Médicament test 02", "orale",
+ 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 Medicament("60000013", "3400930000013", "Médicament test 03", "orale",
+ 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 Medicament("60000014", "3400930000014", "Médicament test 04", "orale",
+ 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 Medicament("60000015", "3400930000015", "Médicament test 05", "orale",
+ 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 Medicament("60000016", "3400930000016", "Médicament test 06", "orale",
+ 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 Medicament("60000017", "3400930000017", "Médicament test 07", "orale",
+ 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 Medicament("60000018", "3400930000018", "Médicament test 08", "orale",
+ 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 Medicament("60000019", "3400930000019", "Médicament test 09", "orale",
+ 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 Medicament("60000010", "3400930000010", "Médicament test 10", "orale",
+ 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()));
}
}
- constructMedsList();
+ constructDrugsList();
}
@@ -239,7 +242,7 @@ public class MedicamentListActivity extends AppCompatActivity {
Toast.makeText(this, "REQUEST_CODE = " + requestCode + "RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show();
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
if (resultCode == 1) {
- constructMedsList();
+ constructDrugsList();
} else {
Toast.makeText(this, "What are you doing here?", Toast.LENGTH_SHORT).show();
Log.d(TAG, "What are you doing here?");
@@ -284,7 +287,7 @@ public class MedicamentListActivity extends AppCompatActivity {
}
// Get Medoc from database
- final Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13);
+ final Drug scannedMedoc = dbDrug.getDrugByCIP13(cip13);
askToAddInDB(scannedMedoc);
}
}
@@ -295,9 +298,9 @@ public class MedicamentListActivity extends AppCompatActivity {
*/
protected void showInputDialog() {
// get prompts.xml view
- LayoutInflater layoutInflater = LayoutInflater.from(MedicamentListActivity.this);
+ LayoutInflater layoutInflater = LayoutInflater.from(DrugListActivity.this);
View promptView = layoutInflater.inflate(R.layout.input_dialog, null);
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MedicamentListActivity.this);
+ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(DrugListActivity.this);
alertDialogBuilder.setView(promptView);
final EditText editText = promptView.findViewById(R.id.edittext);
@@ -308,7 +311,7 @@ public class MedicamentListActivity extends AppCompatActivity {
.setPositiveButton("OK", (dialog, id) -> {
String cip13 = editText.getText().toString();
- Medicament med = dbMedoc.getMedocByCIP13(cip13);
+ Drug med = dbDrug.getDrugByCIP13(cip13);
askToAddInDB(med);
})
.setNegativeButton("Cancel",
@@ -330,34 +333,30 @@ public class MedicamentListActivity extends AppCompatActivity {
@Override
public void afterTextChanged(Editable s) {
- if (s.length() != 13 ) {
- alert.getButton(alert.BUTTON_POSITIVE).setEnabled(false);
- } else {
- alert.getButton(alert.BUTTON_POSITIVE).setEnabled(true);
- }
+ alert.getButton(alert.BUTTON_POSITIVE).setEnabled(s.length() == 13);
}
});
alert.show();
}
/**
- * Ask if the medicament found in the database should be include in the
+ * Ask if the drug found in the database should be include in the
* user database
- * @param med Medicament- medicament to be added
+ * @param med Drug- drug to be added
*/
- private void askToAddInDB(Medicament med) {
+ private void askToAddInDB(Drug med) {
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.setTitle(getString(R.string.app_name));
if (med != null) {
- String msg = med.getNom() + " " + getString(R.string.msgFound);
+ String msg = med.getName() + " " + getString(R.string.msgFound);
dlg.setMessage(msg);
dlg.setNegativeButton(getString(R.string.button_cancel), (dialog, which) -> {
// Nothing to do in case of cancel
});
dlg.setPositiveButton(getString(R.string.button_ok), (dialog, which) -> {
- // Add Medicament to DB then try to show it
+ // Add Drug to DB then try to show it
addMedToList(med);
});
} else {
@@ -370,18 +369,18 @@ public class MedicamentListActivity extends AppCompatActivity {
}
/**
- * Add New medicament to the user database
- * @param med Medicament - medicament to be added
+ * Add New drug to the user database
+ * @param med Drug - drug to be added
*/
- private void addMedToList(Medicament med)
+ private void addMedToList(Drug med)
{
med.setDateEndOfStock();
mAdapter.addItem(med);
- Log.d(TAG, "Call MedicamentDetailActivity");
+ Log.d(TAG, "Call DrugDetailActivity");
Context context = this;
- Intent intent = new Intent(context, MedicamentDetailActivity.class);
- intent.putExtra("medicament", med);
+ Intent intent = new Intent(context, DrugDetailActivity.class);
+ intent.putExtra("drug", med);
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
}
@@ -421,12 +420,12 @@ public class MedicamentListActivity extends AppCompatActivity {
Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()));
}
/**
- * setupRecyclerView (list of medicaments
+ * setupRecyclerView (list of drugs
* @param recyclerView RecyclerView
*/
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
- mAdapter = new SimpleItemRecyclerViewAdapter(medicaments);
+ mAdapter = new SimpleItemRecyclerViewAdapter(drugs);
recyclerView.setAdapter(mAdapter);
}
@@ -446,14 +445,14 @@ public class MedicamentListActivity extends AppCompatActivity {
public class SimpleItemRecyclerViewAdapter
extends RecyclerView.Adapter {
- private final List mValues;
+ private final List mValues;
- SimpleItemRecyclerViewAdapter(List items) {
+ SimpleItemRecyclerViewAdapter(List items) {
mValues = items;
}
- void addItem(Medicament scannedMedoc) {
- if (!dbHelper.isMedicamentExist(scannedMedoc.getCip13())) {
+ void addItem(Drug scannedMedoc) {
+ if (!dbHelper.isDrugExist(scannedMedoc.getCip13())) {
mValues.add(scannedMedoc);
notifyDataSetChanged();
dbHelper.addDrug(scannedMedoc);
@@ -477,21 +476,21 @@ public class MedicamentListActivity extends AppCompatActivity {
Log.d(TAG, "dateEndOfStock == " + dateEndOfStock);
Log.d(TAG, "stock == " + mValues.get(position).getStock());
- Log.d(TAG, "prise == " + mValues.get(position).getPrise());
+ Log.d(TAG, "take == " + mValues.get(position).getTake());
Log.d(TAG, "warn == " + mValues.get(position).getWarnThreshold());
Log.d(TAG, "alert == " + mValues.get(position).getAlertThreshold());
holder.mItem = mValues.get(position);
holder.mIDView.setText(mValues.get(position).getCip13());
- holder.mContentView.setText(mValues.get(position).getNom());
+ holder.mContentView.setText(mValues.get(position).getName());
holder.mEndOfStock.setText(dateEndOfStock);
// Test to change background programmatically
- if (mValues.get(position).getPrise() == 0) {
+ if (mValues.get(position).getTake() == 0) {
holder.mView.setBackgroundResource(R.drawable.gradient_bg);
holder.mIconView.setImageResource(R.drawable.ic_suspended_pill);
} else {
- int remainingStock = (int) Math.floor(mValues.get(position).getStock() / mValues.get(position).getPrise());
+ int remainingStock = (int) Math.floor(mValues.get(position).getStock() / mValues.get(position).getTake());
if (remainingStock <= mValues.get(position).getAlertThreshold()) {
holder.mView.setBackgroundResource(R.drawable.gradient_bg_alert);
holder.mIconView.setImageResource(R.drawable.lower_stock_vect);
@@ -508,10 +507,10 @@ public class MedicamentListActivity extends AppCompatActivity {
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Medicament medicamentCourant = mValues.get(position);
+ Drug drugCourant = mValues.get(position);
Context context = v.getContext();
- Intent intent = new Intent(context, MedicamentDetailActivity.class);
- intent.putExtra("medicament", medicamentCourant);
+ Intent intent = new Intent(context, DrugDetailActivity.class);
+ intent.putExtra("drug", drugCourant);
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
}
@@ -530,13 +529,13 @@ public class MedicamentListActivity extends AppCompatActivity {
final TextView mEndOfStock;
final ImageView mIconView;
- Medicament mItem;
+ Drug mItem;
ViewHolder(View view) {
super(view);
mView = view;
mIDView = view.findViewById(R.id.cip13);
- mContentView = view.findViewById(R.id.valeur);
+ mContentView = view.findViewById(R.id.value);
mEndOfStock = view.findViewById(R.id.endOfStock);
mIconView = view.findViewById(R.id.list_image);
}
diff --git a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java
index 0df0f23..ddb29fd 100644
--- a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java
+++ b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java
@@ -46,25 +46,25 @@ public class PillDroidJobService extends JobService {
if (jobCancelled) {
return;
}
- List medicaments = dbHelper.getAllDrugs();
+ List drugs = dbHelper.getAllDrugs();
- Medicament firstMedicament = null;
+ Drug firstDrug = null;
try {
- firstMedicament = medicaments.get(0);
+ firstDrug = drugs.get(0);
}
catch (Exception e){
Log.e(TAG, e.toString());
e.printStackTrace();
}
- if (firstMedicament != null) {
- if (firstMedicament.getPrise() != 0) {
- if(firstMedicament.getStock() < firstMedicament.getAlertThreshold()) {
+ if (firstDrug != null) {
+ if (firstDrug.getTake() != 0) {
+ if(firstDrug.getStock() < firstDrug.getAlertThreshold()) {
scheduleNotification();
} else
{
- double dummy = (firstMedicament.getStock() - firstMedicament.getAlertThreshold());
+ double dummy = (firstDrug.getStock() - firstDrug.getAlertThreshold());
Log.d(TAG, "no notification scheduled " + dummy);
}
}
@@ -88,7 +88,7 @@ public class PillDroidJobService extends JobService {
void scheduleNotification() {
Log.d(TAG, "schedule notification");
createNotificationChannel();
- Intent intent = new Intent(this, MedicamentListActivity.class);
+ Intent intent = new Intent(this, DrugListActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "PillDroid")
.setSmallIcon(R.drawable.ic_pill_alarm)
diff --git a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java
index 834f53d..ebb5a8c 100644
--- a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java
@@ -124,7 +124,7 @@ public class WelcomeActivity extends AppCompatActivity {
void launchHomeScreen() {
prefManager.setFirstTimeLaunch(false);
- startActivity(new Intent(WelcomeActivity.this, MedicamentListActivity.class));
+ startActivity(new Intent(WelcomeActivity.this, DrugListActivity.class));
finish();
}
diff --git a/app/src/main/res/layout-w900dp/medicament_list.xml b/app/src/main/res/layout-w900dp/medicament_list.xml
index f003192..902b468 100644
--- a/app/src/main/res/layout-w900dp/medicament_list.xml
+++ b/app/src/main/res/layout-w900dp/medicament_list.xml
@@ -9,7 +9,7 @@
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle"
- tools:context="net.foucry.pilldroid.MedicamentListActivity">
+ tools:context="net.foucry.pilldroid.DrugListActivity">