Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.instructure.student.fragment

import android.os.Bundle
import java.text.DateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -147,10 +148,13 @@ class AssignmentBasicFragment : ParentFragment() {
// Assignment description can be null
var description = when {
assignment.isLocked -> getLockedInfoHTML(assignment.lockInfo!!, R.string.lockedAssignmentDesc)
assignment.lockDate?.before(Calendar.getInstance(Locale.getDefault()).time) == true ->
assignment.lockDate?.before(Calendar.getInstance(Locale.getDefault()).time) == true -> {
// If an assignment has an available from and until field and it has expired (the current date is after "until" it will have a lock explanation,
// but no lock info because it isn't Locked as part of a module
assignment.lockExplanation
val dateString = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault()).format(assignment.lockDate!!)
val timeString = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault()).format(assignment.lockDate!!)
getString(com.instructure.pandautils.R.string.closedSubtext, dateString, timeString)
}
else -> assignment.description
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,11 @@ class AssignmentDetailsViewModel @Inject constructor(
)
}

val partialLockedMessage = assignment.lockExplanation.takeIf { it.isValid() && assignment.lockDate?.before(Date()).orDefault() }.orEmpty()
val partialLockedMessage = assignment.lockDate?.takeIf { it.before(Date()) }?.let {
val dateString = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault()).format(it)
val timeString = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault()).format(it)
resources.getString(R.string.closedSubtext, dateString, timeString)
}.orEmpty()

val submissionHistory = assignment.submission?.submissionHistory
val attempts = submissionHistory?.let { history ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.instructure.canvasapi2.utils.isValid
import java.time.DayOfWeek
import java.util.Calendar
import java.util.Locale
import java.util.TimeZone
import kotlin.system.exitProcess

object LocaleUtils {
Expand Down Expand Up @@ -66,6 +67,9 @@ object LocaleUtils {
Locale.Builder().setLanguageTag(localeString).build()
}
Locale.setDefault(locale)
// Ensure device timezone is used for all date/time formatting
val deviceTimeZone = TimeZone.getDefault()
TimeZone.setDefault(deviceTimeZone)
val config = Configuration()
config.setLocales(LocaleList(locale))
ContextKeeper.updateLocale(config)
Expand Down
1 change: 1 addition & 0 deletions libs/pandautils/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
<string name="noSubmissionTeacher">This student doesn\'t have a submission yet.</string>
<string name="locked">Locked</string>
<string name="lockedSubtext">This assignment is locked until %1$s at %2$s.</string>
<string name="closedSubtext">This assignment was locked on %1$s at %2$s.</string>
<string name="chooseFile">Choose a File</string>
<string name="chooseFileSubtext">Attach a file to your submission by tapping an option below.</string>
<string name="chooseFileForUploadSubtext">Select a file to upload by tapping an option below</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import org.junit.Rule
import org.junit.Test
import java.util.Calendar
import java.util.Date
import java.util.Locale

@ExperimentalCoroutinesApi
class AssignmentDetailsViewModelTest {
Expand Down Expand Up @@ -188,24 +189,27 @@ class AssignmentDetailsViewModelTest {

@Test
fun `Load partially locked assignment`() {
val lockedExplanation = "locked"
val lockDate = Calendar.getInstance().apply { add(Calendar.DAY_OF_MONTH, -1) }.time
val dateString = java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG, Locale.getDefault()).format(lockDate)
val timeString = java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT, Locale.getDefault()).format(lockDate)
val expectedLockedMessage = "This assignment was locked on $dateString at $timeString."

every { resources.getString(R.string.errorLoadingAssignment) } returns lockedExplanation
every { resources.getString(R.string.errorLoadingAssignment) } returns ""
every { resources.getString(R.string.closedSubtext, dateString, timeString) } returns expectedLockedMessage

val course = Course(enrollments = mutableListOf(Enrollment(type = Enrollment.EnrollmentType.Student)))
coEvery { assignmentDetailsRepository.getCourseWithGrade(any(), any()) } returns course

val assignment = Assignment(
lockExplanation = lockedExplanation,
lockAt = Calendar.getInstance().apply { add(Calendar.DAY_OF_MONTH, -1) }.time.toApiString()
lockAt = lockDate.toApiString()
)
coEvery { assignmentDetailsRepository.getAssignment(any(), any(), any(), any()) } returns assignment

val viewModel = getViewModel()

assertEquals(ViewState.Success, viewModel.state.value)
assertEquals(false, viewModel.data.value?.fullLocked)
assertEquals(lockedExplanation, viewModel.data.value?.lockedMessage)
assertEquals(expectedLockedMessage, viewModel.data.value?.lockedMessage)
}

@Test
Expand Down
Loading