Skip to content

Commit

Permalink
fix: Fixes according to designer feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk committed Jul 30, 2024
1 parent 01118a6 commit db4e41f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 14 deletions.
57 changes: 49 additions & 8 deletions core/src/main/java/org/openedx/core/utils/TimeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,59 @@ object TimeUtils {
private const val FORMAT_ISO_8601_WITH_TIME_ZONE = "yyyy-MM-dd'T'HH:mm:ssXXX"
private const val SEVEN_DAYS_IN_MILLIS = 604800000L

fun formatToString(date: Date, useRelativeDates: Boolean): String {
return if (useRelativeDates) {
DateUtils.getRelativeTimeSpanString(
fun formatToString(context: Context, date: Date, useRelativeDates: Boolean): String {
if (!useRelativeDates) {
val locale = Locale(Locale.getDefault().language)
val dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale)
return dateFormat.format(date)
}

val now = Calendar.getInstance()
val inputDate = Calendar.getInstance().apply { time = date }
val daysDiff = ((now.timeInMillis - inputDate.timeInMillis) / (1000 * 60 * 60 * 24)).toInt()
return when {
daysDiff in -5..-1 -> DateUtils.formatDateTime(
context,
date.time,
DateUtils.FORMAT_SHOW_WEEKDAY
).toString()

daysDiff == -6 -> context.getString(R.string.core_next) + " " + DateUtils.formatDateTime(
context,
date.time,
DateUtils.FORMAT_SHOW_WEEKDAY
).toString()

daysDiff in -1..1 -> DateUtils.getRelativeTimeSpanString(
date.time,
getCurrentTime(),
now.timeInMillis,
DateUtils.DAY_IN_MILLIS,
DateUtils.FORMAT_ABBREV_TIME
).toString()
} else {
val locale = Locale(Locale.getDefault().language)
val dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale)
dateFormat.format(date)

daysDiff in 2..6 -> DateUtils.getRelativeTimeSpanString(
date.time,
now.timeInMillis,
DateUtils.DAY_IN_MILLIS
).toString()

inputDate.get(Calendar.YEAR) == now.get(Calendar.YEAR) -> {
DateUtils.getRelativeTimeSpanString(
date.time,
now.timeInMillis,
DateUtils.DAY_IN_MILLIS,
DateUtils.FORMAT_SHOW_DATE
).toString()
}

else -> {
DateUtils.getRelativeTimeSpanString(
date.time,
now.timeInMillis,
DateUtils.DAY_IN_MILLIS,
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR
).toString()
}
}
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,5 @@
<string name="core_to_sync">To Sync</string>
<string name="core_not_synced">Not Synced</string>
<string name="core_syncing_to_calendar">Syncing to calendar…</string>
<string name="core_next">"Next"</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ private fun CourseDateItem(
useRelativeDates: Boolean,
onItemClick: (CourseDateBlock) -> Unit,
) {
val context = LocalContext.current
Column(
modifier = Modifier
.wrapContentHeight()
Expand All @@ -610,7 +611,7 @@ private fun CourseDateItem(
Spacer(modifier = Modifier.height(20.dp))
}
if (canShowDate) {
val timeTitle = formatToString(dateBlock.date, useRelativeDates)
val timeTitle = formatToString(context, dateBlock.date, useRelativeDates)
Text(
text = timeTitle,
style = MaterialTheme.appTypography.labelMedium,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
Expand Down Expand Up @@ -750,12 +751,13 @@ fun CourseSubSectionItem(
useRelativeDates: Boolean,
onClick: (Block) -> Unit,
) {
val context = LocalContext.current
val icon =
if (block.isCompleted()) painterResource(R.drawable.course_ic_task_alt) else painterResource(coreR.drawable.ic_core_chapter_icon)
val iconColor =
if (block.isCompleted()) MaterialTheme.appColors.successGreen else MaterialTheme.appColors.onSurface
val due by rememberSaveable {
mutableStateOf(block.due?.let { TimeUtils.formatToString(it, useRelativeDates) } ?: "")
mutableStateOf(block.due?.let { TimeUtils.formatToString(context, it, useRelativeDates) } ?: "")
}
val isAssignmentEnable = !block.isCompleted() && block.assignmentProgress != null && !due.isNullOrEmpty()
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ private fun PrimaryCourseCard(
nearestAssignment.assignmentType ?: "",
stringResource(
id = CoreR.string.core_date_format_assignment_due,
TimeUtils.formatToString(nearestAssignment.date, useRelativeDates)
TimeUtils.formatToString(context, nearestAssignment.date, useRelativeDates)
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions default_config/stage/config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
API_HOST_URL: 'http://localhost:8000'
API_HOST_URL: 'https://axim-mobile.raccoongang.net'
APPLICATION_ID: 'org.openedx.app'
ENVIRONMENT_DISPLAY_NAME: 'Localhost'
URI_SCHEME: ''
FEEDBACK_EMAIL_ADDRESS: '[email protected]'
FAQ_URL: ''
OAUTH_CLIENT_ID: 'OAUTH_CLIENT_ID'
OAUTH_CLIENT_ID: 'zP3vPz00c8fTRpYjNbVSlA1fxt9LnCxTM4JK1KQ0'

# Keep empty to hide setting
AGREEMENT_URLS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.openedx.core.ui.theme.appColors
Expand All @@ -29,12 +30,13 @@ fun OptionsSection(
isRelativeDatesEnabled: Boolean,
onRelativeDateSwitchClick: (Boolean) -> Unit
) {
val context = LocalContext.current
val textDescription = if (isRelativeDatesEnabled) {
stringResource(R.string.profile_show_relative_dates)
} else {
stringResource(
R.string.profile_show_full_dates,
TimeUtils.formatToString(Date(), false)
TimeUtils.formatToString(context, Date(), false)
)
}
Column {
Expand Down

0 comments on commit db4e41f

Please sign in to comment.