File tree Expand file tree Collapse file tree 7 files changed +55
-1
lines changed
core/src/main/java/org/openedx/core/data
dates/src/main/java/org/openedx/dates Expand file tree Collapse file tree 7 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import org.openedx.core.data.model.CourseStructureModel
1313import org.openedx.core.data.model.EnrollmentStatus
1414import org.openedx.core.data.model.HandoutsModel
1515import org.openedx.core.data.model.ResetCourseDates
16+ import org.openedx.core.data.model.ShiftDueDatesBody
1617import retrofit2.http.Body
1718import retrofit2.http.GET
1819import retrofit2.http.Header
@@ -110,4 +111,9 @@ interface CourseApi {
110111 @Path(" username" ) username : String ,
111112 @Query(" page" ) page : Int
112113 ): CourseDatesResponse
114+
115+ @POST(" /api/course_experience/v1/reset_multiple_course_deadlines/" )
116+ suspend fun shiftDueDate (
117+ @Body shiftDueDatesBody : ShiftDueDatesBody
118+ )
113119}
Original file line number Diff line number Diff line change 1+ package org.openedx.core.data.model
2+
3+ import com.google.gson.annotations.SerializedName
4+
5+ data class ShiftDueDatesBody (
6+ @SerializedName(" course_keys" ) val courseKeys : List <String >
7+ )
Original file line number Diff line number Diff line change 11package org.openedx.dates.data.repository
22
33import org.openedx.core.data.api.CourseApi
4+ import org.openedx.core.data.model.ShiftDueDatesBody
45import org.openedx.core.data.storage.CorePreferences
56import org.openedx.core.domain.model.CourseDate
67import org.openedx.core.domain.model.CourseDatesResponse
@@ -22,4 +23,7 @@ class DatesRepository(
2223 suspend fun getUserDatesFromCache (): List <CourseDate > {
2324 return dao.getCourseDateEntities().mapNotNull { it.mapToDomain() }
2425 }
26+
27+ suspend fun shiftDueDate (courseIds : List <String >) =
28+ api.shiftDueDate(ShiftDueDatesBody (courseIds))
2529}
Original file line number Diff line number Diff line change @@ -10,4 +10,6 @@ class DatesInteractor(
1010
1111 suspend fun getUserDatesFromCache () = repository.getUserDatesFromCache()
1212
13+ suspend fun shiftDueDate (courseIds : List <String >) = repository.shiftDueDate(courseIds)
14+
1315}
Original file line number Diff line number Diff line change @@ -217,6 +217,7 @@ private fun DatesScreen(
217217 item {
218218 ShiftDueDatesCard (
219219 modifier = Modifier .padding(top = 12 .dp),
220+ isButtonEnabled = ! uiState.isShiftDueDatesPressed,
220221 onClick = {
221222 onAction(DatesViewActions .ShiftDueDate )
222223 }
@@ -285,6 +286,7 @@ private fun DatesScreen(
285286@Composable
286287private fun ShiftDueDatesCard (
287288 modifier : Modifier = Modifier ,
289+ isButtonEnabled : Boolean ,
288290 onClick : () -> Unit
289291) {
290292 Card (
@@ -314,6 +316,7 @@ private fun ShiftDueDatesCard(
314316 )
315317 OpenEdXButton (
316318 text = stringResource(id = R .string.dates_shift_due_date),
319+ enabled = isButtonEnabled,
317320 onClick = onClick
318321 )
319322 }
@@ -382,6 +385,7 @@ private fun DatesScreenPreview() {
382385private fun ShiftDueDatesCardPreview () {
383386 OpenEdXTheme {
384387 ShiftDueDatesCard (
388+ isButtonEnabled = true ,
385389 onClick = {}
386390 )
387391 }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import org.openedx.core.domain.model.DatesSection
55
66data class DatesUIState (
77 val isLoading : Boolean = true ,
8+ val isShiftDueDatesPressed : Boolean = false ,
89 val isRefreshing : Boolean = false ,
910 val canLoadMore : Boolean = false ,
1011 val dates : Map <DatesSection , List <CourseDate >> = emptyMap()
Original file line number Diff line number Diff line change @@ -116,7 +116,37 @@ class DatesViewModel(
116116 }
117117
118118 fun shiftDueDate () {
119- // TODO
119+ viewModelScope.launch {
120+ try {
121+ _uiState .update { state ->
122+ state.copy(
123+ isShiftDueDatesPressed = true ,
124+ )
125+ }
126+ val pastDueDates = _uiState .value.dates[DatesSection .PAST_DUE ] ? : emptyList()
127+ val courseIds = pastDueDates
128+ .filter { it.relative }
129+ .map { it.courseId }
130+ datesInteractor.shiftDueDate(courseIds)
131+ refreshData()
132+ } catch (e: Exception ) {
133+ if (e.isInternetError()) {
134+ _uiMessage .emit(
135+ UIMessage .SnackBarMessage (resourceManager.getString(R .string.core_error_no_connection))
136+ )
137+ } else {
138+ _uiMessage .emit(
139+ UIMessage .SnackBarMessage (resourceManager.getString(R .string.core_error_unknown_error))
140+ )
141+ }
142+ } finally {
143+ _uiState .update { state ->
144+ state.copy(
145+ isShiftDueDatesPressed = false ,
146+ )
147+ }
148+ }
149+ }
120150 }
121151
122152 fun fetchMore () {
You can’t perform that action at this time.
0 commit comments