From 390f620ca4bc1b3fad0f973d2699967428e7c968 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Wed, 10 Aug 2016 21:03:28 +0200 Subject: [PATCH] =?UTF-8?q?Notification=20programm=C3=A9e=20pour=20le=20pr?= =?UTF-8?q?emier=20m=C3=A9dicament=20qui=20arrive=20en=20fin=20de=20stock,?= =?UTF-8?q?=20=C3=A0=20la=20date=20de=20fin=20de=20stock=20(le=20calcul=20?= =?UTF-8?q?n'\''est=20pas=20correct)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changement définition du TAG des logs --- .../java/net/foucry/pilldroid/DBHelper.java | 14 ++--- .../java/net/foucry/pilldroid/DBMedoc.java | 12 +++-- .../pilldroid/MedicamentListActivity.java | 52 +++++++++---------- .../java/net/foucry/pilldroid/UtilDate.java | 7 +-- 4 files changed, 45 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java index cfc065d..12f13ca 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java +++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java @@ -34,6 +34,8 @@ public class DBHelper extends SQLiteOpenHelper { 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, KEY_SEUIL_WARN, KEY_SEUIL_ALERT}; @@ -76,7 +78,7 @@ public class DBHelper extends SQLiteOpenHelper { public void dropDrug() { 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"); this.onCreate(db); @@ -84,7 +86,7 @@ public class DBHelper extends SQLiteOpenHelper { public void addDrug(Medicament medicament) { // Logging - Log.d(MedicamentListActivity.Constants.TAG, medicament.toString()); + Log.d(TAG, medicament.toString()); // Get reference to writable DB SQLiteDatabase db = this.getWritableDatabase(); @@ -144,7 +146,7 @@ public class DBHelper extends SQLiteOpenHelper { medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); // Log - Log.d(MedicamentListActivity.Constants.TAG, "getDrug("+id+")" + medicament.toString()); + Log.d(TAG, "getDrug("+id+")" + medicament.toString()); // Return medicament @@ -183,7 +185,7 @@ public class DBHelper extends SQLiteOpenHelper { medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); // Log - Log.d(MedicamentListActivity.Constants.TAG, "getDrug("+cip13+")" + medicament.toString()); + Log.d(TAG, "getDrug("+cip13+")" + medicament.toString()); // Return medicament @@ -225,7 +227,7 @@ public class DBHelper extends SQLiteOpenHelper { } cursor.close(); - Log.d(MedicamentListActivity.Constants.TAG, "getAllDrugs " + medicaments.toString()); + Log.d(TAG, "getAllDrugs " + medicaments.toString()); // return return medicaments; @@ -269,7 +271,7 @@ public class DBHelper extends SQLiteOpenHelper { db.close(); // log - Log.d(MedicamentListActivity.Constants.TAG, "delete drug "+medicament.toString()); + Log.d(TAG, "delete drug "+medicament.toString()); } public int getCount() { diff --git a/app/src/main/java/net/foucry/pilldroid/DBMedoc.java b/app/src/main/java/net/foucry/pilldroid/DBMedoc.java index a446765..8aee11e 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBMedoc.java +++ b/app/src/main/java/net/foucry/pilldroid/DBMedoc.java @@ -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 TAG = DBMedoc.class.getName(); + public DBMedoc(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.myContext = context; @@ -64,7 +66,7 @@ public class DBMedoc extends SQLiteOpenHelper{ private boolean checkDatabase() { if (BuildConfig.DEBUG) { - Log.e(MedicamentListActivity.Constants.TAG, "checkDatabase called"); + Log.e(TAG, "checkDatabase called"); } SQLiteDatabase checkDB = null; @@ -84,7 +86,7 @@ public class DBMedoc extends SQLiteOpenHelper{ } private void copyDatabase() throws IOException { - Log.e(MedicamentListActivity.Constants.TAG, "copyDatabase called"); + Log.e(TAG, "copyDatabase called"); InputStream myInput = myContext.getAssets().open(DATABASE_NAME); String outFileName = DATABASE_PATH + DATABASE_NAME; @@ -105,7 +107,7 @@ public class DBMedoc extends SQLiteOpenHelper{ } public void openDatabase() throws SQLiteException { - Log.e(MedicamentListActivity.Constants.TAG, "openDatabase called"); + Log.e(TAG, "openDatabase called"); String myPath = DATABASE_PATH + DATABASE_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); @@ -130,7 +132,7 @@ public class DBMedoc extends SQLiteOpenHelper{ private DBMedoc dbMedoc; public Medicament getMedocByCIP13(String cip13) { - Log.e(MedicamentListActivity.Constants.TAG, "getNedocByCIP13 - " + cip13); + Log.e(TAG, "getNedocByCIP13 - " + cip13); SQLiteDatabase db = this.getReadableDatabase(); @@ -167,7 +169,7 @@ public class DBMedoc extends SQLiteOpenHelper{ medicament.setAlertThreshold(7); // Log - Log.d(MedicamentListActivity.Constants.TAG, "getDrug(" + cip13 + ")" + medicament.toString()); + Log.d(TAG, "getDrug(" + cip13 + ")" + medicament.toString()); // Return medicament diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 139f61e..4d2a86a 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -34,10 +34,8 @@ import com.google.android.gms.appindexing.AppIndex; import com.google.android.gms.common.api.GoogleApiClient; import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Collections; import java.util.Comparator; -import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Random; @@ -92,6 +90,19 @@ public class MedicamentListActivity extends AppCompatActivity { public void 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. // See https://g.co/AppIndexing/AndroidStudio for more information. Action viewAction = Action.newAction( @@ -108,10 +119,7 @@ public class MedicamentListActivity extends AppCompatActivity { client.disconnect(); } - // Log TAG String - public interface Constants { - String TAG = "nef.foucry.pilldroid"; - } + private static final String TAG = MedicamentListActivity.class.getName(); private static DBHelper dbHelper; private static DBMedoc dbMedoc; @@ -132,10 +140,6 @@ public class MedicamentListActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_medicament_list); - // Register for alarm - -// RegisterAlarmBroadcast(); - dbHelper = new DBHelper(this); dbMedoc = new DBMedoc(this); @@ -235,21 +239,16 @@ public class MedicamentListActivity extends AppCompatActivity { public void onPause() { super.onPause(); - Calendar calendar = Calendar.getInstance(); + /*Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); Date tomorrow = UtilDate.getTomorrow(); - int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); - scheduleNotification(getNotification("It's tomorrow At 12"), between2DateInMillis); + //int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); + 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) { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); //intent.putExtra("SCAN_MODE", "CODE_128"); @@ -264,8 +263,8 @@ public class MedicamentListActivity extends AppCompatActivity { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); - Log.i(Constants.TAG, "Format:" + format); - Log.i(Constants.TAG, "Content:" + contents); + Log.i(TAG, "Format:" + format); + Log.i(TAG, "Content:" + contents); AlertDialog.Builder dlg = new AlertDialog.Builder(this); dlg.setTitle(context.getString(R.string.app_name)); @@ -351,6 +350,7 @@ public class MedicamentListActivity extends AppCompatActivity { } catch (final PackageManager.NameNotFoundException e) {} return (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???"); } + /** * SimpleItemRecyclerViewAdapter */ @@ -381,11 +381,11 @@ public class MedicamentListActivity extends AppCompatActivity { SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE d MMMM yyyy", Locale.getDefault()); String dateEndOfStock = date2String(mValues.get(position).getDateEndOfStock(), dateFormat); - Log.d(Constants.TAG, "dateEndOfStock == " + dateEndOfStock); - Log.d(Constants.TAG, "stock == " + mValues.get(position).getStock()); - Log.d(Constants.TAG, "prise == " + mValues.get(position).getPrise()); - Log.d(Constants.TAG, "warn == " + mValues.get(position).getWarnThreshold()); - Log.d(Constants.TAG, "alert == " + mValues.get(position).getAlertThreshold()); + Log.d(TAG, "dateEndOfStock == " + dateEndOfStock); + Log.d(TAG, "stock == " + mValues.get(position).getStock()); + Log.d(TAG, "prise == " + mValues.get(position).getPrise()); + Log.d(TAG, "warn == " + mValues.get(position).getWarnThreshold()); + Log.d(TAG, "alert == " + mValues.get(position).getAlertThreshold()); holder.mItem = mValues.get(position); holder.mIDView.setText(mValues.get(position).getCip13()); diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index 434a25b..29c60eb 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -12,6 +12,7 @@ import java.util.Date; */ public class UtilDate { + private static final String TAG = UtilDate.class.getName(); /** * * @param aDate @@ -21,7 +22,7 @@ public class UtilDate { */ public static Date dateAtNoon(Date aDate) { - Log.d(MedicamentListActivity.Constants.TAG, "dateAtNoon " + aDate); + Log.d(TAG, "dateAtNoon " + aDate); Calendar calendar = Calendar.getInstance(); calendar.setTime(aDate); @@ -37,7 +38,7 @@ public class UtilDate { */ public static Date getTomorrow() { - Log.d(MedicamentListActivity.Constants.TAG, "tomorrow"); + Log.d(TAG, "tomorrow"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR,1); @@ -70,7 +71,7 @@ public class UtilDate { */ 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.setTime(date);