Tentative avec 1 heure de décalage

This commit is contained in:
Jacques Foucry 2016-11-03 13:57:19 +01:00
parent 3faec26a70
commit 0b1da8a65e
3 changed files with 10 additions and 25 deletions

View file

@ -48,6 +48,7 @@ import java.util.Locale;
import java.util.Random; import java.util.Random;
import java.util.logging.Handler; import java.util.logging.Handler;
import static net.foucry.pilldroid.NotificationPublisher.NOTIFICATION_ID;
import static net.foucry.pilldroid.UtilDate.date2String; import static net.foucry.pilldroid.UtilDate.date2String;
import static net.foucry.pilldroid.Utils.doubleRandomInclusive; import static net.foucry.pilldroid.Utils.doubleRandomInclusive;
@ -268,26 +269,6 @@ public class MedicamentListActivity extends AppCompatActivity {
super.onPause(); super.onPause();
newStockCalculation(); newStockCalculation();
/* 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 = now.getTime() + 10000;
} else {
dateSchedule = dateAlerte.getTime();
}
// int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
scheduleNotification(getNotification(getString(R.string.notification_text)), 10000);
Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule));*/
} }
/** scanNow /** scanNow
@ -306,6 +287,7 @@ public class MedicamentListActivity extends AppCompatActivity {
* Calculation of newStock * Calculation of newStock
*/ */
public void newStockCalculation() { public void newStockCalculation() {
Medicament currentMedicament; Medicament currentMedicament;
for (int position = 0 ; position < this. getCount() ; position++ ) { for (int position = 0 ; position < this. getCount() ; position++ ) {
currentMedicament = this.getItem(position); currentMedicament = this.getItem(position);
@ -327,13 +309,13 @@ public class MedicamentListActivity extends AppCompatActivity {
if (dateAlerte.getTime() < now.getTime()) if (dateAlerte.getTime() < now.getTime())
{ {
dateSchedule = now.getTime() + 10000; // If dateAlerte < now we schedule an alert for now + 5 seconds dateSchedule = now.getTime() + 3600000; // If dateAlerte < now we schedule an alert for now + 5 seconds (3600000 pour 1 heure)
} else { } else {
dateSchedule = dateAlerte.getTime(); // If dateAlerte > now we use dateAlerte as scheduleDate dateSchedule = dateAlerte.getTime(); // If dateAlerte > now we use dateAlerte as scheduleDate
} }
// int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime()); // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
scheduleNotification(getNotification(getString(R.string.notification_text)), dateSchedule); scheduleNotification(getNotification(getString(R.string.notification_text)),3600000);
Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule)); Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule));
} }
@ -409,7 +391,7 @@ public class MedicamentListActivity extends AppCompatActivity {
Log.i(TAG, "scheduleNotification delay == " + delay); Log.i(TAG, "scheduleNotification delay == " + delay);
Intent notificationIntent = new Intent(this, NotificationPublisher.class); Intent notificationIntent = new Intent(this, NotificationPublisher.class);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, 1); notificationIntent.putExtra(NOTIFICATION_ID, 1);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification); notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

View file

@ -8,16 +8,19 @@ import android.content.Intent;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.Log; import android.util.Log;
import static android.support.v7.widget.StaggeredGridLayoutManager.TAG;
/** /**
* Created by jfoucry on 6/23/16. * Created by jfoucry on 6/23/16.
*/ */
public class NotificationPublisher extends BroadcastReceiver { public class NotificationPublisher extends BroadcastReceiver {
private static String TAG = Thread.currentThread().getStackTrace()[1].getMethodName();
public static String NOTIFICATION_ID = "notification-id"; public static String NOTIFICATION_ID = "notification-id";
public static String NOTIFICATION = "notification"; public static String NOTIFICATION = "notification";
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive"); Log.i(TAG, "");
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

View file

@ -18,7 +18,7 @@ public class PillDroidJobService extends JobService {
@Override @Override
public boolean handleMessage(Message msg) { public boolean handleMessage(Message msg) {
// Toast.makeText( getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show(); // Toast.makeText( getApplicationContext(), "PillDroid - Calcul nouveau stocks", Toast.LENGTH_SHORT).show();
MedicamentListActivity.newStockCalculation(getApplicationContext()); // MedicamentListActivity.newStockCalculation(getApplicationContext());
jobFinished( (JobParameters) msg.obj,false); jobFinished( (JobParameters) msg.obj,false);
return true; return true;