Skip to content

Commit

Permalink
Medications successfully restore after forced stop
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamGuidarini committed Aug 7, 2022
1 parent 56bb782 commit 35fa199
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static void setCardParams(CardView cardView)
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
cardView.setLayoutParams(layoutParams);
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) cardView.getLayoutParams();
marginLayoutParams.setMargins(25, 40, 25, 20);
marginLayoutParams.setMargins(25, 40, 10, 10);
cardView.requestLayout();
cardView.setRadius(30);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,7 @@ private void clearPreviousNotifications()
}
else
{
long[] ids = db.getMedicationTimeIds(medication);

for (long id : ids)
for (long id : medIds)
{
NotificationHelper.deletePendingNotification(id * -1, this);
}
Expand Down
44 changes: 37 additions & 7 deletions app/src/main/java/projects/medicationtracker/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;

public class MainActivity extends AppCompatActivity
Expand All @@ -53,7 +54,7 @@ protected void onCreate(Bundle savedInstanceState)
Objects.requireNonNull(getSupportActionBar()).setTitle("Medication Schedule");

NotificationHelper.createNotificationChannel(this);
// prepareNotifications();
prepareNotifications();

createMainActivityViews();
}
Expand Down Expand Up @@ -467,18 +468,47 @@ private void prepareNotifications()

for (Medication medication : medications)
{
LocalTime[] times = db.getMedicationTimes(medication.getMedId());
long[] timeIds = db.getMedicationTimeIds(medication);
long[] medicationTimeIds = db.getMedicationTimeIds(medication);

for (int i = 0; i < times.length; i++)
if (medication.getMedFrequency() == 1440)
{
NotificationHelper.deletePendingNotification(medication.getMedId(), this);

}
else
{
for (int i = 0; i < medicationTimeIds.length; i++)
{
NotificationHelper.deletePendingNotification(medicationTimeIds[i], this);
}
}
}

for (Medication medication : medications)
{
long[] medicationTimeIds = db.getMedicationTimeIds(medication);

if (medication.getMedFrequency() == 1440)
{
NotificationHelper.scheduleNotification(
this,
getApplicationContext(),
medication,
LocalDateTime.of(medication.getStartDate().toLocalDate(), times[i]),
times.length > 1 ? timeIds[i] * -1 : medication.getMedId()
LocalDateTime.of(LocalDate.now(), medication.getTimes()[0].toLocalTime()),
medication.getMedId()
);
}
else
{
for (int i = 0; i < medicationTimeIds.length; i++)
{
NotificationHelper.scheduleNotification(
getApplicationContext(),
medication,
LocalDateTime.of(LocalDate.now(), medication.getTimes()[i].toLocalTime()),
medicationTimeIds[i] * -1
);
}
}
}
}

Expand Down

0 comments on commit 35fa199

Please sign in to comment.