Correction calcul envoie des notifications

This commit is contained in:
Jacques Foucry 2016-08-14 11:12:15 +02:00
parent e148350ffd
commit 188a641018

View file

@ -2,6 +2,7 @@ package net.foucry.pilldroid;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@ -72,6 +73,10 @@ public class MedicamentListActivity extends AppCompatActivity {
public void onStart() { public void onStart() {
super.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. // 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.
client.connect(); client.connect();
@ -103,15 +108,15 @@ public class MedicamentListActivity extends AppCompatActivity {
if (dateAlerte.getTime() < now.getTime()) if (dateAlerte.getTime() < now.getTime())
{ {
dateSchedule = now.getTime() + 300000; dateSchedule = 120000;
} else { } else {
dateSchedule = dateAlerte.getTime(); dateSchedule = dateAlerte.getTime() - now.getTime();
} }
// int between2DateInMillis = (int) (tomorrow.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. // 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.
@ -268,7 +273,7 @@ public class MedicamentListActivity extends AppCompatActivity {
public void onActivityResult(int requestCode, int resultCode, Intent intent) { public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Context context = getApplicationContext(); Context context = getApplicationContext();
String cip13 = null; String cip13;
if (requestCode == 0) { if (requestCode == 0) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT"); String contents = intent.getStringExtra("SCAN_RESULT");
@ -329,7 +334,7 @@ public class MedicamentListActivity extends AppCompatActivity {
private void setupRecyclerView(@NonNull RecyclerView recyclerView) { private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext())); recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
mAdapter = (SimpleItemRecyclerViewAdapter) new SimpleItemRecyclerViewAdapter(medicaments); mAdapter = new SimpleItemRecyclerViewAdapter(medicaments);
recyclerView.setAdapter(mAdapter); recyclerView.setAdapter(mAdapter);
} }
@ -423,7 +428,7 @@ 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 = (Medicament) mValues.get(position); Medicament medicamentCourant = mValues.get(position);
if (mTwoPane) { if (mTwoPane) {
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
arguments.putSerializable("medicament", medicamentCourant); arguments.putSerializable("medicament", medicamentCourant);