diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataModule.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataModule.kt index 5dc9bde68f..fa34d5a7d6 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataModule.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataModule.kt @@ -92,6 +92,7 @@ class TEIDataModule( d2: D2, periodUtils: DhisPeriodUtils, metadataIconProvider: MetadataIconProvider, + dateUtils: DateUtils, ): TeiDataRepository { return TeiDataRepositoryImpl( d2, @@ -100,6 +101,7 @@ class TEIDataModule( enrollmentUid, periodUtils, metadataIconProvider, + dateUtils, ) } @@ -192,5 +194,5 @@ class TEIDataModule( fun provideD2ErrorUtils() = D2ErrorUtils(view.context, NetworkUtils(view.context)) @Provides - fun provideDateUtils() = DateUtils.getInstance() + fun provideDateUtils(): DateUtils = DateUtils.getInstance() } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TeiDataRepositoryImpl.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TeiDataRepositoryImpl.kt index 7e8227b954..c5897d2486 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TeiDataRepositoryImpl.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TeiDataRepositoryImpl.kt @@ -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( @@ -379,7 +380,7 @@ class TeiDataRepositoryImpl( private fun checkEventStatus(events: List): List { 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() diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dialogs/scheduling/SchedulingViewModel.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dialogs/scheduling/SchedulingViewModel.kt index 9c2070b1d4..28a9d8017b 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dialogs/scheduling/SchedulingViewModel.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dialogs/scheduling/SchedulingViewModel.kt @@ -215,10 +215,9 @@ class SchedulingViewModel( d2.eventModule().events().uid(eventUid).run { setDueDate(dueDate.currentDate) setStatus(EventStatus.SCHEDULE) + onDueDateUpdated?.invoke() } } - - onDueDateUpdated?.invoke() } } diff --git a/commons/src/main/java/org/dhis2/commons/date/DateUtils.java b/commons/src/main/java/org/dhis2/commons/date/DateUtils.java index 73229db3ca..d2d0010c6b 100644 --- a/commons/src/main/java/org/dhis2/commons/date/DateUtils.java +++ b/commons/src/main/java/org/dhis2/commons/date/DateUtils.java @@ -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); }