Skip to content

Commit

Permalink
[Teacher][MBL-13254] Fix speed grader crash (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinKern authored Sep 16, 2019
1 parent dc772f1 commit be88b69
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/teacher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {
defaultConfig {
minSdkVersion Versions.MIN_SDK
targetSdkVersion Versions.TARGET_SDK
versionCode = 23
versionCode = 24
versionName = '1.9.0'
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,10 @@ class SpeedGraderGradeFragment : BasePresenterFragment<SpeedGraderGradePresenter
@Suppress("unused")
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
fun onAssignmentGraded(event: AssignmentGradedEvent) {
event.once(javaClass.simpleName + presenter.submission?.id) {
val submissionId = presenter?.submission?.id ?: return
event.once(javaClass.simpleName + submissionId) {
if(mAssignment.id == it) {
GlobalScope.launch {
// Try to update our submission for post/hide grades
presenter.submission = SubmissionManager.getSingleSubmissionAsync(
presenter.course.id,
presenter.assignment.id,
presenter.submission?.userId ?: return@launch,
true
).await().dataOrNull ?: return@launch

withContext(Dispatchers.Main) {
setupViews()
}
}
presenter?.refreshSubmission()
}
}
}
Expand Down Expand Up @@ -242,6 +231,7 @@ class SpeedGraderGradeFragment : BasePresenterFragment<SpeedGraderGradePresenter
addGradeIcon.setGone()
gradeProgressSpinner.announceForAccessibility(getString(R.string.loading))
gradeProgressSpinner.setVisible()
hiddenIcon.setGone()
}

val hasUnsavedChanges: Boolean get() = rubricEditView?.hasUnsavedChanges ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import com.instructure.teacher.events.SubmissionUpdatedEvent
import com.instructure.teacher.events.post
import com.instructure.teacher.viewinterface.SpeedGraderGradeView
import instructure.androidblueprint.FragmentPresenter
import kotlinx.coroutines.Job
import kotlinx.coroutines.*

class SpeedGraderGradePresenter(var submission: Submission?, val assignment: Assignment, val course: Course, val assignee: Assignee) : FragmentPresenter<SpeedGraderGradeView>() {

private var mPostGradeAPICall: Job? = null
private var refreshSubmissionApiCall: Job? = null

@Suppress("EXPERIMENTAL_FEATURE_WARNING")
fun updateGrade(grade: String, isExcused: Boolean) {
Expand Down Expand Up @@ -58,6 +59,34 @@ class SpeedGraderGradePresenter(var submission: Submission?, val assignment: Ass
}
}

fun refreshSubmission() {
refreshSubmissionApiCall = GlobalScope.launch(Dispatchers.Main) {
try {
viewCallback?.onRefreshStarted()

// Try to update our submission for post/hide grades
val newSubmission = SubmissionManager.getSingleSubmissionAsync(
course.id,
assignment.id,
submission?.userId ?: return@launch,
true
).await().dataOrNull ?: return@launch

submission = newSubmission
viewCallback?.updateGradeText()
viewCallback?.onRefreshFinished()
} catch (e: Throwable) {
viewCallback?.updateGradeError()
}
}
}

override fun onDestroyed() {
super.onDestroyed()
mPostGradeAPICall?.cancel()
refreshSubmissionApiCall?.cancel()
}

override fun loadData(forceNetwork: Boolean) { }
override fun refresh(forceNetwork: Boolean) { }

Expand Down

0 comments on commit be88b69

Please sign in to comment.