Skip to content
Snippets Groups Projects
Unverified Commit 3b47b6f0 authored by Kolya Opahle's avatar Kolya Opahle Committed by GitHub
Browse files

Handling a NoRegistrationTokenSetException by returning UNPAIRED state (#161)

parent a1a3c673
No related branches found
No related tags found
No related merge requests found
package de.rki.coronawarnapp.storage
import androidx.lifecycle.MutableLiveData
import de.rki.coronawarnapp.exception.NoRegistrationTokenSetException
import de.rki.coronawarnapp.service.submission.SubmissionService
import de.rki.coronawarnapp.util.DeviceUIState
import de.rki.coronawarnapp.util.formatter.TestResult
......@@ -18,7 +19,7 @@ object SubmissionRepository {
if (LocalData.numberOfSuccessfulSubmissions() == 1) {
uiState = DeviceUIState.SUBMITTED_FINAL
} else {
if (LocalData.registrationToken() != "") {
if (LocalData.registrationToken() != null) {
uiState = when {
LocalData.isAllowedToSubmitDiagnosisKeys() == true -> {
DeviceUIState.PAIRED_POSITIVE
......@@ -31,27 +32,31 @@ object SubmissionRepository {
}
private suspend fun fetchTestResult(): DeviceUIState {
val testResult = SubmissionService.asyncRequestTestResult()
try {
val testResult = SubmissionService.asyncRequestTestResult()
if (testResult == TestResult.POSITIVE) {
LocalData.isAllowedToSubmitDiagnosisKeys(true)
}
if (testResult == TestResult.POSITIVE) {
LocalData.isAllowedToSubmitDiagnosisKeys(true)
}
val initialTestResultReceivedTimestamp = LocalData.inititalTestResultReceivedTimestamp()
val initialTestResultReceivedTimestamp = LocalData.inititalTestResultReceivedTimestamp()
if (initialTestResultReceivedTimestamp == null) {
val currentTime = System.currentTimeMillis()
LocalData.inititalTestResultReceivedTimestamp(currentTime)
testResultReceivedDate.value = Date(currentTime)
} else {
testResultReceivedDate.value = Date(initialTestResultReceivedTimestamp)
}
if (initialTestResultReceivedTimestamp == null) {
val currentTime = System.currentTimeMillis()
LocalData.inititalTestResultReceivedTimestamp(currentTime)
testResultReceivedDate.value = Date(currentTime)
} else {
testResultReceivedDate.value = Date(initialTestResultReceivedTimestamp)
}
return when (testResult) {
TestResult.NEGATIVE -> DeviceUIState.PAIRED_NEGATIVE
TestResult.POSITIVE -> DeviceUIState.PAIRED_POSITIVE
TestResult.PENDING -> DeviceUIState.PAIRED_NO_RESULT
TestResult.INVALID -> DeviceUIState.PAIRED_ERROR
return when (testResult) {
TestResult.NEGATIVE -> DeviceUIState.PAIRED_NEGATIVE
TestResult.POSITIVE -> DeviceUIState.PAIRED_POSITIVE
TestResult.PENDING -> DeviceUIState.PAIRED_NO_RESULT
TestResult.INVALID -> DeviceUIState.PAIRED_ERROR
}
} catch (err: NoRegistrationTokenSetException) {
return DeviceUIState.UNPAIRED
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment