Skip to content

Show user profile and dining barcode on Account page - #287

Open
flau1019 wants to merge 5 commits into
mainfrom
barcode_UI
Open

flau1019 wants to merge 5 commits into
mainfrom
barcode_UI

Conversation

@flau1019

@flau1019 flau1019 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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
  • Drop a late profile response if the user logged out or switched accounts while it was in flight

Barcode

  • Draw the GET barcode as a PDF417 symbol with ZXing (Pdf417Encoder), black on white even in dark mode
  • Regenerate it every 5 seconds from the cached credentials while the sheet is open, matching iOS; 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

Test Coverage

  • Unit tests for Pdf417Encoder and BarcodeGenerator
  • Tested on the emulator and in previews with a personal Cornell ID

Next Steps (optional)

Related PRs or Issues (optional)

Builds on #286 (retrieve and store barcode data).

Screenshots (optional)

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
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: abddb235-e8a6-436f-a1de-3fc7695fbce8
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@flau1019
flau1019 requested review from caleb-bit and mqiu90 and removed request for caleb-bit November 19, 2026 15:56

@caleb-bit caleb-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +230 to +232
val pin = getAccountRepository.getPin() ?: throw e
val refreshResult = getAccountRepository.refreshLogin(pin = pin)
if (refreshResult is Result.Error) throw IllegalStateException("refreshLogin failed")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 } }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@flau1019 flau1019 changed the title Show user profile and barcode sheet on Account page Show user profile and dining barcode on Account page Nov 29, 2026
@flau1019
flau1019 requested review from caleb-bit and mqiu90 November 29, 2026 03:24
is Result.Success -> {
onNetworkSuccess()
refreshBarcodeData()
refreshProfileAndBarcodeData()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea that makes sense

* margin around it so scanners can find its edges.
*/
@Composable
private fun DiningBarcode(barcodeUiState: BarcodeUiState) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea that makes sense

Comment thread app/src/main/res/values/strings.xml Outdated
<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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: lowk we should use more general wording, something like "Barcode unavailable right now. Please try again later."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

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.
@flau1019
flau1019 requested a review from mqiu90 November 29, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants