Skip to content

Commit

Permalink
fix: scan qrcode in networking and event spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed May 18, 2024
1 parent 835b570 commit ee916e6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun Event(
) {
LazyColumn(
modifier = modifier,
contentPadding = PaddingValues(vertical = 24.dp),
contentPadding = PaddingValues(top = 24.dp, bottom = 72.dp),
verticalArrangement = Arrangement.spacedBy(24.dp)
) {
item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
Expand Down Expand Up @@ -124,17 +124,16 @@ fun TicketDetailed(
.placeholder(isLoading)
)
if (qrCode != null) {
BoxWithConstraints {
Image(
bitmap = qrCode.asImageBitmap(),
contentDescription = stringResource(
Resource.string.semantic_ticket_qrcode
),
modifier = Modifier
.size(this.maxWidth * TicketRatio)
.placeholder(isLoading)
)
}
Image(
bitmap = qrCode.asImageBitmap(),
contentDescription = stringResource(
Resource.string.semantic_ticket_qrcode
),
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
.placeholder(isLoading)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fun Main(
onItineraryClicked = onItineraryClicked,
onScheduleStarted = onScheduleStarted,
onProfileCreated = onProfileCreated,
savedStateHandle = navController.currentBackStackEntry?.savedStateHandle,
navController = navController
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.unit.toSize
import androidx.lifecycle.SavedStateHandle
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.NavType
Expand Down Expand Up @@ -62,7 +59,6 @@ import org.gdglille.devfest.android.theme.m3.style.adaptive.isCompat
import org.gdglille.devfest.android.theme.m3.style.adaptive.isMedium
import org.gdglille.devfest.android.theme.m3.style.appbars.iconColor
import org.gdglille.devfest.models.ui.ExportNetworkingUi
import org.gdglille.devfest.models.ui.VCardModel
import org.gdglille.devfest.models.ui.convertToModelUi
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource
Expand All @@ -89,26 +85,9 @@ fun MainNavigation(
onScheduleStarted: () -> Unit,
onProfileCreated: () -> Unit,
modifier: Modifier = Modifier,
savedStateHandle: SavedStateHandle? = null,
navController: NavHostController = rememberNavController(),
viewModel: MainNavigationViewModel = koinViewModel()
) {
if (savedStateHandle != null) {
val qrCodeTicket by savedStateHandle.getLiveData<String>(ResultKey.QR_CODE_TICKET)
.observeAsState()
val qrCodeVCard by savedStateHandle.getLiveData<VCardModel>(ResultKey.QR_CODE_VCARD)
.observeAsState()
LaunchedEffect(qrCodeTicket, qrCodeVCard) {
qrCodeTicket?.let {
viewModel.saveTicket(it)
savedStateHandle.remove<String>(ResultKey.QR_CODE_TICKET)
}
qrCodeVCard?.let {
viewModel.saveNetworkingProfile(it.convertToModelUi())
savedStateHandle.remove<String>(ResultKey.QR_CODE_VCARD)
}
}
}
val rootUri = "c4h://event"
val config = LocalConfiguration.current
val uiState = viewModel.uiState.collectAsState()
Expand Down Expand Up @@ -379,10 +358,7 @@ fun MainNavigation(
VCardQrCodeScanner(
navigateToSettingsScreen = {},
onQrCodeDetected = { vcard ->
navController
.previousBackStackEntry
?.savedStateHandle
?.set(ResultKey.QR_CODE_VCARD, vcard)
viewModel.saveNetworkingProfile(vcard.convertToModelUi())
navController.popBackStack()
},
onBackClicked = { navController.popBackStack() }
Expand All @@ -392,10 +368,7 @@ fun MainNavigation(
TicketQrCodeScanner(
navigateToSettingsScreen = {},
onQrCodeDetected = { barcode ->
navController
.previousBackStackEntry
?.savedStateHandle
?.set(ResultKey.QR_CODE_TICKET, barcode)
viewModel.saveTicket(barcode)
navController.popBackStack()
},
onBackClicked = { navController.popBackStack() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun ContactsScreen(
UserItem(
displayName = "${user.firstName} ${user.lastName}",
email = user.email,
company = user.email,
company = user.company,
onClick = { openDialog.value = true }
)
if (index < users.size - 1) {
Expand Down

0 comments on commit ee916e6

Please sign in to comment.