mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 20:59:00 +00:00
Fix reminders not showing if not previously marked as complete
This commit is contained in:
parent
4afc8a8238
commit
798fa1a330
2 changed files with 20 additions and 19 deletions
|
|
@ -75,10 +75,9 @@ class TaskAlarmManager(
|
|||
}
|
||||
|
||||
private fun setTimeForDailyReminder(remindersItem: RemindersItem?, task: Task): RemindersItem? {
|
||||
val oldTime = remindersItem?.time
|
||||
val newTime = (task.getNextReminderOccurence(oldTime) ?: return null)
|
||||
val newTime = (remindersItem?.let { task.getNextReminderOccurrence(it) } ?: return null)
|
||||
|
||||
remindersItem?.time = newTime.withZoneSameLocal(ZoneId.systemDefault()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
||||
remindersItem.time = newTime.withZoneSameLocal(ZoneId.systemDefault()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
||||
|
||||
return remindersItem
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,24 +202,26 @@ open class Task : RealmObject, BaseMainObject, Parcelable, BaseTask {
|
|||
|
||||
fun checkIfDue(): Boolean = isDue == true
|
||||
|
||||
fun getNextReminderOccurence(oldTime: String?): ZonedDateTime? {
|
||||
if (oldTime == null) {
|
||||
return null
|
||||
}
|
||||
val nextDate = nextDue?.firstOrNull()
|
||||
fun getNextReminderOccurrence(remindersItem: RemindersItem): ZonedDateTime? {
|
||||
remindersItem.time?.let {
|
||||
val oldTime = it
|
||||
val now = ZonedDateTime.now().withZoneSameLocal(ZoneId.systemDefault())?.toInstant()
|
||||
val nextDate = nextDue?.firstOrNull()
|
||||
|
||||
return if (nextDate != null && !isDisplayedActive) {
|
||||
val nextDueCalendar = GregorianCalendar()
|
||||
nextDueCalendar.time = nextDate
|
||||
parse(oldTime)
|
||||
?.withYear(nextDueCalendar.get(Calendar.YEAR))
|
||||
?.withMonth(nextDueCalendar.get(Calendar.MONTH))
|
||||
?.withDayOfMonth(nextDueCalendar.get(Calendar.DAY_OF_MONTH))
|
||||
} else if (isDisplayedActive) {
|
||||
parse(oldTime)
|
||||
} else {
|
||||
null
|
||||
//If task !isDisplayedActive or if isDisplayedActive but reminder passed,
|
||||
//set a updated reminder with nextDate
|
||||
return if (nextDate != null && (!isDisplayedActive || remindersItem.getLocalZonedDateTimeInstant()?.isBefore(now) == true)) {
|
||||
val nextDueCalendar = GregorianCalendar()
|
||||
nextDueCalendar.time = nextDate
|
||||
parse(oldTime)
|
||||
?.withYear(nextDueCalendar.get(Calendar.YEAR))
|
||||
?.withMonth(nextDueCalendar.get(Calendar.MONTH) + 1) //+1 to handle Gregorian Calendar month range from 0-11
|
||||
?.withDayOfMonth(nextDueCalendar.get(Calendar.DAY_OF_MONTH))
|
||||
} else {
|
||||
return parse(oldTime)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun formatter(): DateTimeFormatter =
|
||||
|
|
|
|||
Loading…
Reference in a new issue