Repository navigation
Conversation
Add a profile card with the user's photo, name, and email, plus a Barcode button that opens a Dining Barcode sheet (barcode rendering comes later). - Fetch the profile from POST /users/get-profile after financials load, renewing an expired GET session and retrying once on 401 - Join first/middle/last name and decode the base64 photo - Keep the profile in memory only and clear it on logout; exclude the response body from network logs, per the backend's no-cache/no-log note
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
caleb-bit
left a comment
There was a problem hiding this comment.
Looks good so far, but the PR should include the actual barcode generation setup since you're already making it visible in the profiles screen. Otherwise we're merging in a feature that doesn't work. I believe you should be able to use Mabel's code to finalize this feature.
| val pin = getAccountRepository.getPin() ?: throw e | ||
| val refreshResult = getAccountRepository.refreshLogin(pin = pin) | ||
| if (refreshResult is Result.Error) throw IllegalStateException("refreshLogin failed") |
There was a problem hiding this comment.
this logic seems repeated. can we refactor it out
| * Fetches the user's name, email, and photo. If the GET session has expired (401), gets a | ||
| * new session with the saved PIN and tries once more, like [getFinancials]. | ||
| */ | ||
| suspend fun getProfile(): Result<UserProfile> = resultOfNetworkCall { |
There was a problem hiding this comment.
Do we need this to return anything if we already have the flow? Maybe change function name and return type so it's more of an update function.
| } | ||
| } | ||
| } | ||
| // TODO: render the dining barcode here. |
There was a problem hiding this comment.
barcode code is already on main 'getAccountRepository.getCachedBarcodeCredentials()' which should give u the see and patron ID, and 'BarcodeGenerator.generateBarcode(seed, patronId, nowInSeconds)' gives u the value. i think that it should work by regenerating periodically while the sheet is open, draw it with something like ZXing (ios does this), and show a message if the credentials are null.
| networkApi.getProfile(sessionId = SessionID(getAccountRepository.getSessionId())) | ||
| } | ||
| val profile = withContext(Dispatchers.Default) { response.toUserProfile() } | ||
| _userProfile.value = profile |
There was a problem hiding this comment.
wait if the user logs out while this is loading, the old profile gets saved back after logout. could u only save it if the session ID still matches the one u send, kind of like 'refreshBarcodeData'?
| is Result.Success -> { | ||
| onNetworkSuccess() | ||
| refreshBarcodeData() | ||
| refreshProfile() |
There was a problem hiding this comment.
this runs at the same time as 'refreshBarcodeData()' so if the session expired, both refresh it at once and can break each other. maybe run them one after the other in the same coroutine?
| onBarcodeClicked: () -> Unit = {} | ||
| ) { | ||
| val innerListState = rememberLazyListState() | ||
| val isFirstVisible by remember { derivedStateOf { innerListState.firstVisibleItemIndex > 1 } } |
There was a problem hiding this comment.
this index needs to go up by 2 bc the profile card and spacer added two items at the top
| modifier = Modifier.size(40.dp) | ||
| ) | ||
| Column(modifier = Modifier.padding(start = 12.dp)) { | ||
| userProfile.name?.let { |
There was a problem hiding this comment.
nit: this name/email/avatar row is the same as in 'ProfileCard', so it could be one composable
|
|
||
| private fun ProfilePhoto.toImageBitmap(): ImageBitmap? { | ||
| if (mimeType?.startsWith("image/") == false) return null | ||
| val bytes = runCatching { Base64.decode(data ?: return null, Base64.DEFAULT) } |
There was a problem hiding this comment.
nit: id double check the backend's photo format. if it's 'data:image/...;base64', prefix, this decode would fail
Draw the GET barcode as a PDF417 symbol with ZXing, regenerated every 5 seconds from the cached credentials while the sheet is open, so it works offline. - Show "Barcode unavailable" when no credentials are cached - Load the profile and then refresh the barcode data one after the other, so their session renewals can't invalidate each other - Drop a late profile response if the user logged out or switched accounts while it was in flight - Switch the Account header to the compact title only once the transactions header reaches the top
| is Result.Success -> { | ||
| onNetworkSuccess() | ||
| refreshBarcodeData() | ||
| refreshProfileAndBarcodeData() |
There was a problem hiding this comment.
can we maybe swap these so 'refreshBarcodeData()' runs first? right now the barcode is gonna wait for 'getProfile()' to finish, and that's a lot slower
There was a problem hiding this comment.
yea that makes sense
| * margin around it so scanners can find its edges. | ||
| */ | ||
| @Composable | ||
| private fun DiningBarcode(barcodeUiState: BarcodeUiState) { |
There was a problem hiding this comment.
nit: 'ContentScale.Fit' with 'FilterQuality.None' scales the barcode by a non-whole factor so some of the bars end up 3px and some 4px. i feel like it would be safer to scale by a whole number instead? or maybe someone could try this in the dhall tmr.
There was a problem hiding this comment.
yea that makes sense
| <string name="account_show_transactions">Show transactions</string> | ||
| <string name="account_barcode">Barcode</string> | ||
| <string name="account_dining_barcode">Dining Barcode</string> | ||
| <string name="account_barcode_unavailable">Barcode unavailable. Connect to the internet and reopen your account to load it.</string> |
There was a problem hiding this comment.
nit: lowk we should use more general wording, something like "Barcode unavailable right now. Please try again later."
LoginViewModel is recreated on each visit to the Profile screen, but the profile stays in UserRepository until logout, so refetching it every time was wasted work. Logout clears it, so a new account still fetches its own.
ContentScale.Fit with FilterQuality.None scaled the barcode by a fractional factor, so modules came out a mix of widths (e.g. 7px and 8px). Draw it at the largest whole-number scale that fits so every module is the same number of pixels.
Add a profile card with the user's photo, name, and email, plus a Barcode button that opens a Dining Barcode sheet showing the user's dining barcode.
Overview
Above
Changes Made
Profile
Barcode
Pdf417Encoder), black on white even in dark modeTest Coverage
Pdf417EncoderandBarcodeGeneratorNext Steps (optional)
Related PRs or Issues (optional)
Builds on #286 (retrieve and store barcode data).
Screenshots (optional)