mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-18 02:51:38 +01:00
Notification programmée pour le premier médicament qui arrive en fin de stock, à la date de fin de stock (le calcul n'\''est pas correct)
Changement définition du TAG des logs
This commit is contained in:
parent
df01e9b8b7
commit
390f620ca4
4 changed files with 45 additions and 40 deletions
|
@ -34,6 +34,8 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private static DBHelper sInstance;
|
private static DBHelper sInstance;
|
||||||
|
|
||||||
|
private static final String TAG = DBHelper.class.getName();
|
||||||
|
|
||||||
private static final String[] COLUMS = {KEY_ID, KEY_CIS,KEY_CIP13, KEY_NAME, KEY_ADMIN, KEY_PRES, KEY_STOCK, KEY_PRISE,
|
private static final String[] COLUMS = {KEY_ID, KEY_CIS,KEY_CIP13, KEY_NAME, KEY_ADMIN, KEY_PRES, KEY_STOCK, KEY_PRISE,
|
||||||
KEY_SEUIL_WARN, KEY_SEUIL_ALERT};
|
KEY_SEUIL_WARN, KEY_SEUIL_ALERT};
|
||||||
|
|
||||||
|
@ -76,7 +78,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public void dropDrug() {
|
public void dropDrug() {
|
||||||
SQLiteDatabase db = this.getWritableDatabase();
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "Drop drug table");
|
Log.d(TAG, "Drop drug table");
|
||||||
db.execSQL("DROP TABLE IF EXISTS drug");
|
db.execSQL("DROP TABLE IF EXISTS drug");
|
||||||
|
|
||||||
this.onCreate(db);
|
this.onCreate(db);
|
||||||
|
@ -84,7 +86,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public void addDrug(Medicament medicament) {
|
public void addDrug(Medicament medicament) {
|
||||||
// Logging
|
// Logging
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, medicament.toString());
|
Log.d(TAG, medicament.toString());
|
||||||
|
|
||||||
// Get reference to writable DB
|
// Get reference to writable DB
|
||||||
SQLiteDatabase db = this.getWritableDatabase();
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
@ -144,7 +146,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "getDrug("+id+")" + medicament.toString());
|
Log.d(TAG, "getDrug("+id+")" + medicament.toString());
|
||||||
|
|
||||||
// Return medicament
|
// Return medicament
|
||||||
|
|
||||||
|
@ -183,7 +185,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "getDrug("+cip13+")" + medicament.toString());
|
Log.d(TAG, "getDrug("+cip13+")" + medicament.toString());
|
||||||
|
|
||||||
// Return medicament
|
// Return medicament
|
||||||
|
|
||||||
|
@ -225,7 +227,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.close();
|
cursor.close();
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "getAllDrugs " + medicaments.toString());
|
Log.d(TAG, "getAllDrugs " + medicaments.toString());
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return medicaments;
|
return medicaments;
|
||||||
|
@ -269,7 +271,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
db.close();
|
db.close();
|
||||||
|
|
||||||
// log
|
// log
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "delete drug "+medicament.toString());
|
Log.d(TAG, "delete drug "+medicament.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
|
|
|
@ -35,6 +35,8 @@ public class DBMedoc extends SQLiteOpenHelper{
|
||||||
|
|
||||||
private static final String[] COLUMNS_NAMES = {MEDOC_CIS, MEDOC_CIP13, MEDOC_ADMIN, MEDOC_NOM, MEDOC_PRES};
|
private static final String[] COLUMNS_NAMES = {MEDOC_CIS, MEDOC_CIP13, MEDOC_ADMIN, MEDOC_NOM, MEDOC_PRES};
|
||||||
|
|
||||||
|
private static final String TAG = DBMedoc.class.getName();
|
||||||
|
|
||||||
public DBMedoc(Context context) {
|
public DBMedoc(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
this.myContext = context;
|
this.myContext = context;
|
||||||
|
@ -64,7 +66,7 @@ public class DBMedoc extends SQLiteOpenHelper{
|
||||||
|
|
||||||
private boolean checkDatabase() {
|
private boolean checkDatabase() {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.e(MedicamentListActivity.Constants.TAG, "checkDatabase called");
|
Log.e(TAG, "checkDatabase called");
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLiteDatabase checkDB = null;
|
SQLiteDatabase checkDB = null;
|
||||||
|
@ -84,7 +86,7 @@ public class DBMedoc extends SQLiteOpenHelper{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyDatabase() throws IOException {
|
private void copyDatabase() throws IOException {
|
||||||
Log.e(MedicamentListActivity.Constants.TAG, "copyDatabase called");
|
Log.e(TAG, "copyDatabase called");
|
||||||
|
|
||||||
InputStream myInput = myContext.getAssets().open(DATABASE_NAME);
|
InputStream myInput = myContext.getAssets().open(DATABASE_NAME);
|
||||||
String outFileName = DATABASE_PATH + DATABASE_NAME;
|
String outFileName = DATABASE_PATH + DATABASE_NAME;
|
||||||
|
@ -105,7 +107,7 @@ public class DBMedoc extends SQLiteOpenHelper{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openDatabase() throws SQLiteException {
|
public void openDatabase() throws SQLiteException {
|
||||||
Log.e(MedicamentListActivity.Constants.TAG, "openDatabase called");
|
Log.e(TAG, "openDatabase called");
|
||||||
String myPath = DATABASE_PATH + DATABASE_NAME;
|
String myPath = DATABASE_PATH + DATABASE_NAME;
|
||||||
|
|
||||||
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
|
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
|
||||||
|
@ -130,7 +132,7 @@ public class DBMedoc extends SQLiteOpenHelper{
|
||||||
private DBMedoc dbMedoc;
|
private DBMedoc dbMedoc;
|
||||||
|
|
||||||
public Medicament getMedocByCIP13(String cip13) {
|
public Medicament getMedocByCIP13(String cip13) {
|
||||||
Log.e(MedicamentListActivity.Constants.TAG, "getNedocByCIP13 - " + cip13);
|
Log.e(TAG, "getNedocByCIP13 - " + cip13);
|
||||||
|
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
|
|
||||||
|
@ -167,7 +169,7 @@ public class DBMedoc extends SQLiteOpenHelper{
|
||||||
medicament.setAlertThreshold(7);
|
medicament.setAlertThreshold(7);
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "getDrug(" + cip13 + ")" + medicament.toString());
|
Log.d(TAG, "getDrug(" + cip13 + ")" + medicament.toString());
|
||||||
|
|
||||||
// Return medicament
|
// Return medicament
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,8 @@ import com.google.android.gms.appindexing.AppIndex;
|
||||||
import com.google.android.gms.common.api.GoogleApiClient;
|
import com.google.android.gms.common.api.GoogleApiClient;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -92,6 +90,19 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
||||||
|
/* Calendar calendar = Calendar.getInstance();
|
||||||
|
Date now = calendar.getTime();
|
||||||
|
Date tomorrow = UtilDate.getTomorrow();*/
|
||||||
|
|
||||||
|
Medicament firstMedicament = medicaments.get(0);
|
||||||
|
|
||||||
|
long outOfStock = firstMedicament.getDateEndOfStock().getTime();
|
||||||
|
|
||||||
|
// int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
|
||||||
|
scheduleNotification(getNotification("It's today + 10s"), outOfStock);
|
||||||
|
|
||||||
|
Log.d(TAG, "Notification scheduled for "+ firstMedicament.getDateEndOfStock().toString());
|
||||||
|
|
||||||
// ATTENTION: This was auto-generated to implement the App Indexing API.
|
// ATTENTION: This was auto-generated to implement the App Indexing API.
|
||||||
// See https://g.co/AppIndexing/AndroidStudio for more information.
|
// See https://g.co/AppIndexing/AndroidStudio for more information.
|
||||||
Action viewAction = Action.newAction(
|
Action viewAction = Action.newAction(
|
||||||
|
@ -108,10 +119,7 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log TAG String
|
private static final String TAG = MedicamentListActivity.class.getName();
|
||||||
public interface Constants {
|
|
||||||
String TAG = "nef.foucry.pilldroid";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DBHelper dbHelper;
|
private static DBHelper dbHelper;
|
||||||
private static DBMedoc dbMedoc;
|
private static DBMedoc dbMedoc;
|
||||||
|
@ -132,10 +140,6 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_medicament_list);
|
setContentView(R.layout.activity_medicament_list);
|
||||||
|
|
||||||
// Register for alarm
|
|
||||||
|
|
||||||
// RegisterAlarmBroadcast();
|
|
||||||
|
|
||||||
dbHelper = new DBHelper(this);
|
dbHelper = new DBHelper(this);
|
||||||
dbMedoc = new DBMedoc(this);
|
dbMedoc = new DBMedoc(this);
|
||||||
|
|
||||||
|
@ -235,21 +239,16 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
/*Calendar calendar = Calendar.getInstance();
|
||||||
Date now = calendar.getTime();
|
Date now = calendar.getTime();
|
||||||
Date tomorrow = UtilDate.getTomorrow();
|
Date tomorrow = UtilDate.getTomorrow();
|
||||||
|
|
||||||
int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
|
//int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
|
||||||
scheduleNotification(getNotification("It's tomorrow At 12"), between2DateInMillis);
|
scheduleNotification(getNotification("It's today +20s"), 20000);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "Notification scheduled");
|
Log.d(TAG, "Notification scheduled");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* protected void onDestroy() {
|
|
||||||
unregisterReceiver(mReceiver);
|
|
||||||
super.onDestroy();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public void scanNow(View view) {
|
public void scanNow(View view) {
|
||||||
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
|
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
|
||||||
//intent.putExtra("SCAN_MODE", "CODE_128");
|
//intent.putExtra("SCAN_MODE", "CODE_128");
|
||||||
|
@ -264,8 +263,8 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
String contents = intent.getStringExtra("SCAN_RESULT");
|
String contents = intent.getStringExtra("SCAN_RESULT");
|
||||||
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
|
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
|
||||||
Log.i(Constants.TAG, "Format:" + format);
|
Log.i(TAG, "Format:" + format);
|
||||||
Log.i(Constants.TAG, "Content:" + contents);
|
Log.i(TAG, "Content:" + contents);
|
||||||
|
|
||||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||||
dlg.setTitle(context.getString(R.string.app_name));
|
dlg.setTitle(context.getString(R.string.app_name));
|
||||||
|
@ -351,6 +350,7 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
} catch (final PackageManager.NameNotFoundException e) {}
|
} catch (final PackageManager.NameNotFoundException e) {}
|
||||||
return (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");
|
return (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimpleItemRecyclerViewAdapter
|
* SimpleItemRecyclerViewAdapter
|
||||||
*/
|
*/
|
||||||
|
@ -381,11 +381,11 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE d MMMM yyyy", Locale.getDefault());
|
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE d MMMM yyyy", Locale.getDefault());
|
||||||
String dateEndOfStock = date2String(mValues.get(position).getDateEndOfStock(), dateFormat);
|
String dateEndOfStock = date2String(mValues.get(position).getDateEndOfStock(), dateFormat);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "dateEndOfStock == " + dateEndOfStock);
|
Log.d(TAG, "dateEndOfStock == " + dateEndOfStock);
|
||||||
Log.d(Constants.TAG, "stock == " + mValues.get(position).getStock());
|
Log.d(TAG, "stock == " + mValues.get(position).getStock());
|
||||||
Log.d(Constants.TAG, "prise == " + mValues.get(position).getPrise());
|
Log.d(TAG, "prise == " + mValues.get(position).getPrise());
|
||||||
Log.d(Constants.TAG, "warn == " + mValues.get(position).getWarnThreshold());
|
Log.d(TAG, "warn == " + mValues.get(position).getWarnThreshold());
|
||||||
Log.d(Constants.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());
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Date;
|
||||||
*/
|
*/
|
||||||
public class UtilDate {
|
public class UtilDate {
|
||||||
|
|
||||||
|
private static final String TAG = UtilDate.class.getName();
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param aDate
|
* @param aDate
|
||||||
|
@ -21,7 +22,7 @@ public class UtilDate {
|
||||||
*/
|
*/
|
||||||
public static Date dateAtNoon(Date aDate) {
|
public static Date dateAtNoon(Date aDate) {
|
||||||
|
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "dateAtNoon " + aDate);
|
Log.d(TAG, "dateAtNoon " + aDate);
|
||||||
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(aDate);
|
calendar.setTime(aDate);
|
||||||
|
@ -37,7 +38,7 @@ public class UtilDate {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static Date getTomorrow() {
|
public static Date getTomorrow() {
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "tomorrow");
|
Log.d(TAG, "tomorrow");
|
||||||
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.add(Calendar.DAY_OF_YEAR,1);
|
calendar.add(Calendar.DAY_OF_YEAR,1);
|
||||||
|
@ -70,7 +71,7 @@ public class UtilDate {
|
||||||
*/
|
*/
|
||||||
public static String date2String(Date date, DateFormat dateFormat) {
|
public static String date2String(Date date, DateFormat dateFormat) {
|
||||||
|
|
||||||
Log.d(MedicamentListActivity.Constants.TAG, "date == " + date);
|
Log.d(TAG, "date == " + date);
|
||||||
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(date);
|
calendar.setTime(date);
|
||||||
|
|
Loading…
Reference in a new issue