Skip to content

Commit

Permalink
Replace ScanQrDialog with the KMM ScanQrCodeDialog.
Browse files Browse the repository at this point in the history
There were significant layout problems with the old QR code reader: the camera
image was often misaligned, the borders were offset, the image could be
squished, and the misalignment was inconsistent. The new QR code scanner looks
much better behaved, though we lose the brackets that used to be there.

Tested by:
- Manual testing of both issuance and identity verification.
- ./gradlew check
- ./gradlew connectedCheck

Signed-off-by: Kevin Deus <[email protected]>
  • Loading branch information
kdeus committed Nov 22, 2024
1 parent 3577eae commit cd1c59d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.android.identity.appsupport.ui.qrcode.ScanQrCodeDialog
import com.android.identity.issuance.IssuingAuthorityConfiguration
import com.android.identity.issuance.remote.WalletServerProvider
import com.android.identity.util.Logger
Expand All @@ -38,7 +39,6 @@ import com.android.identity_credential.wallet.WalletApplication
import com.android.identity_credential.wallet.credentialoffer.extractCredentialIssuerData
import com.android.identity_credential.wallet.navigation.WalletDestination
import com.android.identity_credential.wallet.ui.ScreenWithAppBarAndBackButton
import com.android.identity_credential.wallet.ui.qrscanner.ScanQrDialog
import com.android.identity_credential.wallet.util.getUrlQueryFromCustomSchemeUrl
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -100,13 +100,6 @@ fun AddToWalletScreen(
// to navigate after scanning a Qr code
navigateToOnComposable.value?.let { route -> onNavigate(route) }

/**
* Helper function for hiding [ScanQrDialog] from current view.
*/
fun dismissScanQrDialog() {
showQrScannerDialog.value = false
}

ScreenWithAppBarAndBackButton(
title = stringResource(R.string.add_screen_title),
onBackButtonClick = { onNavigate(WalletDestination.PopBackStack.route) }
Expand All @@ -121,13 +114,10 @@ fun AddToWalletScreen(
} else {
// compose ScanQrDialog when user taps on "Scan Credential Offer"
if (showQrScannerDialog.value) {
ScanQrDialog(
modifier = Modifier
.fillMaxWidth(0.9f)
.fillMaxHeight(0.6f),
ScanQrCodeDialog(
title = stringResource(R.string.credential_offer_scan),
description = stringResource(id = R.string.credential_offer_details),
onScannedQrCode = { qrCodeTextUrl ->
onCodeScanned = { qrCodeTextUrl ->
// filter only for OID4VCI Url schemes.
if (qrCodeTextUrl.startsWith(WalletApplication.OID4VCI_CREDENTIAL_OFFER_URL_SCHEME)) {
// scanned text is expected to be an encoded Url
Expand All @@ -145,8 +135,13 @@ fun AddToWalletScreen(
}
}
}
true
},
onClose = { dismissScanQrDialog() }
dismissButton = stringResource(R.string.reader_screen_scan_qr_dialog_dismiss_button),
onDismiss = { showQrScannerDialog.value = false },
modifier = Modifier
.fillMaxWidth()//0.9f)
.fillMaxHeight(0.6f),
)
} else { // not showing [ScanQrDialog]
AddToWalletScreenWithIssuerDisplayDatas(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import com.android.identity.appsupport.ui.qrcode.ScanQrCodeDialog
import com.android.identity.cbor.Cbor
import com.android.identity.cbor.DiagnosticOption
import com.android.identity.documenttype.DocumentTypeRepository
Expand All @@ -81,7 +82,6 @@ import com.android.identity_credential.wallet.navigation.WalletDestination
import com.android.identity_credential.wallet.ui.KeyValuePairHtml
import com.android.identity_credential.wallet.ui.KeyValuePairText
import com.android.identity_credential.wallet.ui.ScreenWithAppBarAndBackButton
import com.android.identity_credential.wallet.ui.qrscanner.ScanQrDialog
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import kotlinx.datetime.Instant
Expand Down Expand Up @@ -173,10 +173,15 @@ private fun WaitForEngagement(
var dropdownSelected = remember { mutableStateOf(availableRequests[0]) }

if (showQrScannerDialog.value) {
ScanQrDialog(title = stringResource(R.string.reader_screen_scan_qr_dialog_title),
ScanQrCodeDialog(
title = stringResource(R.string.reader_screen_scan_qr_dialog_title),
description = stringResource(R.string.reader_screen_scan_qr_dialog_text),
onScannedQrCode = { qrCodeText -> model.setQrCode(qrCodeText) },
onClose = { showQrScannerDialog.value = false }
onCodeScanned = { qrCodeText ->
model.setQrCode(qrCodeText)
true
},
dismissButton = stringResource(R.string.reader_screen_scan_qr_dialog_dismiss_button),
onDismiss = { showQrScannerDialog.value = false },
)
}

Expand Down

This file was deleted.

0 comments on commit cd1c59d

Please sign in to comment.