From 188a641018c020cb3311386522cfef6b7f31e473 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Sun, 14 Aug 2016 11:12:15 +0200 Subject: [PATCH] Correction calcul envoie des notifications --- .../pilldroid/MedicamentListActivity.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 1c98bad..074fce9 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -2,6 +2,7 @@ package net.foucry.pilldroid; import android.app.AlarmManager; import android.app.Notification; +import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -72,6 +73,10 @@ public class MedicamentListActivity extends AppCompatActivity { public void onStart() { super.onStart(); + Log.d(TAG, "Remove old notification"); + NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + nm.cancelAll(); + // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. client.connect(); @@ -103,15 +108,15 @@ public class MedicamentListActivity extends AppCompatActivity { if (dateAlerte.getTime() < now.getTime()) { - dateSchedule = now.getTime() + 300000; + dateSchedule = 120000; } else { - dateSchedule = dateAlerte.getTime(); + dateSchedule = dateAlerte.getTime() - now.getTime(); } // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); - scheduleNotification(getNotification("It's today + 10s"), dateSchedule); + scheduleNotification(getNotification("Vous devez passer à la pharmacie."), dateSchedule); - Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule)); + Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(now.getTime() + dateSchedule)); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. @@ -268,7 +273,7 @@ public class MedicamentListActivity extends AppCompatActivity { public void onActivityResult(int requestCode, int resultCode, Intent intent) { Context context = getApplicationContext(); - String cip13 = null; + String cip13; if (requestCode == 0) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); @@ -329,7 +334,7 @@ public class MedicamentListActivity extends AppCompatActivity { private void setupRecyclerView(@NonNull RecyclerView recyclerView) { recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext())); - mAdapter = (SimpleItemRecyclerViewAdapter) new SimpleItemRecyclerViewAdapter(medicaments); + mAdapter = new SimpleItemRecyclerViewAdapter(medicaments); recyclerView.setAdapter(mAdapter); } @@ -423,7 +428,7 @@ public class MedicamentListActivity extends AppCompatActivity { holder.mView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Medicament medicamentCourant = (Medicament) mValues.get(position); + Medicament medicamentCourant = mValues.get(position); if (mTwoPane) { Bundle arguments = new Bundle(); arguments.putSerializable("medicament", medicamentCourant);