Skip to content

Commit

Permalink
fix: [ANDROAPP-6644] invoke onDateValue changed after sdk update requ…
Browse files Browse the repository at this point in the history
…est, set overdue correctly from repository
  • Loading branch information
xavimolloy authored and mmmateos committed Nov 26, 2024
1 parent a7eff18 commit 8887820
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class TEIDataModule(
d2: D2,
periodUtils: DhisPeriodUtils,
metadataIconProvider: MetadataIconProvider,
dateUtils: DateUtils,
): TeiDataRepository {
return TeiDataRepositoryImpl(
d2,
Expand All @@ -100,6 +101,7 @@ class TEIDataModule(
enrollmentUid,
periodUtils,
metadataIconProvider,
dateUtils,
)
}

Expand Down Expand Up @@ -192,5 +194,5 @@ class TEIDataModule(
fun provideD2ErrorUtils() = D2ErrorUtils(view.context, NetworkUtils(view.context))

@Provides
fun provideDateUtils() = DateUtils.getInstance()
fun provideDateUtils(): DateUtils = DateUtils.getInstance()
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TeiDataRepositoryImpl(
private val enrollmentUid: String?,
private val periodUtils: DhisPeriodUtils,
private val metadataIconProvider: MetadataIconProvider,
private val dateUtils: DateUtils,
) : TeiDataRepository {

override fun getTEIEnrollmentEvents(
Expand Down Expand Up @@ -379,7 +380,7 @@ class TeiDataRepositoryImpl(
private fun checkEventStatus(events: List<Event>): List<Event> {
return events.mapNotNull { event ->
if (event.status() == EventStatus.SCHEDULE &&
event.dueDate()?.before(DateUtils.getInstance().today) == true
dateUtils.isEventDueDateOverdue(event.dueDate())
) {
d2.eventModule().events().uid(event.uid()).setStatus(EventStatus.OVERDUE)
d2.eventModule().events().uid(event.uid()).blockingGet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,9 @@ class SchedulingViewModel(
d2.eventModule().events().uid(eventUid).run {
setDueDate(dueDate.currentDate)
setStatus(EventStatus.SCHEDULE)
onDueDateUpdated?.invoke()
}
}

onDueDateUpdated?.invoke()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public Boolean isEventExpired(@Nullable Date currentDate, Date completedDay, int
*/
public Boolean isEventDueDateOverdue(Date dueDate) {
Date currentDate = getStartOfDay(new Date());

if(dueDate.equals(currentDate)) return false;
return dueDate.before(currentDate);
}

Expand Down

0 comments on commit 8887820

Please sign in to comment.