Skip to content

Commit 239df3e

Browse files
feat: shift due date card
1 parent d460573 commit 239df3e

File tree

6 files changed

+89
-4
lines changed

6 files changed

+89
-4
lines changed

core/src/main/java/org/openedx/core/data/model/CourseDatesResponse.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ data class CourseDate(
1616
val assignmentTitle: String?,
1717
@SerializedName("learner_has_access")
1818
val learnerHasAccess: Boolean?,
19+
@SerializedName("relative")
20+
val relative: Boolean?,
1921
@SerializedName("course_name")
2022
val courseName: String?
2123
) {
@@ -27,7 +29,8 @@ data class CourseDate(
2729
dueDate = dueDate ?: return null,
2830
assignmentTitle = assignmentTitle ?: "",
2931
learnerHasAccess = learnerHasAccess ?: false,
30-
courseName = courseName ?: ""
32+
courseName = courseName ?: "",
33+
relative = relative ?: false
3134
)
3235
}
3336
}

core/src/main/java/org/openedx/core/domain/model/CourseDatesResponse.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ data class CourseDate(
1515
val dueDate: Date,
1616
val assignmentTitle: String,
1717
val learnerHasAccess: Boolean,
18+
val relative: Boolean,
1819
val courseName: String
1920
)

dates/src/main/java/org/openedx/dates/data/storage/CourseDateEntity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ data class CourseDateEntity(
2020
val assignmentTitle: String?,
2121
@ColumnInfo("learnerHasAccess")
2222
val learnerHasAccess: Boolean?,
23+
@ColumnInfo("relative")
24+
val relative: Boolean?,
2325
@ColumnInfo("courseName")
2426
val courseName: String?,
2527
) {
@@ -32,6 +34,7 @@ data class CourseDateEntity(
3234
dueDate = dueDate ?: return null,
3335
assignmentTitle = assignmentTitle ?: "",
3436
learnerHasAccess = learnerHasAccess ?: false,
37+
relative = relative ?: false,
3538
courseName = courseName ?: ""
3639
)
3740
}
@@ -45,6 +48,7 @@ data class CourseDateEntity(
4548
dueDate = dueDate,
4649
assignmentTitle = assignmentTitle,
4750
learnerHasAccess = learnerHasAccess,
51+
relative = relative,
4852
courseName = courseName
4953
)
5054
}

dates/src/main/java/org/openedx/dates/presentation/dates/DatesFragment.kt

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.openedx.dates.presentation.dates
33
import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.ViewGroup
6+
import androidx.compose.foundation.layout.Arrangement
67
import androidx.compose.foundation.layout.Box
78
import androidx.compose.foundation.layout.Column
89
import androidx.compose.foundation.layout.PaddingValues
@@ -17,6 +18,7 @@ import androidx.compose.foundation.lazy.LazyColumn
1718
import androidx.compose.foundation.lazy.rememberLazyListState
1819
import androidx.compose.foundation.rememberScrollState
1920
import androidx.compose.foundation.verticalScroll
21+
import androidx.compose.material.Card
2022
import androidx.compose.material.CircularProgressIndicator
2123
import androidx.compose.material.ExperimentalMaterialApi
2224
import androidx.compose.material.Icon
@@ -48,15 +50,18 @@ import androidx.compose.ui.unit.Dp
4850
import androidx.compose.ui.unit.dp
4951
import androidx.fragment.app.Fragment
5052
import org.koin.androidx.viewmodel.ext.android.viewModel
53+
import org.openedx.core.domain.model.DatesSection
5154
import org.openedx.core.presentation.dates.CourseDateBlockSection
5255
import org.openedx.core.ui.HandleUIMessage
5356
import org.openedx.core.ui.MainScreenTitle
5457
import org.openedx.core.ui.OfflineModeDialog
58+
import org.openedx.core.ui.OpenEdXButton
5559
import org.openedx.core.ui.displayCutoutForLandscape
5660
import org.openedx.core.ui.shouldLoadMore
5761
import org.openedx.core.ui.statusBarsInset
5862
import org.openedx.core.ui.theme.OpenEdXTheme
5963
import org.openedx.core.ui.theme.appColors
64+
import org.openedx.core.ui.theme.appShapes
6065
import org.openedx.core.ui.theme.appTypography
6166
import org.openedx.dates.R
6267
import org.openedx.dates.presentation.dates.DatesFragment.Companion.LOAD_MORE_THRESHOLD
@@ -103,6 +108,10 @@ class DatesFragment : Fragment() {
103108
viewModel.fetchMore()
104109
}
105110

111+
DatesViewActions.ShiftDueDate -> {
112+
viewModel.shiftDueDate()
113+
}
114+
106115
is DatesViewActions.OpenEvent -> {
107116
viewModel.navigateToCourseOutline(
108117
requireActivity().supportFragmentManager,
@@ -197,11 +206,23 @@ private fun DatesScreen(
197206
LazyColumn(
198207
modifier = contentWidth.fillMaxSize(),
199208
state = scrollState,
200-
contentPadding = PaddingValues(bottom = 20.dp)
209+
contentPadding = PaddingValues(bottom = 48.dp)
201210
) {
202211
uiState.dates.keys.forEach { sectionKey ->
203-
val dates = uiState.dates[sectionKey] ?: emptyList()
212+
val dates = uiState.dates[sectionKey].orEmpty()
204213
dates.isNotEmptyThenLet { sectionDates ->
214+
val isHavePastRelatedDates =
215+
sectionKey == DatesSection.PAST_DUE && dates.any { it.relative }
216+
if (isHavePastRelatedDates) {
217+
item {
218+
ShiftDueDatesCard(
219+
modifier = Modifier.padding(top = 12.dp),
220+
onClick = {
221+
onAction(DatesViewActions.ShiftDueDate)
222+
}
223+
)
224+
}
225+
}
205226
item {
206227
CourseDateBlockSection(
207228
sectionKey = sectionKey,
@@ -261,6 +282,44 @@ private fun DatesScreen(
261282
)
262283
}
263284

285+
@Composable
286+
private fun ShiftDueDatesCard(
287+
modifier: Modifier = Modifier,
288+
onClick: () -> Unit
289+
) {
290+
Card(
291+
modifier = modifier
292+
.fillMaxWidth(),
293+
backgroundColor = MaterialTheme.appColors.cardViewBackground,
294+
shape = MaterialTheme.appShapes.cardShape,
295+
) {
296+
Column(
297+
modifier = Modifier
298+
.fillMaxSize()
299+
.padding(12.dp),
300+
horizontalAlignment = Alignment.CenterHorizontally,
301+
verticalArrangement = Arrangement.spacedBy(12.dp)
302+
) {
303+
Text(
304+
modifier = Modifier.fillMaxWidth(),
305+
text = stringResource(id = R.string.dates_shift_due_date_card_title),
306+
color = MaterialTheme.appColors.textDark,
307+
style = MaterialTheme.appTypography.titleMedium,
308+
)
309+
Text(
310+
modifier = Modifier.fillMaxWidth(),
311+
text = stringResource(id = R.string.dates_shift_due_date_card_description),
312+
color = MaterialTheme.appColors.textDark,
313+
style = MaterialTheme.appTypography.labelLarge,
314+
)
315+
OpenEdXButton(
316+
text = stringResource(id = R.string.dates_shift_due_date),
317+
onClick = onClick
318+
)
319+
}
320+
}
321+
}
322+
264323
@Composable
265324
private fun EmptyState(
266325
modifier: Modifier = Modifier
@@ -317,3 +376,13 @@ private fun DatesScreenPreview() {
317376
)
318377
}
319378
}
379+
380+
@Preview
381+
@Composable
382+
private fun ShiftDueDatesCardPreview() {
383+
OpenEdXTheme {
384+
ShiftDueDatesCard(
385+
onClick = {}
386+
)
387+
}
388+
}

dates/src/main/java/org/openedx/dates/presentation/dates/DatesViewModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DatesViewModel(
3232
private val networkConnection: NetworkConnection,
3333
private val resourceManager: ResourceManager,
3434
private val datesInteractor: DatesInteractor,
35-
private val corePreferences: CorePreferences,
35+
corePreferences: CorePreferences,
3636
) : BaseViewModel() {
3737

3838
private val _uiState = MutableStateFlow(DatesUIState())
@@ -115,6 +115,10 @@ class DatesViewModel(
115115
}
116116
}
117117

118+
fun shiftDueDate() {
119+
//TODO
120+
}
121+
118122
fun fetchMore() {
119123
if (!_uiState.value.isLoading && page != -1) {
120124
fetchDates(false)
@@ -174,4 +178,5 @@ interface DatesViewActions {
174178
class OpenEvent(val date: CourseDate) : DatesViewActions
175179
object LoadMore : DatesViewActions
176180
object SwipeRefresh : DatesViewActions
181+
object ShiftDueDate : DatesViewActions
177182
}

dates/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
<string name="dates">Dates</string>
44
<string name="dates_empty_state_title">No Dates</string>
55
<string name="dates_empty_state_description">You currently have no active courses with scheduled events. Enroll in a course to view important dates and deadlines.</string>
6+
<string name="dates_shift_due_date_card_title">Missed Some Deadlines?</string>
7+
<string name="dates_shift_due_date_card_description">Don’t worry - shift our suggested schedule to complete past due assignments without losing any progress.</string>
8+
<string name="dates_shift_due_date">Shift Due Dates</string>
69
</resources>

0 commit comments

Comments
 (0)