This commit is contained in:
Jacques Foucry 2016-08-16 09:53:28 +02:00
commit edd62d4b6b
2 changed files with 27 additions and 1 deletions

View file

@ -25,6 +25,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
@ -71,6 +72,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();
@ -91,6 +96,27 @@ public class MedicamentListActivity extends AppCompatActivity {
public void onStop() {
super.onStop();
Calendar calendar = Calendar.getInstance();
Date now = calendar.getTime();
long dateSchedule;
Medicament firstMedicament = medicaments.get(0);
Date dateAlerte = UtilDate.removeDaysToDate(firstMedicament.getAlertThreshold(), firstMedicament.getDateEndOfStock());
if (dateAlerte.getTime() < now.getTime())
{
dateSchedule = 120000;
} else {
dateSchedule = dateAlerte.getTime() - now.getTime();
}
// int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
scheduleNotification(getNotification("Vous devez passer à la pharmacie."), 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.
Action viewAction = Action.newAction(

View file

@ -107,7 +107,7 @@ public class UtilDate {
}
public static String convertDate(long dateInMilliseconds) {
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
DateFormat formatter = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(dateInMilliseconds);
return formatter.format(calendar.getTime());