-
-
Notifications
You must be signed in to change notification settings - Fork 45
Phase 2 Connect Merge Fixes #3034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThis set of changes refactors the ConnectID-related login and redirection logic across multiple activities in the application. The previous approach, which relied on a Sequence Diagram(s)sequenceDiagram
participant User
participant LoginActivity
participant ConnectIDManager
participant HomeScreenActivity
participant DispatchActivity
User->>LoginActivity: Launches app / attempts login
LoginActivity->>ConnectIDManager: evaluateConnectAppState()
ConnectIDManager-->>LoginActivity: Returns ConnectAppMangement state
LoginActivity->>LoginActivity: Sets connectAppState
LoginActivity->>LoginActivity: loginManagedByConnectId() checks connectAppState
LoginActivity->>LoginActivity: Handles login flow based on state
LoginActivity->>DispatchActivity: setResultAndFinish() with intent extras
DispatchActivity->>DispatchActivity: Checks redirectToConnectHome / redirectToConnectOpportunityInfo flags
alt redirectToConnectHome
DispatchActivity->>HomeScreenActivity: Navigate to Connect Jobs List
else redirectToConnectOpportunityInfo
DispatchActivity->>HomeScreenActivity: Navigate to Opportunity Info screen
else no flags
DispatchActivity->>HomeScreenActivity: Launch home screen
end
Possibly related PRs
Suggested labels
Suggested reviewers
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
app/src/org/commcare/activities/LoginActivity.java (1)
217-229: 🛠️ Refactor suggestionHandle unlock failures in Connect flow
When
unlockConnectreturnsfalse, there's no fallback. Adding a user-facing error or a manual login fallback would prevent leaving the user stranded.
🧹 Nitpick comments (7)
app/src/org/commcare/activities/StandardHomeActivityUIController.java (3)
55-55: Consider using a modern collection typeThe use of
Vector<String>is unusual in contemporary Java. Consider returning aList<String>(e.g.,ArrayList<String>) instead for simpler usage unless you require thread-safe synchronization.
74-76: Clarify the job status checkHiding the "connect" button when
shouldShowJobStatus()is false may be correct, but the method name can be confusing in context. Adding a short comment on why you're tying tile visibility to job status can aid maintainability.
115-120: Consider caching the tileRepeatedly calling
findViewById(R.id.connect_alert_tile)could incur minor overhead if triggered often. Consider storing the tile reference in a field or confirm this is only invoked occasionally.app/src/org/commcare/activities/LoginActivityUIController.java (1)
175-185: Handle UI flow on failed unlockIn
setUpConnectUiListeners(), resetting toUnmanagedwhen the password field gains focus is logical. However, ifunlockConnect(...)fails in the button click, consider providing user feedback or a retry path to prevent silent failures.app/src/org/commcare/activities/LoginActivity.java (3)
499-508: Provide error handling on failed Connect unlockIf
unlockConnectfails, this method simply finishes without informing the user. Consider adding an error message or log to clarify the failure.
510-524: Cleanly managed Connect sign-in failureUsing a switch expression for Connect states is clear. As a minor improvement, logging additional details (like username) could help later troubleshooting.
915-939: Tighten up complex Connect state transitions
evaluateConnectAppState()branches heavily on multiple conditions. Consider splitting it into smaller helpers or adding comments to guide future maintainers through the logic.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
app/res/layout/home_screen.xml(1 hunks)app/src/org/commcare/activities/DispatchActivity.java(5 hunks)app/src/org/commcare/activities/HomeScreenBaseActivity.java(2 hunks)app/src/org/commcare/activities/LoginActivity.java(9 hunks)app/src/org/commcare/activities/LoginActivityUIController.java(7 hunks)app/src/org/commcare/activities/StandardHomeActivity.java(0 hunks)app/src/org/commcare/activities/StandardHomeActivityUIController.java(4 hunks)app/src/org/commcare/connect/ConnectIDManager.java(5 hunks)
💤 Files with no reviewable changes (1)
- app/src/org/commcare/activities/StandardHomeActivity.java
🧰 Additional context used
🧬 Code Graph Analysis (3)
app/src/org/commcare/activities/HomeScreenBaseActivity.java (1)
app/src/org/commcare/activities/DispatchActivity.java (1)
DispatchActivity(37-497)
app/src/org/commcare/connect/ConnectIDManager.java (2)
app/src/org/commcare/connect/database/ConnectUserDatabaseUtil.java (1)
ConnectUserDatabaseUtil(11-71)app/src/org/commcare/connect/workers/ConnectHeartbeatWorker.kt (1)
context(12-28)
app/src/org/commcare/activities/LoginActivityUIController.java (2)
app/src/org/commcare/connect/ConnectIDManager.java (1)
ConnectIDManager(69-701)app/src/org/commcare/connect/database/ConnectUserDatabaseUtil.java (1)
ConnectUserDatabaseUtil(11-71)
🔇 Additional comments (23)
app/res/layout/home_screen.xml (1)
21-21: Good change to default visibility.Setting the Connect alert tile to initially hidden is a good practice since it should only be visible under specific conditions, which are now handled dynamically at runtime. This avoids unnecessary UI elements taking up space when not relevant.
app/src/org/commcare/activities/HomeScreenBaseActivity.java (2)
5-5: Added import for the new redirection constant.This import supports the new redirection mechanism being implemented in this PR.
581-586: Improved redirection handling with explicit intent extras.This change improves the navigation flow by replacing the previous approach of setting a pending action on
ConnectIDManagerwith a more explicit intent-based communication. This follows standard Android patterns for activity communication and reduces dependency on global state, making the code more maintainable and testable.app/src/org/commcare/activities/DispatchActivity.java (5)
53-53: Added new constant for redirect flag.This constant is part of the new intent-based redirection approach, providing a stable key for intent extras.
85-86: Added explicit redirection state flags.These boolean flags improve the architecture by maintaining redirection state locally in DispatchActivity rather than relying on global state in ConnectIDManager. This makes the control flow more explicit and easier to trace.
204-211: Refactored dispatch logic to use direct flag checks.This implementation improves the code by:
- Using explicit boolean flags instead of querying ConnectIDManager's pendingAction
- Making the redirection logic more self-contained and traceable
- Reducing coupling between DispatchActivity and ConnectIDManager
The conditional checks are clear and handle the redirection cases appropriately.
446-447: Updated onActivityResult to handle new intent extras.This properly captures the redirection flag from returned intents, completing the intent-based communication approach between activities. This is consistent with the changes in HomeScreenBaseActivity where this flag is set.
484-484: Updated connectManagedLogin handling to use local flags.Previously this would have set a pending action on ConnectIDManager, but now it directly sets the local redirection flag, consistent with the new architecture approach.
app/src/org/commcare/connect/ConnectIDManager.java (4)
630-630: Improved method name for better readability.Renaming from
evalAppStatetoevaluateAppStateuses a more complete verb form, making the code more readable and consistent with naming conventions.
642-642: Updated method call to match the renamed method.This change ensures consistency with the renamed
evaluateAppStatemethod.
684-692: Added new method for conditional job status visibility.This method centralizes the logic for determining when to show job status based on app and job state. This supports the more dynamic UI approach, where visibility is controlled by runtime checks rather than static layout attributes.
The logic correctly handles null checking and the special case of hiding the status when in a learning app with a delivering job state.
574-574:Details
❓ Verification inconclusive
Simplified method by removing redundant checks.
The method now directly returns the user ID from the user record. Since this method is called only after verifying the user exists (in contexts where
isLoggedIN()is true), this simplification is valid. However, ensure caller methods properly handle potential null values.Let's verify all usages of
getConnectUsernameto ensure they handle the case where the user might be null:
🏁 Script executed:
#!/bin/bash # Find all places where getConnectUsername is called rg "getConnectUsername" --type javaLength of output: 259
Verified: Usage of
getConnectUsernameis Safe in the Current ContextThe changes have been verified with the following points:
Simplified User ID Retrieval:
The method now directly returns the user ID viareturn ConnectUserDatabaseUtil.getUser(context).getUserId();Our search shows that aside from its declaration in
ConnectIDManager.java, it’s only referenced inLoginActivity.java. This indicates that the call site is already within a context (e.g., after a successful login) that ensures a valid user is present.Method Renaming:
RenamingevalAppStatetoevaluateAppStateenhances clarity and consistency in verb usage.New Job Status Logic:
The addition ofshouldShowJobStatuscentralizes the logic for displaying the job status. Its implementation aligns well with the refactored dynamic UI requirements.Recommendation:
Ensure that any future callers ofgetConnectUsernameare also protected by proper null or login state checks. This will maintain the safety of directly returning the user ID and prevent potential null pointer issues.app/src/org/commcare/activities/StandardHomeActivityUIController.java (2)
44-44: Invoke secondary phone confirmation tile earlyCalling
updateSecondaryPhoneConfirmationTile()insetupUI()ensures the tile is updated at initialization. This approach looks good.
109-113: Verify intent-based login flag
getBooleanExtra(LoginActivity.CONNECTID_MANAGED_LOGIN, false)might not remain accurate if the activity restarts with a fresh Intent. Confirm that this logic will still work when the activity is relaunched or receives updated extras.app/src/org/commcare/activities/LoginActivityUIController.java (4)
3-5: New static imports for Connect app statesUsing static imports for the Connect-related enums is concise and readable. No issues found.
31-31: Additional Connect user database importImporting
ConnectUserDatabaseUtilis aligned with usage inrefreshConnectView(). No concerns here.
172-173: Delegating Connect UI setupInvoking
setUpConnectUiListeners()duringsetupUI()keeps the Connect-related listeners organized and consistent.
533-556: Defensive check for Connect user record
ConnectUserDatabaseUtil.getUser(activity)should be safe ifConnectIDManager.isLoggedIN()is accurate, but adding a null check would prevent edge-case crashes if the user record is inaccessible or the DB is corrupted.app/src/org/commcare/activities/LoginActivity.java (5)
3-7: New static imports for Connect integrationThese static imports for constants and enums help keep the codebase concise. No issues found.
121-121: Defaulting connectAppState to UnmanagedStarting in
Unmanagedmode is straightforward. Verify that subsequent Connect flows always reevaluate state when needed to avoid confusion.
488-491: Attach Connect extras for redirectionSetting extras like
REDIRECT_TO_CONNECT_OPPORTUNITY_INFOgives the receiving activity context to redirect properly. Confirm that the downstream logic consumes these extras as intended.
941-943: Simple login management check
loginManagedByConnectId()cleanly distinguishes Connect-based scenarios from standard login. Good use of a helper method.
945-951: Straightforward get/set approachThese getters and setters keep
connectAppStateusage explicit. No issues found.
… here, instead it should be set through refreshConnectView()
…cess connect db otherwise
3a23cc2 to
4102a88
Compare
OrangeAndGreen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments but nothing that necessarily prevents going forward
Technical Summary
Some final set of fixes/refactor before we merge the phase 2 connect code into
master. A bunch of commits are just to bring missing code from latestconnect_qabranch to here.Best reviewed commit by commit.
Safety story
I have tried to make some calls here to what makes best sense to me and might introduce a regression with a special case handling on Login Screen that I am unaware of. I am mostly relying on review to spot any such edge case handling. I would like reviewer to pay special attention to login inputs visibility and connect app state management.
QA Plan
Will be QA'ed with phase 2 QA
Labels and Review