Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/org/commcare/activities/CommCareSetupActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ protected void onResumeFragments() {
uiStateScreenTransition();
}

@Override
protected boolean shouldShowDrawer() {
return true;
}
Comment on lines +318 to +321
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Drawer visibility opt-in added; ensure late initialization after login is handled

Overriding shouldShowDrawer() is correct. However, the base now initializes the drawer only in onCreate when isPersonalIdLoggedIn() is true. If a user signs in (e.g., via Connect) while this activity remains in the foreground, the drawer will not appear until the activity is recreated.

Recommend adding a late-init hook in BaseDrawerActivity (e.g., in onResume) to set up the drawer when login state changes, or an exposed method to “ensure” initialization.

If desired, I can provide a small base-class patch to initialize the drawer in onResume when shouldShowDrawer() and login are satisfied.


I’ll inspect both BaseDrawerActivity’s initialization logic and CommCareSetupActivity’s override to confirm the drawer gating behavior.


🏁 Script executed:

#!/bin/bash
# Find BaseDrawerActivity
BASE_FILE=$(rg -l "class BaseDrawerActivity")
echo "BaseDrawerActivity file: $BASE_FILE"
rg -n "onCreate" $BASE_FILE
rg -n "shouldShowDrawer" $BASE_FILE
rg -n "drawer" $BASE_FILE | grep -i init
rg -n "onResume" $BASE_FILE

# Find CommCareSetupActivity
SETUP_FILE=$(rg -l "class CommCareSetupActivity")
echo "CommCareSetupActivity file: $SETUP_FILE"
rg -n "extends BaseDrawerActivity" $SETUP_FILE
rg -n "shouldShowDrawer" $SETUP_FILE

# Check where login state is evaluated
rg -n "isPersonalIdLoggedIn" -n .

Length of output: 2222


Ensure drawer appears after login in CommCareSetupActivity

BaseDrawerActivity (app/src/org/commcare/navdrawer/BaseDrawerActivity.kt:14-18) only sets up the nav-drawer in onCreate when both shouldShowDrawer() and isPersonalIdLoggedIn() are true.
CommCareSetupActivity (app/src/org/commcare/activities/CommCareSetupActivity.java:318-321) opts in to showing the drawer, but if the user logs in (via Connect) after onCreate, the drawer never initializes until the activity is recreated.

Recommend one of:

  • In BaseDrawerActivity, override onResume() to run your existing drawer-init logic when shouldShowDrawer() && isPersonalIdLoggedIn() && drawer isn’t yet initialized.
  • Or expose a protected ensureDrawerInitialized() method in BaseDrawerActivity and invoke it from CommCareSetupActivity immediately after login completes.

This will guarantee the drawer appears without forcing an activity restart.


@Override
public void onURLChosen(String url) {
incomingRef = url;
Expand Down
19 changes: 13 additions & 6 deletions app/src/org/commcare/activities/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,8 @@ protected void onCreate(Bundle savedInstanceState) {

uiController.setupUI();
formAndDataSyncer = new FormAndDataSyncer();


uiController.checkForGlobalErrors();

personalIdManager = PersonalIdManager.getInstance();
personalIdManager.init(this);

initPersonaIdManager();
presetAppId = getIntent().getStringExtra(EXTRA_APP_ID);
appLaunchedFromConnect = getIntent().getBooleanExtra(IS_LAUNCH_FROM_CONNECT, false);
connectLaunchPerformed = false;
Expand All @@ -180,6 +175,13 @@ && new RootBeer(this).isRooted()) {
}
}

private void initPersonaIdManager() {
if (personalIdManager == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Seems like personalIdManager will always be null here since this method is called in onCreate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

think I was afraid if someone call it from somewhere else we will end up re-initing it, so just more of a safe keeping but can remove if you prefer that.

personalIdManager = PersonalIdManager.getInstance();
personalIdManager.init(this);
}
}

private boolean shouldDoConnectLogin() {
return appLaunchedFromConnect && !connectLaunchPerformed;
}
Expand Down Expand Up @@ -1008,6 +1010,11 @@ public void setConnectAppState(PersonalIdManager.ConnectAppMangement connectAppS
this.connectAppState = connectAppState;
}

@Override
protected boolean shouldShowDrawer() {
return true;
}

protected PersonalIdManager.ConnectAppMangement getConnectAppState() {
return connectAppState;
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/org/commcare/activities/StandardHomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ public boolean usesSubmissionProgressBar() {
return false;
}

@Override
protected boolean shouldShowDrawer() {
return true;
}

@Override
public void refreshUI() {
uiController.refreshView();
Expand Down
35 changes: 21 additions & 14 deletions app/src/org/commcare/navdrawer/BaseDrawerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,34 @@ abstract class BaseDrawerActivity<T> : CommCareActivity<T>() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setupDrawerController()
if (shouldShowDrawer() && isPersonalIdLoggedIn()) {
setupDrawerController()
}
}
Comment on lines +16 to 19
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Drawer setup gated in onCreate only — add late-init on resume

The gating is correct, but initialization occurs only in onCreate. If login state flips to “logged-in” while an activity remains active (e.g., user signs in on Setup), the drawer won’t appear until recreation.

Add an onResume check to initialize when conditions become true and drawerController is null.

Example addition (outside this range):

override fun onResume() {
    super.onResume()
    if (drawerController == null && shouldShowDrawer() && isPersonalIdLoggedIn()) {
        setupDrawerController()
    }
}
🤖 Prompt for AI Agents
In app/src/org/commcare/navdrawer/BaseDrawerActivity.kt around lines 16 to 19,
the drawer is only initialized in onCreate so if the user becomes logged-in
while the activity is still running the drawer won’t appear; add an onResume
override that checks if drawerController is null and shouldShowDrawer() &&
isPersonalIdLoggedIn() and calls setupDrawerController() so the drawer is lazily
initialized when login state flips while activity is active.


protected fun setupDrawerController() {
private fun isPersonalIdLoggedIn(): Boolean {
val personalIdManager = PersonalIdManager.getInstance()
personalIdManager.init(this)
if (personalIdManager.isloggedIn()) {
val rootView = findViewById<View>(android.R.id.content)
val drawerRefs = DrawerViewRefs(rootView)
drawerController = BaseDrawerController(
this,
drawerRefs
) { navItemType: NavItemType, recordId: String? ->
handleDrawerItemClick(navItemType, recordId)
Unit
}
drawerController?.setupDrawer()
return personalIdManager.isloggedIn();
}

protected open fun shouldShowDrawer(): Boolean {
return false;
}

private fun setupDrawerController() {
val rootView = findViewById<View>(android.R.id.content)
val drawerRefs = DrawerViewRefs(rootView)
drawerController = BaseDrawerController(
this,
drawerRefs
) { navItemType: NavItemType, recordId: String? ->
handleDrawerItemClick(navItemType, recordId)
}
drawerController!!.setupDrawer()
}

protected open fun handleDrawerItemClick(itemType: NavItemType, recordId: String?) {
protected open fun handleDrawerItemClick(itemType: NavItemType, recordId: String?) {
when (itemType) {
NavItemType.OPPORTUNITIES -> {}
NavItemType.COMMCARE_APPS -> {}
Expand Down
Loading