diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 635de09..fdd5ac5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index 1aeb4c7..b114876 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -37,20 +37,20 @@ public class AlarmReceiver extends BroadcastReceiver { Date tomorrow; LocalTime todayNow = LocalTime.now(); - /*if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG) { Date nextSchedule = calendar.getTime(); calendar.setTimeInMillis(nextSchedule.getTime()); - } else {*/ - calendar.set(Calendar.HOUR_OF_DAY, 11); - today = calendar.getTime(); - calendar.add(Calendar.DAY_OF_YEAR, 1); - tomorrow = calendar.getTime(); - if (todayNow.isBefore(LocalTime.NOON)) { - calendar.setTimeInMillis(today.getTime()); } else { - calendar.setTimeInMillis(tomorrow.getTime()); + calendar.set(Calendar.HOUR_OF_DAY, 11); + today = calendar.getTime(); + calendar.add(Calendar.DAY_OF_YEAR, 1); + tomorrow = calendar.getTime(); + if (todayNow.isBefore(LocalTime.NOON)) { + calendar.setTimeInMillis(today.getTime()); + } else { + calendar.setTimeInMillis(tomorrow.getTime()); + } } - //} PendingIntent alarmIntent; @@ -59,14 +59,14 @@ public class AlarmReceiver extends BroadcastReceiver { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - /*if (BuildConfig.DEBUG) { + if (BuildConfig.DEBUG) { alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()), AlarmManager.ELAPSED_REALTIME, alarmIntent); - } else {*/ + } else { - alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, (calendar.getTimeInMillis()), - AlarmManager.INTERVAL_DAY, alarmIntent); - //} + alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, (calendar.getTimeInMillis()), + AlarmManager.INTERVAL_DAY, alarmIntent); + } Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis())); if (BuildConfig.DEBUG) { diff --git a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java index 75df514..b4799b8 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java @@ -164,8 +164,12 @@ public class Prescription implements Serializable { }*/ if (numberOfDays > 0) { + float currentStock = 0; + float newStock = 0; double takeDuringPeriod = this.take * numberOfDays; - setStock((float) (getStock() - takeDuringPeriod)); + currentStock = getStock(); + newStock = (float) (currentStock - takeDuringPeriod); + setStock((float) newStock); setLast_update(new Date().getTime()); } }