Skip to content

Commit

Permalink
Fixed bug: push date to next day on alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
lhwdev committed Oct 11, 2021
1 parent 33aefd7 commit 3082849
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AlarmReceiver : BroadcastReceiver() {
}

val pref = PreferenceState(context.prefMain())
context.scheduleNextAlarm(context.createIntent(), pref.hour, pref.min, true)
context.scheduleNextAlarm(context.createIntent(), pref.hour, pref.min, pref.isRandomEnabled, nextDay = true)
lock.release()

result.finish()
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/lhwdev/selfTestMacro/selfTestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ fun Context.scheduleNextAlarm(
new[Calendar.MINUTE] = newMin
new[Calendar.SECOND] = 0
new[Calendar.MILLISECOND] = 0
if(nextDay || new <= this) new.add(Calendar.DAY_OF_YEAR, 1)
if(nextDay || new <= this || new[Calendar.DAY_OF_YEAR] == this[Calendar.DAY_OF_YEAR]) {
new.add(Calendar.DAY_OF_YEAR, 1)
}
new
}
selfLog("scheduling next alarm at ${Date.from(newTime.toInstant())}", force = true)
Expand Down

0 comments on commit 3082849

Please sign in to comment.