Skip to content

Commit

Permalink
Upstream unrelated changes from the tf branch (#302)
Browse files Browse the repository at this point in the history
* Upstream unrelated changes from the tf branch

- Improve ProductGrid scrolling
- Improve Home Screen layout time
- Dialog lays on top of content rather than its own screen
- Remove cameraConfig from PrepUploadResponse
- Move Bitmap.rotated extension function to Util
- Remove no longer relevant experimental annotations
- Use new AndroidX method for screen state Flowable

* Downgrade Compose
  • Loading branch information
vanshg authored Jan 30, 2024
1 parent 49d2573 commit 89a2699
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 115 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
- Bump CameraX to 1.3.0
- Removed `cameraConfig` from `PrepUploadResponse`

## 10.0.3
### Added
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
accompanist-permissions = "0.34.0"
accompanist-permissions = "0.32.0"
android-gradle-plugin = "8.2.2"
androidx-activity = "1.8.2"
# TODO: Check if https://android-review.googlesource.com/c/platform/frameworks/support/+/2576871 has
# been merged and if so, swap the buttons in ImageCaptureConfirmationDialog
androidx-compose-bom = "2024.01.00"
androidx-compose-bom = "2023.10.01"
androidx-compose-compiler = "1.5.8"
androidx-core = "1.12.0"
androidx-core-splashscreen = "1.0.1"
Expand Down
1 change: 0 additions & 1 deletion lib/src/main/java/com/smileidentity/models/PrepUpload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ data class PrepUploadResponse(
@Json(name = "ref_id") val refId: String,
@Json(name = "upload_url") val uploadUrl: String,
@Json(name = "smile_job_id") val smileJobId: String,
@Json(name = "camera_config") val cameraConfig: String?,
)
22 changes: 22 additions & 0 deletions lib/src/main/java/com/smileidentity/util/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ internal fun isValidDocumentImage(
uri: Uri?,
) = isImageAtLeast(context, uri, width = 1920, height = 1080)

fun Bitmap.rotated(
rotationDegrees: Int,
flipX: Boolean = false,
flipY: Boolean = false,
): Bitmap {
val matrix = Matrix()

// Rotate the image back to straight.
matrix.postRotate(rotationDegrees.toFloat())

// Mirror the image along the X or Y axis.
matrix.postScale(if (flipX) -1.0f else 1.0f, if (flipY) -1.0f else 1.0f)
val rotatedBitmap =
Bitmap.createBitmap(this, 0, 0, width, height, matrix, true)

// Recycle the old bitmap if it has changed.
if (rotatedBitmap !== this) {
recycle()
}
return rotatedBitmap
}

/**
* Post-processes the image stored in [bitmap] and saves to [file]. The image is scaled to
* [maxOutputSize], but maintains the aspect ratio. The image can also converted to grayscale.
Expand Down
25 changes: 1 addition & 24 deletions lib/src/main/java/com/smileidentity/viewmodel/SelfieViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.smileidentity.viewmodel

import android.graphics.Bitmap
import android.graphics.Matrix
import android.util.Size
import androidx.annotation.OptIn
import androidx.annotation.StringRes
Expand Down Expand Up @@ -33,6 +31,7 @@ import com.smileidentity.util.createLivenessFile
import com.smileidentity.util.createSelfieFile
import com.smileidentity.util.getExceptionHandler
import com.smileidentity.util.postProcessImageBitmap
import com.smileidentity.util.rotated
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.coroutines.FlowPreview
Expand Down Expand Up @@ -344,26 +343,4 @@ class SelfieViewModel(
fun onFinished(callback: SmileIDCallback<SmartSelfieResult>) {
callback(result!!)
}

private fun Bitmap.rotated(
rotationDegrees: Int,
flipX: Boolean = false,
flipY: Boolean = false,
): Bitmap {
val matrix = Matrix()

// Rotate the image back to straight.
matrix.postRotate(rotationDegrees.toFloat())

// Mirror the image along the X or Y axis.
matrix.postScale(if (flipX) -1.0f else 1.0f, if (flipY) -1.0f else 1.0f)
val rotatedBitmap =
Bitmap.createBitmap(this, 0, 0, width, height, matrix, true)

// Recycle the old bitmap if it has changed.
if (rotatedBitmap !== this) {
recycle()
}
return rotatedBitmap
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class DocumentViewModelTest {
refId = "refId",
uploadUrl = "uploadUrl",
smileJobId = "smileJobId",
cameraConfig = null,
)

coEvery { SmileID.api.getDocumentVerificationJobStatus(any()) } returns
Expand Down Expand Up @@ -174,7 +173,6 @@ class DocumentViewModelTest {
refId = "refId",
uploadUrl = "uploadUrl",
smileJobId = "smileJobId",
cameraConfig = null,
)

coEvery { SmileID.api.getDocumentVerificationJobStatus(any()) } returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class EnhancedDocumentVerificationViewModelTest {
refId = "refId",
uploadUrl = "uploadUrl",
smileJobId = "smileJobId",
cameraConfig = null,
)

coEvery { SmileID.api.getEnhancedDocumentVerificationJobStatus(any()) } returns
Expand Down Expand Up @@ -174,7 +173,6 @@ class EnhancedDocumentVerificationViewModelTest {
refId = "refId",
uploadUrl = "uploadUrl",
smileJobId = "smileJobId",
cameraConfig = null,
)

coEvery { SmileID.api.getEnhancedDocumentVerificationJobStatus(any()) } returns
Expand Down
9 changes: 4 additions & 5 deletions sample/src/main/java/com/smileidentity/sample/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package com.smileidentity.sample

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.Icons.Filled
import androidx.compose.material.icons.Icons.Outlined
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.automirrored.outlined.List
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.List
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.List
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.ui.graphics.vector.ImageVector

Expand Down Expand Up @@ -77,8 +76,8 @@ enum class BottomNavigationScreen(
Jobs(
"jobs",
R.string.jobs,
Icons.AutoMirrored.Filled.List,
Icons.AutoMirrored.Outlined.List,
Filled.List,
Outlined.List,
),
Resources(
"resources",
Expand Down
40 changes: 24 additions & 16 deletions sample/src/main/java/com/smileidentity/sample/compose/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.AlertDialog
Expand Down Expand Up @@ -47,6 +47,8 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.dialog
import androidx.navigation.compose.rememberNavController
import com.smileidentity.SmileID
import com.smileidentity.compose.BiometricKYC
Expand Down Expand Up @@ -81,23 +83,16 @@ fun MainScreen(
factory = viewModelFactory { MainScreenViewModel() },
),
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val privacyPolicy = remember { URL("https://usesmileid.com/privacy-policy") }
val coroutineScope = rememberCoroutineScope()
val navController = rememberNavController()
val currentRoute by navController
.currentBackStackEntryFlow
.collectAsStateWithLifecycle(initialValue = navController.currentBackStackEntry)

val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val currentRoute by navController.currentBackStackEntryAsState()
val bottomNavSelection = uiState.bottomNavSelection

val bottomNavItems = remember { BottomNavigationScreen.entries.toImmutableList() }
// Show up button when not on a BottomNavigationScreen
val showUpButton = currentRoute?.destination?.route?.let { route ->
bottomNavItems.none { it.route.contains(route) }
} ?: false

val dialogDestinations = remember { listOf(ProductScreen.SmartSelfieAuthentication.route) }
val clipboardManager = LocalClipboardManager.current

LaunchedEffect(uiState.clipboardText) {
uiState.clipboardText?.let { text ->
coroutineScope.launch {
Expand All @@ -109,6 +104,10 @@ fun MainScreen(
modifier = modifier,
snackbarHost = { Snackbar() },
topBar = {
// Show up button when not on a BottomNavigationScreen
val showUpButton = currentRoute?.destination?.route?.let { route ->
bottomNavItems.none { it.route.contains(route) }
} ?: false
TopBar(
showUpButton = showUpButton,
onNavigateUp = navController::navigateUp,
Expand All @@ -119,7 +118,13 @@ fun MainScreen(
// Don't show bottom bar when navigating to any product screens
val showBottomBar by remember(currentRoute) {
derivedStateOf {
bottomNavItems.any { it.route.contains(currentRoute?.destination?.route ?: "") }
val isDirectlyOnBottomNavDestination = bottomNavItems.any {
it.route.contains(currentRoute?.destination?.route ?: "")
}
val isOnDialogDestination = dialogDestinations.any {
it.contains(currentRoute?.destination?.route ?: "")
}
return@derivedStateOf isDirectlyOnBottomNavDestination || isOnDialogDestination
}
}
if (showBottomBar) {
Expand Down Expand Up @@ -175,10 +180,13 @@ fun MainScreen(
navController.popBackStack()
}
}
composable(ProductScreen.SmartSelfieAuthentication.route) {
dialog(ProductScreen.SmartSelfieAuthentication.route) {
LaunchedEffect(Unit) { viewModel.onSmartSelfieAuthenticationSelected() }
SmartSelfieAuthenticationUserIdInputDialog(
onDismiss = navController::popBackStack,
onDismiss = {
viewModel.onHomeSelected()
navController.popBackStack()
},
onConfirm = { userId ->
navController.navigate(
"${ProductScreen.SmartSelfieAuthentication.route}/$userId",
Expand Down Expand Up @@ -354,7 +362,7 @@ private fun TopBar(
if (showUpButton) {
IconButton(onClick = onNavigateUp) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(R.string.back),
)
}
Expand Down
Loading

0 comments on commit 89a2699

Please sign in to comment.