Skip to content

Commit

Permalink
Beta/1.0.17 (#141)
Browse files Browse the repository at this point in the history
* Remove selected infection and test dates if no symptoms was unselected

* Show only uploaded diagnoses

* Make a diagnoses verified only if we upload it or skip the uploading

* Move conversion from LocalDate to Instant into an extension

* Use smaller size for region selection item

* Add debug arizon json endpoint

* Fix reactive changes of the text information about enabled Exposure Notifications on Possible Exposures screen

* Add tests for deleting\saving\downloading keys urls
  • Loading branch information
Apisov authored Aug 16, 2020
1 parent cc8fb0b commit 21cb2a7
Show file tree
Hide file tree
Showing 13 changed files with 482 additions and 34 deletions.
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
testCoverageEnabled false
buildConfigField("boolean", "FIREBASE_DEBUGGING", "false")
signingConfig signingConfigs.debug
}
debug {
testCoverageEnabled project.hasProperty('coverage')
buildConfigField "boolean", "FIREBASE_DEBUGGING", "true"
}
}

Expand Down Expand Up @@ -107,6 +105,13 @@ android {
arizona {
dimension "client"
applicationId "gov.azdhs.covidwatch.android"
}
}

applicationVariants.all { variant ->
if (variant.getName().startsWith("calibrationArizona")) {
buildConfigField "String", "REGIONS_JSON", '"https://storage.googleapis.com/dev-covid-watch-arizona-regions/arizona-v3.json"'
} else if(variant.getName().startsWith("productionArizona")) {
buildConfigField "String", "REGIONS_JSON", '"https://storage.googleapis.com/covid-watch-arizona-regions/arizona-v3.json"'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class PositiveDiagnosisLocalSource(private val dao: PositiveDiagnosisReportDao)
suspend fun updatePositiveDiagnosisReport(report: PositiveDiagnosisReport) =
dao.update(report)

suspend fun report(id: String) = dao.report(id)

suspend fun diagnosisByVerificationCode(code: String) =
dao.diagnosisByVerificationCode(code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import org.covidwatch.android.data.PositiveDiagnosisReport
@Dao
interface PositiveDiagnosisReportDao : BaseDao<PositiveDiagnosisReport> {

@Query("SELECT * FROM positive_diagnosis_report")
@Query("SELECT * FROM positive_diagnosis_report WHERE uploaded = 1")
fun diagnoses(): LiveData<List<PositiveDiagnosisReport>>

@Query("SELECT * FROM positive_diagnosis_report WHERE id = :id")
suspend fun report(id: String): PositiveDiagnosisReport?

@Query("SELECT * FROM positive_diagnosis_report WHERE verificationTestCode = :code")
suspend fun diagnosisByVerificationCode(code: String): PositiveDiagnosisReport?

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/org/covidwatch/android/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ val appModule = module {
viewModel {
ExposuresViewModel(
enManager = get(),
updateExposureInformationUseCase = get(),
preferenceStorage = get(),
exposureInformationRepository = get()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class UploadDiagnosisKeysUseCase(
diagnosisRepository.updatePositiveDiagnosisReport(
report.copy(
verified = true,
uploaded = true, // Fake uploaded to show it in the list of the submitted diagnoses
reportDate = Instant.now(),
verificationData = report.verificationData?.copy(
verificationTestCode = "",
Expand All @@ -92,7 +93,7 @@ class UploadDiagnosisKeysUseCase(

// Check if we certificated the token before and reuse certificate
if (verificationData.verificationCertificate != null && verificationData.hmacKey != null) {
verifiedDiagnosis = params.report.copy(verified = true)
verifiedDiagnosis = params.report

certificate = verificationData.verificationCertificate
hmacKey = verificationData.hmacKey
Expand All @@ -103,7 +104,6 @@ class UploadDiagnosisKeysUseCase(
)

verifiedDiagnosis = params.report.copy(
verified = true,
verificationData = verificationData.copy(
hmacKey = verificationCertificate.hmacKey,
verificationCertificate = verificationCertificate.certificate
Expand Down Expand Up @@ -132,6 +132,7 @@ class UploadDiagnosisKeysUseCase(

diagnosisRepository.updatePositiveDiagnosisReport(
verifiedDiagnosis.copy(
verified = true,
uploaded = true,
reportDate = Instant.now(),
verificationData = verifiedDiagnosis.verificationData?.copy(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/covidwatch/android/extension/Blob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ fun Instant.toLocalDate(): LocalDate {
return atZone(ZoneId.of("UTC")).toLocalDate()
}

fun LocalDate.toInstant(): Instant = atStartOfDay(ZoneId.of("UTC")).toInstant()

fun Instant.daysTo(anotherDate: Instant) =
Period.between(this.toLocalDate(), anotherDate.toLocalDate()).days

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ExposuresFragment : BaseViewModelFragment<FragmentExposuresBinding, Exposu

if (exposures.isNotEmpty()) adapter.add(FooterItem())
}
observe(exposureNotificationEnabled) { enabled ->
observe(enEnabled) { enabled ->
if (enabled) {
binding.exposureNotificationsSubtitle.setText(R.string.exposures_notifications_on_subtitle)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import kotlinx.coroutines.launch
import org.covidwatch.android.data.CovidExposureInformation
import org.covidwatch.android.data.exposureinformation.ExposureInformationRepository
import org.covidwatch.android.data.pref.PreferenceStorage
import org.covidwatch.android.domain.UpdateExposureInformationUseCase
import org.covidwatch.android.exposurenotification.ExposureNotificationManager
import org.covidwatch.android.exposurenotification.ExposureNotificationManager.Companion.PERMISSION_START_REQUEST_CODE
import org.covidwatch.android.ui.BaseViewModel
import org.covidwatch.android.ui.event.Event

class ExposuresViewModel(
private val enManager: ExposureNotificationManager,
private val updateExposureInformationUseCase: UpdateExposureInformationUseCase,
private val preferenceStorage: PreferenceStorage,
exposureInformationRepository: ExposureInformationRepository
) : BaseViewModel() {

private val _exposureNotificationEnabled = MutableLiveData<Boolean>()
val exposureNotificationEnabled: LiveData<Boolean> = _exposureNotificationEnabled

private val _enEnabled = MutableLiveData<Boolean>()
val enEnabled: LiveData<Boolean> = _enEnabled

private val _showExposureDetails = MutableLiveData<Event<CovidExposureInformation>>()
val showExposureDetails: LiveData<Event<CovidExposureInformation>> = _showExposureDetails

Expand All @@ -38,8 +39,7 @@ class ExposuresViewModel(
fun start() {
viewModelScope.launch {
_exposureNotificationEnabled.value = isExposureNotificationEnabled()

updateExposureInformationUseCase(this)
_enEnabled.value = isExposureNotificationEnabled()
}
}

Expand All @@ -48,8 +48,17 @@ class ExposuresViewModel(
val isEnabled = isExposureNotificationEnabled()

when {
enable && !isEnabled -> withPermission(PERMISSION_START_REQUEST_CODE) { enManager.start() }
!enable && isEnabled -> enManager.stop()
enable && !isEnabled -> withPermission(PERMISSION_START_REQUEST_CODE) {
enManager.start().apply {
success {
_enEnabled.value = true
}
}
}
!enable && isEnabled -> {
_enEnabled.value = false
enManager.stop()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import org.covidwatch.android.databinding.FragmentVerifyPositiveDiagnosisBinding
import org.covidwatch.android.extension.observe
import org.covidwatch.android.extension.observeEvent
import org.covidwatch.android.extension.observeNullableEvent
import org.covidwatch.android.extension.toInstant
import org.covidwatch.android.ui.BaseViewModelFragment
import org.koin.androidx.viewmodel.ext.android.stateViewModel
import java.time.LocalDate
import java.time.ZoneId

class VerifyPositiveDiagnosisFragment :
BaseViewModelFragment<FragmentVerifyPositiveDiagnosisBinding, VerifyPositiveDiagnosisViewModel>() {
Expand Down Expand Up @@ -119,13 +119,13 @@ class VerifyPositiveDiagnosisFragment :
val builder = MaterialDatePicker.Builder.datePicker()
val constraints = CalendarConstraints.Builder()

val twoWeeksAgo = LocalDate.now().plusDays(-14).atStartOfDay(ZoneId.of("UTC")).toInstant()
val twoWeeksAgo = LocalDate.now().plusDays(-14).toInstant()
.toEpochMilli()

// Day in the past or 14 days back
val fromWhen = dayInPast ?: twoWeeksAgo

val untilNow = LocalDate.now().atStartOfDay(ZoneId.of("UTC")).toInstant().toEpochMilli()
val untilNow = LocalDate.now().toInstant().toEpochMilli()

constraints.setValidator(BaseDateValidator { it in fromWhen..untilNow })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class VerifyPositiveDiagnosisViewModel(
setDiagnosisVerification(
diagnosisVerification.value?.copy(
symptomsStartDate = if (noSymptoms) null else symptomDate,
possibleInfectionDate = if (!noSymptoms) null else diagnosisVerification.value?.possibleInfectionDate,
testDate = if (!noSymptoms) null else diagnosisVerification.value?.testDate,
noSymptoms = noSymptoms
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.covidwatch.android.ui.util

import org.covidwatch.android.extension.toInstant
import org.covidwatch.android.extension.toLocalDate
import java.time.Instant
import java.time.LocalDate
Expand Down Expand Up @@ -46,8 +47,7 @@ object DateFormatter {

fun symptomDate(date: String?) =
date?.takeIf { it.isNotEmpty() }
?.let { LocalDate.parse(date).atStartOfDay(ZoneId.of("UTC")) }
?.toInstant()
?.let { LocalDate.parse(date).toInstant() }

@JvmStatic
fun formatDateAndTime(time: Instant?): String =
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_region_name_dropdown.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
style="?spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeight"
android:layout_height="?android:listPreferredItemHeightSmall"
android:background="@drawable/bg_item_region"
android:ellipsize="marquee"
android:foreground="?selectableItemBackground"
Expand Down
Loading

0 comments on commit 21cb2a7

Please sign in to comment.