mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Refactor for internalization
This commit is contained in:
parent
5cbc80df30
commit
2a22187ca3
24 changed files with 373 additions and 374 deletions
|
@ -18,6 +18,7 @@ android {
|
||||||
targetSdkVersion defaultTargetSdkVersion
|
targetSdkVersion defaultTargetSdkVersion
|
||||||
versionCode generateVersionCode() // 190010203
|
versionCode generateVersionCode() // 190010203
|
||||||
versionName generateVersionName() // 1.2.3-SNAPSHOT
|
versionName generateVersionName() // 1.2.3-SNAPSHOT
|
||||||
|
multiDexEnabled true
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
@ -29,6 +30,8 @@ android {
|
||||||
productFlavors {
|
productFlavors {
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
coreLibraryDesugaringEnabled true
|
||||||
|
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
@ -45,6 +48,7 @@ android {
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
}
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
@ -67,6 +71,8 @@ dependencies {
|
||||||
implementation 'androidx.core:core:1.3.2'
|
implementation 'androidx.core:core:1.3.2'
|
||||||
|
|
||||||
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
|
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
|
||||||
|
|
||||||
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer generateVersionCode() {
|
private Integer generateVersionCode() {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.foucry.pilldroid;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.test.ApplicationTestCase;
|
import android.test.ApplicationTestCase;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:allowBackup="true">
|
android:allowBackup="true">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MedicamentListActivity"
|
android:name=".DrugListActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -25,27 +25,27 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".MedicamentDetailActivity"
|
android:name=".DrugDetailActivity"
|
||||||
android:label="@string/title_medicament_detail"
|
android:label="@string/title_medicament_detail"
|
||||||
android:parentActivityName=".MedicamentListActivity"
|
android:parentActivityName=".DrugListActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value="net.foucry.pilldroid.MedicamentListActivity" />
|
android:value="net.foucry.pilldroid.DrugListActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".WelcomeActivity"
|
android:name=".WelcomeActivity"
|
||||||
android:label="Welcome"
|
android:label="Welcome"
|
||||||
android:parentActivityName=".MedicamentListActivity"
|
android:parentActivityName=".DrugListActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value="net.foucry.pilldroid.MedicamentListActivity" />
|
android:value="net.foucry.pilldroid.DrugListActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".About"
|
android:name=".About"
|
||||||
android:label="À propos de PillDroid"
|
android:label="À propos de PillDroid"
|
||||||
android:parentActivityName=".MedicamentListActivity"
|
android:parentActivityName=".DrugListActivity"
|
||||||
android:theme="@style/AppTheme" />
|
android:theme="@style/AppTheme" />
|
||||||
<activity android:name=".CustomScannerActivity" />
|
<activity android:name=".CustomScannerActivity" />
|
||||||
<service
|
<service
|
||||||
|
|
BIN
app/src/main/assets/drugs.db
Normal file
BIN
app/src/main/assets/drugs.db
Normal file
Binary file not shown.
Binary file not shown.
|
@ -18,7 +18,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class AlarmReceiver extends BroadcastReceiver {
|
public class AlarmReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
private static final String TAG = MedicamentDetailFragment.class.getName();
|
private static final String TAG = DrugDetailFragment.class.getName();
|
||||||
|
|
||||||
NotificationManager nm;
|
NotificationManager nm;
|
||||||
|
|
||||||
|
@ -33,21 +33,21 @@ public class AlarmReceiver extends BroadcastReceiver {
|
||||||
DBHelper dbHelper = new DBHelper(context);
|
DBHelper dbHelper = new DBHelper(context);
|
||||||
dbHelper.getAllDrugs();
|
dbHelper.getAllDrugs();
|
||||||
|
|
||||||
List<Medicament> medicaments = dbHelper.getAllDrugs();
|
List<Drug> drugs = dbHelper.getAllDrugs();
|
||||||
|
|
||||||
Medicament firstMedicament = null;
|
Drug firstDrug = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
firstMedicament = medicaments.get(0);
|
firstDrug = drugs.get(0);
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e){
|
||||||
Log.e(TAG, e.toString());
|
Log.e(TAG, e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstMedicament != null) {
|
if (firstDrug != null) {
|
||||||
if (firstMedicament.getPrise() != 0) {
|
if (firstDrug.getTake() != 0) {
|
||||||
if(firstMedicament.getStock() < firstMedicament.getAlertThreshold()) {
|
if(firstDrug.getStock() < firstDrug.getAlertThreshold()) {
|
||||||
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
|
||||||
|
@ -68,7 +68,7 @@ public class AlarmReceiver extends BroadcastReceiver {
|
||||||
notificationManager.notify(notificationId, builder.build());
|
notificationManager.notify(notificationId, builder.build());
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
double dummy = (firstMedicament.getStock() - firstMedicament.getAlertThreshold());
|
double dummy = (firstDrug.getStock() - firstDrug.getAlertThreshold());
|
||||||
Log.d(TAG, "no notification scheduled " + dummy);
|
Log.d(TAG, "no notification scheduled " + dummy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,37 +16,51 @@ import java.io.OutputStream;
|
||||||
/**
|
/**
|
||||||
* Created by jfoucry on 5/25/16.
|
* 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 int DATABASE_VERSION = 1;
|
||||||
|
|
||||||
private static final String dbName = "medicaments.db";
|
private static final String dbName = "drugs.db";
|
||||||
private final Context myContext;
|
private final Context myContext;
|
||||||
private final SQLiteDatabase myDataBase = null;
|
private final SQLiteDatabase myDataBase = null;
|
||||||
|
|
||||||
private static final String TABLE_NAME = "medicaments";
|
private static final String TABLE_NAME = "drugs";
|
||||||
private static final String MEDOC_CIS = "cis";
|
private static final String DRUG_CIS = "cis";
|
||||||
private static final String MEDOC_CIP13 = "cip13";
|
private static final String DRUG_CIP13 = "cip13";
|
||||||
private static final String MEDOC_ADMIN = "mode_administration";
|
private static final String DRUG_ADMIN = "administration_mode";
|
||||||
private static final String MEDOC_NOM = "nom";
|
private static final String DRUG_NAME = "name";
|
||||||
private static final String MEDOC_PRES = "presentation";
|
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);
|
super(context, dbName, null, DATABASE_VERSION);
|
||||||
this.myContext = context;
|
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
|
@Override
|
||||||
public synchronized SQLiteDatabase getWritableDatabase() {
|
public synchronized SQLiteDatabase getWritableDatabase() {
|
||||||
|
|
||||||
File dbFile = myContext.getDatabasePath(dbName);
|
File dbFile = myContext.getDatabasePath(dbName);
|
||||||
|
|
||||||
if (!dbFile.exists()) {
|
if (!isDBFileExist(dbFile)) {
|
||||||
copyDatabase(dbFile.getPath());
|
copyDatabase(dbFile.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +71,6 @@ class DBMedoc extends SQLiteOpenHelper {
|
||||||
public synchronized SQLiteDatabase getReadableDatabase() {
|
public synchronized SQLiteDatabase getReadableDatabase() {
|
||||||
File dbFile = myContext.getDatabasePath(dbName);
|
File dbFile = myContext.getDatabasePath(dbName);
|
||||||
|
|
||||||
//if (dbFile.exists()) return super.getReadableDatabase();
|
|
||||||
|
|
||||||
PrefManager prefManager = new PrefManager(myContext);
|
PrefManager prefManager = new PrefManager(myContext);
|
||||||
int oldVersion = prefManager.getDatabaseVersion();
|
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
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
if (myDataBase != null) {
|
if (myDataBase != null) {
|
||||||
|
@ -113,9 +118,9 @@ class DBMedoc extends SQLiteOpenHelper {
|
||||||
* Lookup in the DB for a record corresponding to cip13
|
* Lookup in the DB for a record corresponding to cip13
|
||||||
*
|
*
|
||||||
* @param cip13 string representing the object we're looking for
|
* @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);
|
Log.e(TAG, "CIP13 - " + cip13);
|
||||||
|
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
|
@ -134,28 +139,28 @@ class DBMedoc extends SQLiteOpenHelper {
|
||||||
|
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
|
|
||||||
// Build medicament object
|
// Build drug object
|
||||||
Medicament medicament = new Medicament();
|
Drug drug = new Drug();
|
||||||
// medicament.setId(Integer.parseInt(cursor.getString(0)));
|
// drug.setId(Integer.parseInt(cursor.getString(0)));
|
||||||
medicament.setCis(cursor.getString(0));
|
drug.setCis(cursor.getString(0));
|
||||||
medicament.setCip13(cursor.getString(1));
|
drug.setCip13(cursor.getString(1));
|
||||||
medicament.setMode_administration(cursor.getString(2));
|
drug.setAdministration_mode(cursor.getString(2));
|
||||||
medicament.setNom(cursor.getString(3));
|
drug.setNama(cursor.getString(3));
|
||||||
medicament.setPresentation(cursor.getString(4));
|
drug.setPresentation(cursor.getString(4));
|
||||||
|
|
||||||
// Set default values
|
// Set default values
|
||||||
medicament.setStock(0);
|
drug.setStock(0);
|
||||||
medicament.setPrise(0);
|
drug.setTake(0);
|
||||||
medicament.setWarnThreshold(14);
|
drug.setWarnThreshold(14);
|
||||||
medicament.setAlertThreshold(7);
|
drug.setAlertThreshold(7);
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
Log.d(TAG, "getDrug(" + cip13 + ")" + medicament.toString());
|
Log.d(TAG, "getDrug(" + cip13 + ")" + drug.toString());
|
||||||
|
|
||||||
// Return medicament
|
// Return drug
|
||||||
|
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return medicament;
|
return drug;
|
||||||
} else
|
} else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
|
@ -6,12 +6,14 @@ import android.database.Cursor;
|
||||||
import android.database.DatabaseUtils;
|
import android.database.DatabaseUtils;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,25 +21,26 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DBHelper extends SQLiteOpenHelper {
|
class DBHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 1;
|
private static final int DATABASE_VERSION = 1;
|
||||||
private static final ThreadLocal<String> 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 TABLE_DRUG = "drug";
|
||||||
private static final String KEY_ID = "id";
|
private static final String KEY_ID = "id";
|
||||||
private static final String KEY_CIS = "cis";
|
private static final String KEY_CIS = "cis";
|
||||||
private static final String KEY_CIP13 = "cip13";
|
private static final String KEY_CIP13 = "cip13";
|
||||||
private static final String KEY_NAME = "nom";
|
private static final String KEY_NAME = "name";
|
||||||
private static final String KEY_ADMIN = "mode_administration";
|
private static final String KEY_ADMIN = "administration_mode";
|
||||||
private static final String KEY_PRES = "presentation";
|
private static final String KEY_PRES = "presentation";
|
||||||
private static final String KEY_STOCK = "stock";
|
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_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";
|
private static final String KEY_LAST_UPDATE = "last_update";
|
||||||
|
|
||||||
final List<Medicament> medicaments = new ArrayList<>();
|
final List<Drug> drugs = new ArrayList<>();
|
||||||
|
|
||||||
private static final String TAG = DBHelper.class.getName();
|
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};
|
KEY_SEUIL_WARN, KEY_SEUIL_ALERT, KEY_LAST_UPDATE};
|
||||||
|
|
||||||
DBHelper(Context context) {
|
DBHelper(Context context) {
|
||||||
super(context, DATABASE_NAME.get(), null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,13 +57,13 @@ class DBHelper extends SQLiteOpenHelper {
|
||||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||||
"cis TEXT, " +
|
"cis TEXT, " +
|
||||||
"cip13 TEXT, " +
|
"cip13 TEXT, " +
|
||||||
"nom TEXT, " +
|
"name TEXT, " +
|
||||||
"mode_administration TEXT, " +
|
"administration_mode TEXT, " +
|
||||||
"presentation TEXT, " +
|
"presentation TEXT, " +
|
||||||
"stock REAL, " +
|
"stock REAL, " +
|
||||||
"prise REAL, " +
|
"take REAL, " +
|
||||||
"warning INT, " +
|
"warning INT, " +
|
||||||
"alerte INT, " +
|
"alert INT, " +
|
||||||
"last_update LONG)";
|
"last_update LONG)";
|
||||||
|
|
||||||
db.execSQL(CREATE_DRUG_TABLE);
|
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
|
* Split drug values into database record and record it to the DB
|
||||||
* @param medicament the medicament object to be saved
|
* @param drug the drug object to be saved
|
||||||
*/
|
*/
|
||||||
void addDrug(Medicament medicament) {
|
void addDrug(Drug drug) {
|
||||||
// Logging
|
// Logging
|
||||||
Log.d(TAG, medicament.toString());
|
Log.d(TAG, drug.toString());
|
||||||
|
|
||||||
// Get reference to writable DB
|
// Get reference to writable DB
|
||||||
SQLiteDatabase db = this.getWritableDatabase();
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
// Create ContentValues to add key "column"/value
|
// Create ContentValues to add key "column"/value
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY_CIS, medicament.getCis());
|
values.put(KEY_CIS, drug.getCis());
|
||||||
values.put(KEY_CIP13, medicament.getCip13());
|
values.put(KEY_CIP13, drug.getCip13());
|
||||||
values.put(KEY_NAME, medicament.getNom());
|
values.put(KEY_NAME, drug.getName());
|
||||||
values.put(KEY_ADMIN, medicament.getMode_administration());
|
values.put(KEY_ADMIN, drug.getAdministration_mode());
|
||||||
values.put(KEY_PRES, medicament.getPresentation());
|
values.put(KEY_PRES, drug.getPresentation());
|
||||||
values.put(KEY_STOCK, medicament.getStock());
|
values.put(KEY_STOCK, drug.getStock());
|
||||||
values.put(KEY_PRISE, medicament.getPrise());
|
values.put(KEY_PRISE, drug.getTake());
|
||||||
values.put(KEY_SEUIL_WARN, medicament.getWarnThreshold());
|
values.put(KEY_SEUIL_WARN, drug.getWarnThreshold());
|
||||||
values.put(KEY_SEUIL_ALERT, medicament.getAlertThreshold());
|
values.put(KEY_SEUIL_ALERT, drug.getAlertThreshold());
|
||||||
values.put(KEY_LAST_UPDATE, medicament.getDateLastUpdate());
|
values.put(KEY_LAST_UPDATE, drug.getDateLastUpdate());
|
||||||
|
|
||||||
// Calculate some medicament's fields
|
// Calculate some drug's fields
|
||||||
|
|
||||||
// Insert
|
// Insert
|
||||||
db.insert(TABLE_DRUG, // table
|
db.insert(TABLE_DRUG, // table
|
||||||
|
@ -122,61 +125,61 @@ class DBHelper extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a medicament from the DB with is id
|
* return a drug from the DB with is id
|
||||||
* @param id of the medicament we looking for (not used)
|
* @param id of the drug we looking for (not used)
|
||||||
* @return return the found medicament of null
|
* @return return the found drug of null
|
||||||
*/
|
*/
|
||||||
public Medicament getDrug(int id) {
|
public Drug getDrug(int id) {
|
||||||
// Get reference to readable DB
|
// Get reference to readable DB
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
|
|
||||||
// Build query
|
// Build query
|
||||||
Cursor cursor = db.query(TABLE_DRUG, // Which table
|
Cursor cursor = db.query(TABLE_DRUG, // Which table
|
||||||
COLUMS, // column names
|
COLUMS, // column names
|
||||||
" id = ?", // selections
|
" id = ?", // selections
|
||||||
new String[] { String.valueOf(id) }, // selections args
|
new String[] { String.valueOf(id) }, // selections args
|
||||||
null, // group by
|
null, // group by
|
||||||
null, // having
|
null, // having
|
||||||
null, // order by
|
null, // order by
|
||||||
null); // limits
|
null); // limits
|
||||||
|
|
||||||
Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(cursor));
|
Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(cursor));
|
||||||
|
|
||||||
// if case we got result, go to the first one
|
// if case we got result, go to the first one
|
||||||
Medicament medicament = new Medicament();
|
Drug drug = new Drug();
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
|
|
||||||
// Build medicament object
|
// Build drug object
|
||||||
medicament.setId(Integer.parseInt(cursor.getString(0)));
|
drug.setId(Integer.parseInt(cursor.getString(0)));
|
||||||
medicament.setCis(cursor.getString(1));
|
drug.setCis(cursor.getString(1));
|
||||||
medicament.setCip13(cursor.getString(2));
|
drug.setCip13(cursor.getString(2));
|
||||||
medicament.setNom(cursor.getString(3));
|
drug.setNama(cursor.getString(3));
|
||||||
medicament.setMode_administration(cursor.getString(4));
|
drug.setAdministration_mode(cursor.getString(4));
|
||||||
medicament.setPresentation(cursor.getString(5));
|
drug.setPresentation(cursor.getString(5));
|
||||||
medicament.setStock(Double.parseDouble(cursor.getString(6)));
|
drug.setStock(Double.parseDouble(cursor.getString(6)));
|
||||||
medicament.setPrise(Double.parseDouble(cursor.getString(7)));
|
drug.setTake(Double.parseDouble(cursor.getString(7)));
|
||||||
medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
|
drug.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
|
||||||
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
drug.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
||||||
medicament.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
|
drug.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
|
||||||
}
|
}
|
||||||
// Log
|
// Log
|
||||||
Log.d(TAG, "getDrug("+id+")" + medicament.toString());
|
Log.d(TAG, "getDrug("+id+")" + drug.toString());
|
||||||
|
|
||||||
assert cursor != null;
|
assert cursor != null;
|
||||||
cursor.close();
|
cursor.close();
|
||||||
db.close();
|
db.close();
|
||||||
// Return medicament
|
// Return drug
|
||||||
|
|
||||||
return medicament;
|
return drug;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param cip13 drug id in French nomemclature
|
* @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
|
// Get reference to readable DB
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
|
|
||||||
|
@ -191,30 +194,30 @@ class DBHelper extends SQLiteOpenHelper {
|
||||||
null); // limits
|
null); // limits
|
||||||
|
|
||||||
// if case we got result, go to the first one
|
// if case we got result, go to the first one
|
||||||
Medicament medicament = new Medicament();
|
Drug drug = new Drug();
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
|
|
||||||
// Build medicament object
|
// Build drug object
|
||||||
medicament.setId(Integer.parseInt(cursor.getString(0)));
|
drug.setId(Integer.parseInt(cursor.getString(0)));
|
||||||
medicament.setCis(cursor.getString(1));
|
drug.setCis(cursor.getString(1));
|
||||||
medicament.setCip13(cursor.getString(2));
|
drug.setCip13(cursor.getString(2));
|
||||||
medicament.setNom(cursor.getString(3));
|
drug.setNama(cursor.getString(3));
|
||||||
medicament.setMode_administration(cursor.getString(4));
|
drug.setAdministration_mode(cursor.getString(4));
|
||||||
medicament.setPresentation(cursor.getString(5));
|
drug.setPresentation(cursor.getString(5));
|
||||||
medicament.setStock(Double.parseDouble(cursor.getString(6)));
|
drug.setStock(Double.parseDouble(cursor.getString(6)));
|
||||||
medicament.setPrise(Double.parseDouble(cursor.getString(7)));
|
drug.setTake(Double.parseDouble(cursor.getString(7)));
|
||||||
medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
|
drug.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
|
||||||
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
drug.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
||||||
medicament.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
|
drug.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert cursor != null;
|
assert cursor != null;
|
||||||
cursor.close();
|
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
|
* @return a Sorted and updated by dateEndOfStock List of All medicaments presents in database
|
||||||
*/
|
*/
|
||||||
|
|
||||||
List<Medicament> getAllDrugs() {
|
List<Drug> getAllDrugs() {
|
||||||
|
|
||||||
// Build the query
|
// Build the query
|
||||||
String query = "SELECT * FROM " + TABLE_DRUG;
|
String query = "SELECT * FROM " + TABLE_DRUG;
|
||||||
|
@ -233,92 +236,92 @@ class DBHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(cursor));
|
Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(cursor));
|
||||||
|
|
||||||
// For Each row, build a medicament and add it to the list
|
// For Each row, build a drug and add it to the list
|
||||||
Medicament medicament;
|
Drug drug;
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
medicament = new Medicament();
|
drug = new Drug();
|
||||||
medicament.setId(Integer.parseInt(cursor.getString(0)));
|
drug.setId(Integer.parseInt(cursor.getString(0)));
|
||||||
medicament.setCis(cursor.getString(1));
|
drug.setCis(cursor.getString(1));
|
||||||
medicament.setCip13(cursor.getString(2));
|
drug.setCip13(cursor.getString(2));
|
||||||
medicament.setNom(cursor.getString(3));
|
drug.setNama(cursor.getString(3));
|
||||||
medicament.setMode_administration(cursor.getString(4));
|
drug.setAdministration_mode(cursor.getString(4));
|
||||||
medicament.setPresentation(cursor.getString(5));
|
drug.setPresentation(cursor.getString(5));
|
||||||
medicament.setStock(Double.parseDouble(cursor.getString(6)));
|
drug.setStock(Double.parseDouble(cursor.getString(6)));
|
||||||
medicament.setPrise(Double.parseDouble(cursor.getString(7)));
|
drug.setTake(Double.parseDouble(cursor.getString(7)));
|
||||||
medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
|
drug.setWarnThreshold(Integer.parseInt(cursor.getString(8)));
|
||||||
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
drug.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
||||||
medicament.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
|
drug.setDateLastUpdate(Long.parseLong(cursor.getString(10)));
|
||||||
// Call calcul method
|
// Call calcul method
|
||||||
medicament.setDateEndOfStock();
|
drug.setDateEndOfStock();
|
||||||
|
|
||||||
|
|
||||||
// Add medicament to medicaments
|
// Add drug to medicaments
|
||||||
medicaments.add(medicament);
|
drugs.add(drug);
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.close();
|
cursor.close();
|
||||||
db.close();
|
db.close();
|
||||||
|
|
||||||
Medicament currentMedicament;
|
Drug currentDrug;
|
||||||
for (int position = 0 ; position < getCount() ; position++ ) {
|
for (int position = 0 ; position < getCount() ; position++ ) {
|
||||||
currentMedicament = getItem(position);
|
currentDrug = getItem(position);
|
||||||
|
|
||||||
// if (!DateUtils.isToday(currentMedicament.getDateLastUpdate()))
|
if (!DateUtils.isToday(currentDrug.getDateLastUpdate()))
|
||||||
// {
|
{
|
||||||
currentMedicament.newStock();
|
currentDrug.newStock();
|
||||||
updateDrug(currentMedicament);
|
updateDrug(currentDrug);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
medicaments.sort(new Comparator<Medicament>() {
|
drugs.sort(new Comparator<Drug>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Medicament lhs, Medicament rhs) {
|
public int compare(Drug lhs, Drug rhs) {
|
||||||
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
|
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++ ) {
|
for (int position = 0 ; position < getCount() ; position++ ) {
|
||||||
currentMedicament = getItem(position);
|
currentDrug = getItem(position);
|
||||||
double currentPrise = currentMedicament.getPrise();
|
double currentTake = currentDrug.getTake();
|
||||||
if (currentPrise == 0)
|
if (currentTake == 0)
|
||||||
{
|
{
|
||||||
medicament = medicaments.remove(position);
|
drug = drugs.remove(position);
|
||||||
medicaments.add(medicaments.size(), medicament);
|
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
|
// Get reference to writable DB
|
||||||
SQLiteDatabase db = this.getWritableDatabase();
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
// Create ContentValues to add columnm/value
|
// Create ContentValues to add columnm/value
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY_ID, medicament.getId());
|
values.put(KEY_ID, drug.getId());
|
||||||
values.put(KEY_CIS, medicament.getCis());
|
values.put(KEY_CIS, drug.getCis());
|
||||||
values.put(KEY_CIP13, medicament.getCip13());
|
values.put(KEY_CIP13, drug.getCip13());
|
||||||
values.put(KEY_NAME, medicament.getNom());
|
values.put(KEY_NAME, drug.getName());
|
||||||
values.put(KEY_ADMIN, medicament.getMode_administration());
|
values.put(KEY_ADMIN, drug.getAdministration_mode());
|
||||||
values.put(KEY_PRES, medicament.getPresentation());
|
values.put(KEY_PRES, drug.getPresentation());
|
||||||
values.put(KEY_STOCK, medicament.getStock());
|
values.put(KEY_STOCK, drug.getStock());
|
||||||
values.put(KEY_PRISE, medicament.getPrise());
|
values.put(KEY_PRISE, drug.getTake());
|
||||||
values.put(KEY_LAST_UPDATE, medicament.getDateLastUpdate());
|
values.put(KEY_LAST_UPDATE, drug.getDateLastUpdate());
|
||||||
|
|
||||||
String[] selectionArgs = { String.valueOf(medicament.getId()) };
|
String[] selectionArgs = { String.valueOf(drug.getId()) };
|
||||||
|
|
||||||
db.update(TABLE_DRUG, // table
|
db.update(TABLE_DRUG, // table
|
||||||
values, // column/value
|
values, // column/value
|
||||||
|
@ -330,28 +333,28 @@ class DBHelper extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a medicament object in database
|
* Delete a drug object in database
|
||||||
* @param medicament object to be delete in the DB
|
* @param drug object to be delete in the DB
|
||||||
*/
|
*/
|
||||||
public void deleteDrug(Medicament medicament) {
|
public void deleteDrug(Drug drug) {
|
||||||
// Get writable database
|
// Get writable database
|
||||||
SQLiteDatabase db = this.getWritableDatabase();
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
// Delete record
|
// Delete record
|
||||||
db.delete(TABLE_DRUG, // table
|
db.delete(TABLE_DRUG, // table
|
||||||
KEY_ID+ " = ?", // selections
|
KEY_ID+ " = ?", // selections
|
||||||
new String[] { String.valueOf(medicament.getId()) } ); // selections args
|
new String[] { String.valueOf(drug.getId()) } ); // selections args
|
||||||
|
|
||||||
// Close DB
|
// Close DB
|
||||||
db.close();
|
db.close();
|
||||||
|
|
||||||
// log
|
// log
|
||||||
Log.d(TAG, "delete drug "+medicament);
|
Log.d(TAG, "delete drug "+ drug);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get count of all medicament present in database
|
* Get count of all drug present in database
|
||||||
* @return number of medicament in DB
|
* @return number of drug in DB
|
||||||
*/
|
*/
|
||||||
int getCount() {
|
int getCount() {
|
||||||
|
|
||||||
|
@ -368,11 +371,11 @@ class DBHelper extends SQLiteOpenHelper {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Medicament getItem(int position) {
|
public Drug getItem(int position) {
|
||||||
return medicaments.get(position);
|
return drugs.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isMedicamentExist(String cip13) {
|
boolean isDrugExist(String cip13) {
|
||||||
boolean value = false;
|
boolean value = false;
|
||||||
try {
|
try {
|
||||||
Cursor c = this.getReadableDatabase().rawQuery("SELECT * FROM "+ TABLE_DRUG + " where cip13 = "+cip13, null);
|
Cursor c = this.getReadableDatabase().rawQuery("SELECT * FROM "+ TABLE_DRUG + " where cip13 = "+cip13, null);
|
||||||
|
|
|
@ -10,17 +10,17 @@ import static net.foucry.pilldroid.UtilDate.*;
|
||||||
/**
|
/**
|
||||||
* Created by jacques on 26/11/15.
|
* Created by jacques on 26/11/15.
|
||||||
*/
|
*/
|
||||||
public class Medicament implements Serializable {
|
public class Drug implements Serializable {
|
||||||
|
|
||||||
/* part read form database */
|
/* part read form database */
|
||||||
private int id;
|
private int id;
|
||||||
private String nom;
|
private String nama;
|
||||||
private String cip13;
|
private String cip13;
|
||||||
private String cis;
|
private String cis;
|
||||||
private String mode_administration;
|
private String administration_mode;
|
||||||
private String presentation;
|
private String presentation;
|
||||||
private double stock;
|
private double stock;
|
||||||
private double prise;
|
private double take;
|
||||||
private int warnThreshold;
|
private int warnThreshold;
|
||||||
private int alertThreshold;
|
private int alertThreshold;
|
||||||
private long dateLastUpdate;
|
private long dateLastUpdate;
|
||||||
|
@ -28,20 +28,20 @@ public class Medicament implements Serializable {
|
||||||
/* calculate part */
|
/* calculate part */
|
||||||
private Date dateEndOfStock;
|
private Date dateEndOfStock;
|
||||||
|
|
||||||
Medicament() {
|
Drug() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Medicament(final String cis, final String cip13, final String nom, final String mode_administration, final String presentation,
|
Drug(final String cis, final String cip13, final String nama, final String administration_mode, final String presentation,
|
||||||
double stock, double prise, int warn, int alert, long dateLastUpdate) {
|
double stock, double take, int warn, int alert, long dateLastUpdate) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.cis = cis;
|
this.cis = cis;
|
||||||
this.cip13 = cip13;
|
this.cip13 = cip13;
|
||||||
this.nom = nom;
|
this.nama = nama;
|
||||||
this.mode_administration = mode_administration;
|
this.administration_mode = administration_mode;
|
||||||
this.presentation = presentation;
|
this.presentation = presentation;
|
||||||
this.stock = stock;
|
this.stock = stock;
|
||||||
this.prise = prise;
|
this.take = take;
|
||||||
this.warnThreshold = warn;
|
this.warnThreshold = warn;
|
||||||
this.alertThreshold = alert;
|
this.alertThreshold = alert;
|
||||||
this.dateLastUpdate = dateLastUpdate;
|
this.dateLastUpdate = dateLastUpdate;
|
||||||
|
@ -52,8 +52,8 @@ public class Medicament implements Serializable {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getNom() {
|
String getName() {
|
||||||
return nom;
|
return nama;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getCip13() {
|
String getCip13() {
|
||||||
|
@ -64,8 +64,8 @@ public class Medicament implements Serializable {
|
||||||
return cis;
|
return cis;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getMode_administration() {
|
String getAdministration_mode() {
|
||||||
return mode_administration;
|
return administration_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getPresentation() {
|
String getPresentation() {
|
||||||
|
@ -76,8 +76,8 @@ public class Medicament implements Serializable {
|
||||||
return stock;
|
return stock;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getPrise() {
|
double getTake() {
|
||||||
return prise;
|
return take;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getAlertThreshold() {
|
int getAlertThreshold() {
|
||||||
|
@ -100,8 +100,8 @@ public class Medicament implements Serializable {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNom(String nom) {
|
void setNama(String nama) {
|
||||||
this.nom = nom;
|
this.nama = nama;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCip13(String cip13) {
|
void setCip13(String cip13) {
|
||||||
|
@ -112,8 +112,8 @@ public class Medicament implements Serializable {
|
||||||
this.cis = cis;
|
this.cis = cis;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMode_administration(String mode_administration) {
|
void setAdministration_mode(String administration_mode) {
|
||||||
this.mode_administration = mode_administration;
|
this.administration_mode = administration_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPresentation(String presentation) {
|
void setPresentation(String presentation) {
|
||||||
|
@ -124,8 +124,8 @@ public class Medicament implements Serializable {
|
||||||
this.stock = stock;
|
this.stock = stock;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPrise(double prise) {
|
void setTake(double take) {
|
||||||
this.prise = prise;
|
this.take = take;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWarnThreshold(int warn) {
|
void setWarnThreshold(int warn) {
|
||||||
|
@ -146,8 +146,8 @@ public class Medicament implements Serializable {
|
||||||
|
|
||||||
void setDateEndOfStock() {
|
void setDateEndOfStock() {
|
||||||
int numberDayOfPrise;
|
int numberDayOfPrise;
|
||||||
if (this.prise > 0) {
|
if (this.take > 0) {
|
||||||
numberDayOfPrise = (int) Math.floor(this.stock / this.prise);
|
numberDayOfPrise = (int) Math.floor(this.stock / this.take);
|
||||||
} else {
|
} else {
|
||||||
numberDayOfPrise = 0;
|
numberDayOfPrise = 0;
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ public class Medicament implements Serializable {
|
||||||
Date lastUpdate = new Date(getDateLastUpdate());
|
Date lastUpdate = new Date(getDateLastUpdate());
|
||||||
int numberOfDays = nbOfDaysBetweenDateAndToday(lastUpdate);
|
int numberOfDays = nbOfDaysBetweenDateAndToday(lastUpdate);
|
||||||
if (numberOfDays > 0) {
|
if (numberOfDays > 0) {
|
||||||
double takeDuringPeriod = this.prise * numberOfDays;
|
double takeDuringPeriod = this.take * numberOfDays;
|
||||||
setStock(getStock() - takeDuringPeriod);
|
setStock(getStock() - takeDuringPeriod);
|
||||||
setDateLastUpdate(new Date().getTime());
|
setDateLastUpdate(new Date().getTime());
|
||||||
}
|
}
|
|
@ -18,16 +18,16 @@ import java.util.Date;
|
||||||
import static net.foucry.pilldroid.R.id.detail_toolbar;
|
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,
|
* activity is only used narrow width devices. On tablet-size devices,
|
||||||
* item details are presented side-by-side with a list of items
|
* 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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -37,10 +37,10 @@ public class MedicamentDetailActivity extends AppCompatActivity {
|
||||||
/* fetching the string passed with intent using ‘extras’*/
|
/* fetching the string passed with intent using ‘extras’*/
|
||||||
|
|
||||||
assert extras != null;
|
assert extras != null;
|
||||||
medicament = (Medicament) extras.getSerializable("medicament");
|
drug = (Drug) extras.getSerializable("drug");
|
||||||
|
|
||||||
assert medicament != null;
|
assert drug != null;
|
||||||
Log.d(TAG, "medicament == " + medicament.toString());
|
Log.d(TAG, "drug == " + drug.toString());
|
||||||
|
|
||||||
setContentView(R.layout.activity_medicament_detail);
|
setContentView(R.layout.activity_medicament_detail);
|
||||||
Toolbar toolbar = findViewById(detail_toolbar);
|
Toolbar toolbar = findViewById(detail_toolbar);
|
||||||
|
@ -67,7 +67,7 @@ public class MedicamentDetailActivity extends AppCompatActivity {
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
actionBar.setTitle(medicament.getNom());
|
actionBar.setTitle(drug.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// savedInstanceState is non-null when there is fragment state
|
// 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
|
// Create the detail fragment and add it to the activity
|
||||||
// using a fragment transaction.
|
// using a fragment transaction.
|
||||||
Bundle arguments = new Bundle();
|
Bundle arguments = new Bundle();
|
||||||
arguments.putSerializable("medicament",
|
arguments.putSerializable("drug",
|
||||||
getIntent().getSerializableExtra("medicament"));
|
getIntent().getSerializableExtra("drug"));
|
||||||
MedicamentDetailFragment fragment = new MedicamentDetailFragment();
|
DrugDetailFragment fragment = new DrugDetailFragment();
|
||||||
fragment.setArguments(arguments);
|
fragment.setArguments(arguments);
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.add(R.id.medicament_detail_container, fragment)
|
.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
|
// 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 true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
@ -115,45 +115,45 @@ public class MedicamentDetailActivity extends AppCompatActivity {
|
||||||
|
|
||||||
DBHelper dbHelper = new DBHelper(this);
|
DBHelper dbHelper = new DBHelper(this);
|
||||||
|
|
||||||
Medicament newMedicament = dbHelper.getDrugByCIP13(medicament.getCip13());
|
Drug newDrug = dbHelper.getDrugByCIP13(drug.getCip13());
|
||||||
|
|
||||||
View stockView;
|
View stockView;
|
||||||
View priseView;
|
View takeView;
|
||||||
View warningView;
|
View warningView;
|
||||||
View alertView;
|
View alertView;
|
||||||
|
|
||||||
stockView = findViewById(R.id.stock_cell);
|
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();
|
String stockValue = stockTextView.getText().toString();
|
||||||
|
|
||||||
priseView = findViewById(R.id.prise_cell);
|
takeView = findViewById(R.id.take_cell);
|
||||||
TextView priseTextView = priseView.findViewById(R.id.valeur);
|
TextView takeTextView = takeView.findViewById(R.id.value);
|
||||||
String priseValue = priseTextView.getText().toString();
|
String takeValue = takeTextView.getText().toString();
|
||||||
|
|
||||||
alertView = findViewById(R.id.alert_cell);
|
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();
|
String alertValue = alertTextView.getText().toString();
|
||||||
|
|
||||||
warningView = findViewById(R.id.warning_cell);
|
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();
|
String warningValue = warningTextView.getText().toString();
|
||||||
|
|
||||||
|
|
||||||
Log.d(TAG, "StockValue == "+ stockValue);
|
Log.d(TAG, "StockValue == "+ stockValue);
|
||||||
Log.d(TAG, "PriseValue == "+ priseValue);
|
Log.d(TAG, "TakeValue == "+ takeValue);
|
||||||
Log.d(TAG, "AlertValue == "+ alertValue);
|
Log.d(TAG, "AlertValue == "+ alertValue);
|
||||||
Log.d(TAG, "WarningValue == "+ warningValue);
|
Log.d(TAG, "WarningValue == "+ warningValue);
|
||||||
Log.d(TAG, "medicamentID == "+ medicament.getId());
|
Log.d(TAG, "medicamentID == "+ drug.getId());
|
||||||
Log.d(TAG, "medicament == "+ medicament.toString());
|
Log.d(TAG, "drug == "+ drug.toString());
|
||||||
|
|
||||||
newMedicament.setStock(Double.parseDouble(stockValue));
|
newDrug.setStock(Double.parseDouble(stockValue));
|
||||||
newMedicament.setPrise(Double.parseDouble(priseValue));
|
newDrug.setTake(Double.parseDouble(takeValue));
|
||||||
newMedicament.setWarnThreshold(Integer.parseInt(warningValue));
|
newDrug.setWarnThreshold(Integer.parseInt(warningValue));
|
||||||
newMedicament.setAlertThreshold(Integer.parseInt(alertValue));
|
newDrug.setAlertThreshold(Integer.parseInt(alertValue));
|
||||||
// newMedicament.setDateLastUpdate(UtilDate.dateAtNoon(new Date()).getTime());
|
// newDrug.setDateLastUpdate(UtilDate.dateAtNoon(new Date()).getTime());
|
||||||
newMedicament.setDateLastUpdate(new Date().getTime());
|
newDrug.setDateLastUpdate(new Date().getTime());
|
||||||
newMedicament.setDateEndOfStock();
|
newDrug.setDateEndOfStock();
|
||||||
|
|
||||||
dbHelper.updateDrug(newMedicament);
|
dbHelper.updateDrug(newDrug);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,29 +12,29 @@ import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment representing a single Medicament detail screen.
|
* A fragment representing a single Drug detail screen.
|
||||||
* This fragment is either contained in a {@link MedicamentListActivity}
|
* This fragment is either contained in a {@link DrugListActivity}
|
||||||
* in two-pane mode (on tablets) or a {@link MedicamentDetailActivity}
|
* in two-pane mode (on tablets) or a {@link DrugDetailActivity}
|
||||||
* on handsets.
|
* on handsets.
|
||||||
*/
|
*/
|
||||||
public class MedicamentDetailFragment extends Fragment {
|
public class DrugDetailFragment extends Fragment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fragment argument representing the item ID that this fragment
|
* The fragment argument representing the item ID that this fragment
|
||||||
* represents.
|
* represents.
|
||||||
*/
|
*/
|
||||||
public static final String ARG_ITEM_ID = "medicament";
|
public static final String ARG_ITEM_ID = "drug";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The dummy content this fragment is presenting.
|
* The dummy content this fragment is presenting.
|
||||||
*/
|
*/
|
||||||
private Medicament medicament;
|
private Drug drug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||||
* fragment (e.g. upon screen orientation changes).
|
* fragment (e.g. upon screen orientation changes).
|
||||||
*/
|
*/
|
||||||
public MedicamentDetailFragment() {
|
public DrugDetailFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,13 +46,13 @@ public class MedicamentDetailFragment extends Fragment {
|
||||||
// Load the dummy content specified by the fragment
|
// Load the dummy content specified by the fragment
|
||||||
// arguments. In a real-world scenario, use a Loader
|
// arguments. In a real-world scenario, use a Loader
|
||||||
// to load content from a content provider.
|
// 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();
|
Activity activity = this.getActivity();
|
||||||
assert activity != null;
|
assert activity != null;
|
||||||
CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout);
|
CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout);
|
||||||
if (appBarLayout != null) {
|
if (appBarLayout != null) {
|
||||||
appBarLayout.setTitle(medicament.getNom());
|
appBarLayout.setTitle(drug.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,60 +64,60 @@ public class MedicamentDetailFragment extends Fragment {
|
||||||
View adminModeView;
|
View adminModeView;
|
||||||
View presentationView;
|
View presentationView;
|
||||||
View stockView;
|
View stockView;
|
||||||
View priseView;
|
View takeView;
|
||||||
View warningView;
|
View warningView;
|
||||||
View alertView;
|
View alertView;
|
||||||
|
|
||||||
// Show the dummy content as text in a TextView.
|
// Show the dummy content as text in a TextView.
|
||||||
if (medicament != null) {
|
if (drug != null) {
|
||||||
// Find each conponment of rootView
|
// Find each conponment of rootView
|
||||||
nameView = detailView.findViewById(R.id.name_cell);
|
nameView = detailView.findViewById(R.id.name_cell);
|
||||||
TextView nameLabel = nameView.findViewById(R.id.label);
|
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);
|
nameLabel.setText(R.string.med_name_label);
|
||||||
nameValeur.setText(medicament.getNom());
|
nameValue.setText(drug.getName());
|
||||||
|
|
||||||
presentationView = detailView.findViewById(R.id.presentation_cell);
|
presentationView = detailView.findViewById(R.id.presentation_cell);
|
||||||
TextView presentationLabel = presentationView.findViewById(R.id.label);
|
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);
|
presentationLabel.setText(R.string.med_presention_labal);
|
||||||
presentationValeur.setText(medicament.getPresentation());
|
presentationValue.setText(drug.getPresentation());
|
||||||
|
|
||||||
adminModeView = detailView.findViewById(R.id.administration_cell);
|
adminModeView = detailView.findViewById(R.id.administration_cell);
|
||||||
TextView adminModeLabel = adminModeView.findViewById(R.id.label);
|
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);
|
adminModeLabel.setText(R.string.med_administationMode_label);
|
||||||
adminModeValeur.setText(medicament.getMode_administration());
|
adminModeValue.setText(drug.getAdministration_mode());
|
||||||
|
|
||||||
stockView = detailView.findViewById(R.id.stock_cell);
|
stockView = detailView.findViewById(R.id.stock_cell);
|
||||||
TextView stockLibelle = (stockView.findViewById(R.id.libelle));
|
TextView stockLibelle = (stockView.findViewById(R.id.label));
|
||||||
TextView stockValue = stockView.findViewById(R.id.valeur);
|
TextView stockValue = stockView.findViewById(R.id.value);
|
||||||
stockLibelle.setText(R.string.med_current_stock_label);
|
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.setHint(R.string.med_current_stock_label);
|
||||||
stockValue.setSelectAllOnFocus(true);
|
stockValue.setSelectAllOnFocus(true);
|
||||||
|
|
||||||
priseView = detailView.findViewById(R.id.prise_cell);
|
takeView = detailView.findViewById(R.id.take_cell);
|
||||||
TextView priseLibelle = priseView.findViewById(R.id.libelle);
|
TextView priseLabel = takeView.findViewById(R.id.label);
|
||||||
TextView priseValue = (priseView.findViewById(R.id.valeur));
|
TextView priseValue = (takeView.findViewById(R.id.value));
|
||||||
priseLibelle.setText(R.string.med_take_label);
|
priseLabel.setText(R.string.med_take_label);
|
||||||
priseValue.setText(Double.toString(medicament.getPrise()));
|
priseValue.setText(Double.toString(drug.getTake()));
|
||||||
priseValue.setHint(R.string.med_take_label);
|
priseValue.setHint(R.string.med_take_label);
|
||||||
priseValue.setSelectAllOnFocus(true);
|
priseValue.setSelectAllOnFocus(true);
|
||||||
|
|
||||||
warningView = detailView.findViewById(R.id.warning_cell);
|
warningView = detailView.findViewById(R.id.warning_cell);
|
||||||
TextView warningLibelle = warningView.findViewById(R.id.libelle);
|
TextView warningLibelle = warningView.findViewById(R.id.label);
|
||||||
TextView warningValue = warningView.findViewById(R.id.valeur);
|
TextView warningValue = warningView.findViewById(R.id.value);
|
||||||
warningLibelle.setText(R.string.med_warningTherehold_label);
|
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.setHint(R.string.med_warningTherehold_label);
|
||||||
warningValue.setSelectAllOnFocus(true);
|
warningValue.setSelectAllOnFocus(true);
|
||||||
|
|
||||||
alertView = detailView.findViewById(R.id.alert_cell);
|
alertView = detailView.findViewById(R.id.alert_cell);
|
||||||
TextView alertLibelle = alertView.findViewById(R.id.libelle);
|
TextView alertLibelle = alertView.findViewById(R.id.label);
|
||||||
TextView alertValue = alertView.findViewById(R.id.valeur);
|
TextView alertValue = alertView.findViewById(R.id.value);
|
||||||
alertLibelle.setText(R.string.med_alertTherehold_label);
|
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.setHint(R.string.med_alertTherehold_label);
|
||||||
alertValue.setSelectAllOnFocus(true);
|
alertValue.setSelectAllOnFocus(true);
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.icu.util.Calendar;
|
import android.icu.util.Calendar;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
@ -46,11 +47,11 @@ import static net.foucry.pilldroid.Utils.intRandomExclusive;
|
||||||
* An activity representing a list of Medicaments. This activity
|
* An activity representing a list of Medicaments. This activity
|
||||||
* has different presentations for handset and tablet-size devices. On
|
* has different presentations for handset and tablet-size devices. On
|
||||||
* handsets, the activity presents a list of items, which when touched,
|
* 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. On tablets, the activity presents the list of items and
|
||||||
* item details side-by-side using two vertical panes.
|
* 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
|
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
|
||||||
* device.
|
* device.
|
||||||
|
@ -86,33 +87,33 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TAG = MedicamentListActivity.class.getName();
|
private static final String TAG = DrugListActivity.class.getName();
|
||||||
|
|
||||||
private DBHelper dbHelper;
|
private DBHelper dbHelper;
|
||||||
private DBMedoc dbMedoc;
|
private DBDrugs dbDrug;
|
||||||
|
|
||||||
private List<Medicament> medicaments;
|
private List<Drug> drugs;
|
||||||
|
|
||||||
private SimpleItemRecyclerViewAdapter mAdapter;
|
private SimpleItemRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return medicaments.size();
|
return drugs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Medicament getItem(int position) {
|
public Drug getItem(int position) {
|
||||||
return medicaments.get(position);
|
return drugs.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void constructMedsList()
|
public void constructDrugsList()
|
||||||
{
|
{
|
||||||
dbHelper = new DBHelper(getApplicationContext());
|
dbHelper = new DBHelper(getApplicationContext());
|
||||||
|
|
||||||
if (!(medicaments == null)) {
|
if (!(drugs == null)) {
|
||||||
if (!medicaments.isEmpty()) {
|
if (!drugs.isEmpty()) {
|
||||||
medicaments.clear();
|
drugs.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
medicaments = dbHelper.getAllDrugs();
|
drugs = dbHelper.getAllDrugs();
|
||||||
|
|
||||||
View mRecyclerView = findViewById(R.id.medicament_list);
|
View mRecyclerView = findViewById(R.id.medicament_list);
|
||||||
assert mRecyclerView != null;
|
assert mRecyclerView != null;
|
||||||
|
@ -125,8 +126,10 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
setContentView(R.layout.activity_medicament_list);
|
setContentView(R.layout.activity_medicament_list);
|
||||||
|
|
||||||
dbHelper = new DBHelper(this);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
dbMedoc = new DBMedoc(this);
|
dbHelper = new DBHelper(this);
|
||||||
|
}
|
||||||
|
dbDrug = new DBDrugs(this);
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
|
||||||
|
@ -152,40 +155,40 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
final int min_prise=0;
|
final int min_prise=0;
|
||||||
final int max_prise=3;
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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)",
|
"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()));
|
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();
|
Toast.makeText(this, "REQUEST_CODE = " + requestCode + "RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show();
|
||||||
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
|
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
|
||||||
if (resultCode == 1) {
|
if (resultCode == 1) {
|
||||||
constructMedsList();
|
constructDrugsList();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "What are you doing here?", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "What are you doing here?", Toast.LENGTH_SHORT).show();
|
||||||
Log.d(TAG, "What are you doing here?");
|
Log.d(TAG, "What are you doing here?");
|
||||||
|
@ -284,7 +287,7 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Medoc from database
|
// Get Medoc from database
|
||||||
final Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13);
|
final Drug scannedMedoc = dbDrug.getDrugByCIP13(cip13);
|
||||||
askToAddInDB(scannedMedoc);
|
askToAddInDB(scannedMedoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,9 +298,9 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
*/
|
*/
|
||||||
protected void showInputDialog() {
|
protected void showInputDialog() {
|
||||||
// get prompts.xml view
|
// 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);
|
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);
|
alertDialogBuilder.setView(promptView);
|
||||||
|
|
||||||
final EditText editText = promptView.findViewById(R.id.edittext);
|
final EditText editText = promptView.findViewById(R.id.edittext);
|
||||||
|
@ -308,7 +311,7 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
.setPositiveButton("OK", (dialog, id) -> {
|
.setPositiveButton("OK", (dialog, id) -> {
|
||||||
String cip13 = editText.getText().toString();
|
String cip13 = editText.getText().toString();
|
||||||
|
|
||||||
Medicament med = dbMedoc.getMedocByCIP13(cip13);
|
Drug med = dbDrug.getDrugByCIP13(cip13);
|
||||||
askToAddInDB(med);
|
askToAddInDB(med);
|
||||||
})
|
})
|
||||||
.setNegativeButton("Cancel",
|
.setNegativeButton("Cancel",
|
||||||
|
@ -330,34 +333,30 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
if (s.length() != 13 ) {
|
alert.getButton(alert.BUTTON_POSITIVE).setEnabled(s.length() == 13);
|
||||||
alert.getButton(alert.BUTTON_POSITIVE).setEnabled(false);
|
|
||||||
} else {
|
|
||||||
alert.getButton(alert.BUTTON_POSITIVE).setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
alert.show();
|
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
|
* 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);
|
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||||
dlg.setTitle(getString(R.string.app_name));
|
dlg.setTitle(getString(R.string.app_name));
|
||||||
|
|
||||||
if (med != null) {
|
if (med != null) {
|
||||||
String msg = med.getNom() + " " + getString(R.string.msgFound);
|
String msg = med.getName() + " " + getString(R.string.msgFound);
|
||||||
|
|
||||||
dlg.setMessage(msg);
|
dlg.setMessage(msg);
|
||||||
dlg.setNegativeButton(getString(R.string.button_cancel), (dialog, which) -> {
|
dlg.setNegativeButton(getString(R.string.button_cancel), (dialog, which) -> {
|
||||||
// Nothing to do in case of cancel
|
// Nothing to do in case of cancel
|
||||||
});
|
});
|
||||||
dlg.setPositiveButton(getString(R.string.button_ok), (dialog, which) -> {
|
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);
|
addMedToList(med);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -370,18 +369,18 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add New medicament to the user database
|
* Add New drug to the user database
|
||||||
* @param med Medicament - medicament to be added
|
* @param med Drug - drug to be added
|
||||||
*/
|
*/
|
||||||
private void addMedToList(Medicament med)
|
private void addMedToList(Drug med)
|
||||||
{
|
{
|
||||||
med.setDateEndOfStock();
|
med.setDateEndOfStock();
|
||||||
mAdapter.addItem(med);
|
mAdapter.addItem(med);
|
||||||
|
|
||||||
Log.d(TAG, "Call MedicamentDetailActivity");
|
Log.d(TAG, "Call DrugDetailActivity");
|
||||||
Context context = this;
|
Context context = this;
|
||||||
Intent intent = new Intent(context, MedicamentDetailActivity.class);
|
Intent intent = new Intent(context, DrugDetailActivity.class);
|
||||||
intent.putExtra("medicament", med);
|
intent.putExtra("drug", med);
|
||||||
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
||||||
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
|
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()));
|
Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* setupRecyclerView (list of medicaments
|
* setupRecyclerView (list of drugs
|
||||||
* @param recyclerView RecyclerView
|
* @param recyclerView RecyclerView
|
||||||
*/
|
*/
|
||||||
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
|
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
|
||||||
mAdapter = new SimpleItemRecyclerViewAdapter(medicaments);
|
mAdapter = new SimpleItemRecyclerViewAdapter(drugs);
|
||||||
recyclerView.setAdapter(mAdapter);
|
recyclerView.setAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,14 +445,14 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
public class SimpleItemRecyclerViewAdapter
|
public class SimpleItemRecyclerViewAdapter
|
||||||
extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
||||||
|
|
||||||
private final List<Medicament> mValues;
|
private final List<Drug> mValues;
|
||||||
|
|
||||||
SimpleItemRecyclerViewAdapter(List<Medicament> items) {
|
SimpleItemRecyclerViewAdapter(List<Drug> items) {
|
||||||
mValues = items;
|
mValues = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addItem(Medicament scannedMedoc) {
|
void addItem(Drug scannedMedoc) {
|
||||||
if (!dbHelper.isMedicamentExist(scannedMedoc.getCip13())) {
|
if (!dbHelper.isDrugExist(scannedMedoc.getCip13())) {
|
||||||
mValues.add(scannedMedoc);
|
mValues.add(scannedMedoc);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
dbHelper.addDrug(scannedMedoc);
|
dbHelper.addDrug(scannedMedoc);
|
||||||
|
@ -477,21 +476,21 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
Log.d(TAG, "dateEndOfStock == " + dateEndOfStock);
|
Log.d(TAG, "dateEndOfStock == " + dateEndOfStock);
|
||||||
Log.d(TAG, "stock == " + mValues.get(position).getStock());
|
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, "warn == " + mValues.get(position).getWarnThreshold());
|
||||||
Log.d(TAG, "alert == " + mValues.get(position).getAlertThreshold());
|
Log.d(TAG, "alert == " + mValues.get(position).getAlertThreshold());
|
||||||
|
|
||||||
holder.mItem = mValues.get(position);
|
holder.mItem = mValues.get(position);
|
||||||
holder.mIDView.setText(mValues.get(position).getCip13());
|
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);
|
holder.mEndOfStock.setText(dateEndOfStock);
|
||||||
|
|
||||||
// Test to change background programmatically
|
// 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.mView.setBackgroundResource(R.drawable.gradient_bg);
|
||||||
holder.mIconView.setImageResource(R.drawable.ic_suspended_pill);
|
holder.mIconView.setImageResource(R.drawable.ic_suspended_pill);
|
||||||
} else {
|
} 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()) {
|
if (remainingStock <= mValues.get(position).getAlertThreshold()) {
|
||||||
holder.mView.setBackgroundResource(R.drawable.gradient_bg_alert);
|
holder.mView.setBackgroundResource(R.drawable.gradient_bg_alert);
|
||||||
holder.mIconView.setImageResource(R.drawable.lower_stock_vect);
|
holder.mIconView.setImageResource(R.drawable.lower_stock_vect);
|
||||||
|
@ -508,10 +507,10 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
holder.mView.setOnClickListener(new View.OnClickListener() {
|
holder.mView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Medicament medicamentCourant = mValues.get(position);
|
Drug drugCourant = mValues.get(position);
|
||||||
Context context = v.getContext();
|
Context context = v.getContext();
|
||||||
Intent intent = new Intent(context, MedicamentDetailActivity.class);
|
Intent intent = new Intent(context, DrugDetailActivity.class);
|
||||||
intent.putExtra("medicament", medicamentCourant);
|
intent.putExtra("drug", drugCourant);
|
||||||
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
||||||
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
|
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
|
||||||
}
|
}
|
||||||
|
@ -530,13 +529,13 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
final TextView mEndOfStock;
|
final TextView mEndOfStock;
|
||||||
final ImageView mIconView;
|
final ImageView mIconView;
|
||||||
|
|
||||||
Medicament mItem;
|
Drug mItem;
|
||||||
|
|
||||||
ViewHolder(View view) {
|
ViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
mView = view;
|
mView = view;
|
||||||
mIDView = view.findViewById(R.id.cip13);
|
mIDView = view.findViewById(R.id.cip13);
|
||||||
mContentView = view.findViewById(R.id.valeur);
|
mContentView = view.findViewById(R.id.value);
|
||||||
mEndOfStock = view.findViewById(R.id.endOfStock);
|
mEndOfStock = view.findViewById(R.id.endOfStock);
|
||||||
mIconView = view.findViewById(R.id.list_image);
|
mIconView = view.findViewById(R.id.list_image);
|
||||||
}
|
}
|
|
@ -46,25 +46,25 @@ public class PillDroidJobService extends JobService {
|
||||||
if (jobCancelled) {
|
if (jobCancelled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<Medicament> medicaments = dbHelper.getAllDrugs();
|
List<Drug> drugs = dbHelper.getAllDrugs();
|
||||||
|
|
||||||
Medicament firstMedicament = null;
|
Drug firstDrug = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
firstMedicament = medicaments.get(0);
|
firstDrug = drugs.get(0);
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e){
|
||||||
Log.e(TAG, e.toString());
|
Log.e(TAG, e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstMedicament != null) {
|
if (firstDrug != null) {
|
||||||
if (firstMedicament.getPrise() != 0) {
|
if (firstDrug.getTake() != 0) {
|
||||||
if(firstMedicament.getStock() < firstMedicament.getAlertThreshold()) {
|
if(firstDrug.getStock() < firstDrug.getAlertThreshold()) {
|
||||||
scheduleNotification();
|
scheduleNotification();
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
double dummy = (firstMedicament.getStock() - firstMedicament.getAlertThreshold());
|
double dummy = (firstDrug.getStock() - firstDrug.getAlertThreshold());
|
||||||
Log.d(TAG, "no notification scheduled " + dummy);
|
Log.d(TAG, "no notification scheduled " + dummy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public class PillDroidJobService extends JobService {
|
||||||
void scheduleNotification() {
|
void scheduleNotification() {
|
||||||
Log.d(TAG, "schedule notification");
|
Log.d(TAG, "schedule notification");
|
||||||
createNotificationChannel();
|
createNotificationChannel();
|
||||||
Intent intent = new Intent(this, MedicamentListActivity.class);
|
Intent intent = new Intent(this, DrugListActivity.class);
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,0);
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,0);
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "PillDroid")
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "PillDroid")
|
||||||
.setSmallIcon(R.drawable.ic_pill_alarm)
|
.setSmallIcon(R.drawable.ic_pill_alarm)
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class WelcomeActivity extends AppCompatActivity {
|
||||||
|
|
||||||
void launchHomeScreen() {
|
void launchHomeScreen() {
|
||||||
prefManager.setFirstTimeLaunch(false);
|
prefManager.setFirstTimeLaunch(false);
|
||||||
startActivity(new Intent(WelcomeActivity.this, MedicamentListActivity.class));
|
startActivity(new Intent(WelcomeActivity.this, DrugListActivity.class));
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
android:divider="?android:attr/dividerHorizontal"
|
android:divider="?android:attr/dividerHorizontal"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:showDividers="middle"
|
android:showDividers="middle"
|
||||||
tools:context="net.foucry.pilldroid.MedicamentListActivity">
|
tools:context="net.foucry.pilldroid.DrugListActivity">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
This layout is a two-pane layout for the Medicaments
|
This layout is a two-pane layout for the Medicaments
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
app:layoutManager="LinearLayoutManager"
|
app:layoutManager="LinearLayoutManager"
|
||||||
tools:context="net.foucry.pilldroid.MedicamentListActivity"
|
tools:context="net.foucry.pilldroid.DrugListActivity"
|
||||||
tools:listitem="@layout/medicament_list_content" />
|
tools:listitem="@layout/medicament_list_content" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
android:background="@drawable/list_selector"
|
android:background="@drawable/list_selector"
|
||||||
android:backgroundTint="@android:color/transparent"
|
android:backgroundTint="@android:color/transparent"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
tools:context="net.foucry.pilldroid.MedicamentDetailActivity"
|
tools:context="net.foucry.pilldroid.DrugDetailActivity"
|
||||||
tools:ignore="MergeRootFrame">
|
tools:ignore="MergeRootFrame">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
tools:context=".MedicamentListActivity">
|
tools:context=".DrugListActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/app_bar"
|
android:id="@+id/app_bar"
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
android:background="@drawable/list_selector">
|
android:background="@drawable/list_selector">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/valeur"
|
android:id="@+id/value"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="10sp"
|
android:paddingStart="10sp"
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/label"
|
android:text="@string/label"
|
||||||
android:layout_below="@+id/valeur"
|
android:layout_below="@+id/value"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:textStyle="italic"
|
android:textStyle="italic"
|
||||||
android:textColor="#0c4758"
|
android:textColor="#0c4758"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context="net.foucry.pilldroid.MedicamentDetailFragment">
|
tools:context="net.foucry.pilldroid.DrugDetailFragment">
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/name_cell"
|
android:id="@+id/name_cell"
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
android:layout_marginTop="30sp" />
|
android:layout_marginTop="30sp" />
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/prise_cell"
|
android:id="@+id/take_cell"
|
||||||
layout="@layout/value_input"
|
layout="@layout/value_input"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
|
@ -8,5 +8,5 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layoutManager="LinearLayoutManager"
|
app:layoutManager="LinearLayoutManager"
|
||||||
android:background="@drawable/list_selector"
|
android:background="@drawable/list_selector"
|
||||||
tools:context="net.foucry.pilldroid.MedicamentListActivity"
|
tools:context="net.foucry.pilldroid.DrugListActivity"
|
||||||
tools:listitem="@layout/medicament_list_content" />
|
tools:listitem="@layout/medicament_list_content" />
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
android:layout_alignParentStart="true" />
|
android:layout_alignParentStart="true" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/valeur"
|
android:id="@+id/value"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/nom_m_dicament"
|
android:text="@string/nom_m_dicament"
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
android:textColor="#343434"
|
android:textColor="#343434"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:text="@string/cip13_goes_here"
|
android:text="@string/cip13_goes_here"
|
||||||
android:layout_below="@+id/valeur"
|
android:layout_below="@+id/value"
|
||||||
android:layout_toEndOf="@+id/list_image"
|
android:layout_toEndOf="@+id/list_image"
|
||||||
android:layout_marginStart="5dp" />
|
android:layout_marginStart="5dp" />
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
android:background="@drawable/list_selector"
|
android:background="@drawable/list_selector"
|
||||||
android:weightSum="1">
|
android:weightSum="1">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/libelle"
|
android:id="@+id/label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignBottom="@+id/valeur"
|
android:layout_alignBottom="@+id/value"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_toStartOf="@id/valeur"
|
android:layout_toStartOf="@id/value"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:paddingStart="5dp"
|
android:paddingStart="5dp"
|
||||||
android:paddingEnd="25dp"
|
android:paddingEnd="25dp"
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/valeur"
|
android:id="@+id/value"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:gravity="end|fill_vertical"
|
android:gravity="end|fill_vertical"
|
||||||
android:inputType="numberDecimal"
|
android:inputType="numberDecimal"
|
||||||
android:labelFor="@id/valeur"
|
android:labelFor="@id/value"
|
||||||
android:paddingEnd="25dp"
|
android:paddingEnd="25dp"
|
||||||
android:paddingStart="5dp"
|
android:paddingStart="5dp"
|
||||||
android:hint="@string/zero"
|
android:hint="@string/zero"
|
||||||
|
|
|
@ -68,11 +68,11 @@
|
||||||
<string name="next">Next</string>
|
<string name="next">Next</string>
|
||||||
<string name="start">Start</string>
|
<string name="start">Start</string>
|
||||||
<string name="zero" translatable="false">0</string>
|
<string name="zero" translatable="false">0</string>
|
||||||
<string name="add_button">Add new medicament in list</string>
|
<string name="add_button">Add new drug in list</string>
|
||||||
<string name="nom_m_dicament">Drug Name</string>
|
<string name="nom_m_dicament">Drug Name</string>
|
||||||
<string name="icone_de_stock">Stock Icon</string>
|
<string name="icone_de_stock">Stock Icon</string>
|
||||||
<string name="cip13_goes_here">cip13 goes here</string>
|
<string name="cip13_goes_here">cip13 goes here</string>
|
||||||
<string name="Date">lundi 1 janvier 2001</string>
|
<string name="Date">Monday January 1st 2001</string>
|
||||||
<string name="Value">Value</string>
|
<string name="Value">Value</string>
|
||||||
<string name="label">Label</string>
|
<string name="label">Label</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package net.foucry.pilldroid;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To work on unit tests, switch the Test Artifact in the Build Variants view.
|
|
||||||
*/
|
|
||||||
public class ExampleUnitTest {
|
|
||||||
@Test
|
|
||||||
public void addition_isCorrect() throws Exception {
|
|
||||||
assertEquals(4, 2 + 2);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue