Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
code smell fixes (EXPOSURAPP-3058) (#1330)
Browse files Browse the repository at this point in the history
* code smell fix for SubmissionQRCodeScanFragment.kt

* code smell fix for RetrieveDiagnosisKeysTransaction.kt

* code smell fix for GoogleAPIVersion.kt

* code smell fix for GoogleAPIVersion.kt

* Update RetrieveDiagnosisKeysTransaction.kt

* Update GoogleAPIVersion.kt

* Update DownloadInfo.kt

* simplified logic

* Revert "simplified logic"

This reverts commit a419e5b.

* simplified logic

Co-authored-by: Ralf Gehrer <ralfgehrer@users.noreply.github.com>
  • Loading branch information
AndroidMedaGalaxy and ralfgehrer committed Oct 7, 2020
1 parent e17b605 commit 1948fd8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
Expand Up @@ -10,8 +10,9 @@ data class DownloadInfo(
val serverMD5 by lazy { headers.getPayloadChecksumMD5() }

private fun Headers.getPayloadChecksumMD5(): String? {
// TODO EXPOSUREBACK-178

val fileMD5 = values("ETag").singleOrNull()
// TODO EXPOSUREBACK-178
// var fileMD5 = headers.values("x-amz-meta-cwa-hash-md5").singleOrNull()
// if (fileMD5 == null) {
// headers.values("x-amz-meta-cwa-hash").singleOrNull()
Expand Down
Expand Up @@ -199,11 +199,7 @@ object RetrieveDiagnosisKeysTransaction : Transaction() {
.asyncRetrieveApplicationConfiguration()
.supportedCountriesList
}

if (CWADebug.isDebugBuildOrMode) {
onKeyFilesDownloadStarted?.invoke()
onKeyFilesDownloadStarted = null
}
invokeSubmissionStartedInDebugOrBuildMode()

val availableKeyFiles = executeFetchKeyFilesFromServer(countries)

Expand All @@ -218,11 +214,7 @@ object RetrieveDiagnosisKeysTransaction : Transaction() {

onKeyFilesDownloadFinished?.invoke(availableKeyFiles.size, totalFileSize)
onKeyFilesDownloadFinished = null
}

if (CWADebug.isDebugBuildOrMode) {
onApiSubmissionStarted?.invoke()
onApiSubmissionStarted = null
invokeSubmissionStartedInDebugOrBuildMode()
}

val isSubmissionSuccessful = executeAPISubmission(
Expand All @@ -231,16 +223,27 @@ object RetrieveDiagnosisKeysTransaction : Transaction() {
token = token
)

if (CWADebug.isDebugBuildOrMode) {
onApiSubmissionFinished?.invoke()
onApiSubmissionFinished = null
}
invokeSubmissionFinishedInDebugOrBuildMode()

if (isSubmissionSuccessful) executeFetchDateUpdate(currentDate)

executeClose()
}

private fun invokeSubmissionStartedInDebugOrBuildMode() {
if (CWADebug.isDebugBuildOrMode) {
onApiSubmissionStarted?.invoke()
onApiSubmissionStarted = null
}
}

private fun invokeSubmissionFinishedInDebugOrBuildMode() {
if (CWADebug.isDebugBuildOrMode) {
onApiSubmissionFinished?.invoke()
onApiSubmissionFinished = null
}
}

override suspend fun rollback() {
super.rollback()
try {
Expand Down
Expand Up @@ -156,17 +156,15 @@ class SubmissionQRCodeScanFragment : Fragment(R.layout.fragment_submission_qr_co
permissions: Array<String>,
grantResults: IntArray
) {
if (requestCode == REQUEST_CAMERA_PERMISSION_CODE) {

// permission was denied
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_DENIED)) {
// if permission was denied
if (requestCode == REQUEST_CAMERA_PERMISSION_CODE &&
(grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_DENIED)) {
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
showCameraPermissionRationaleDialog()
} else {
// user permanently denied access to the camera
showCameraPermissionDeniedDialog()
}
}
}
}

Expand Down
Expand Up @@ -22,8 +22,10 @@ class GoogleAPIVersion @Inject constructor() {
val currentVersion = InternalExposureNotificationClient.getVersion()
currentVersion >= compareVersion
} catch (apiException: ApiException) {
if (apiException.statusCode == CommonStatusCodes.API_NOT_CONNECTED) false
else throw apiException
if (apiException.statusCode != CommonStatusCodes.API_NOT_CONNECTED) {
throw apiException
}
return false
}
}

Expand Down

0 comments on commit 1948fd8

Please sign in to comment.