-
-
Notifications
You must be signed in to change notification settings - Fork 45
Fixes navigtation drawer to only be visible for required Screens #3292
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -180,6 +175,13 @@ && new RootBeer(this).isRooted()) { | |
| } | ||
| } | ||
|
|
||
| private void initPersonaIdManager() { | ||
| if (personalIdManager == null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
@@ -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; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| 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 -> {} | ||
|
|
||
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.
💡 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:
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:
This will guarantee the drawer appears without forcing an activity restart.