From e2d5228a7f9eeaa811a70a837b8386bb6a6875c0 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Thu, 11 Aug 2016 17:42:09 +0200 Subject: [PATCH] Nouvelle programmation des notifications --- .../pilldroid/MedicamentListActivity.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 4d2a86a..1c98bad 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -34,8 +34,10 @@ 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; @@ -90,18 +92,26 @@ public class MedicamentListActivity extends AppCompatActivity { public void onStop() { super.onStop(); -/* Calendar calendar = Calendar.getInstance(); + Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); - Date tomorrow = UtilDate.getTomorrow();*/ + + long dateSchedule; Medicament firstMedicament = medicaments.get(0); - long outOfStock = firstMedicament.getDateEndOfStock().getTime(); + Date dateAlerte = UtilDate.removeDaysToDate(firstMedicament.getAlertThreshold(), firstMedicament.getDateEndOfStock()); + + if (dateAlerte.getTime() < now.getTime()) + { + dateSchedule = now.getTime() + 300000; + } else { + dateSchedule = dateAlerte.getTime(); + } // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); - scheduleNotification(getNotification("It's today + 10s"), outOfStock); + scheduleNotification(getNotification("It's today + 10s"), dateSchedule); - Log.d(TAG, "Notification scheduled for "+ firstMedicament.getDateEndOfStock().toString()); + Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule)); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information.