Skip to content

Conversation

@OrangeAndGreen
Copy link
Contributor

@OrangeAndGreen OrangeAndGreen commented Mar 13, 2025

https://dimagi.atlassian.net/browse/CCCT-838

cross-request: dimagi/commcare-core#1455

Product Description

Delivery progress tabs no longer squished vertically when changing between tabs.

Technical Summary

This PR fixes a bug in which part of the UI would sometimes be sized too short (matching a different UI), such that elements were squished. Also while working in this code, I cleaned things up slightly so as not to hold static references to the two fragments (which equated to holding static references to Context objects).

Showing the error:
image

Feature Flag

Connect

Safety Assurance

Safety story

Tested the code out to verify things size correctly now and nothing got broken in my cleanup.
Otherwise this is mostly just about updating the height of a UI element, pretty simple change.

Automated test coverage

No automated tests for Connect yet.

QA Plan

See steps to reproduce in the Jira ticket. The UI should no longer get squished when following the steps.

Labels and Review

  • Do we need to enhance the manual QA test coverage ? If yes, the "QA Note" label is set correctly
  • Does the PR introduce any major changes worth communicating ? If yes, the "Release Note" label is set and a "Release Note" is specified in PR description.
  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

…rences to Context objects.

Updating tab height at bottom of page when changing tabs (to fix a vertical squishing bug).
@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2025

📝 Walkthrough

Walkthrough

The changes update the ConnectDeliveryProgressFragment to improve its handling of user interactions and fragment management. The onCreateView method now enforces type safety using the @NonNull annotation on the LayoutInflater parameter. A new onOptionsItemSelected method has been added to process menu selections, notably triggering a data refresh when a sync action is chosen. In the onPageSelected method, the logic has been modified to adjust the height of the ViewPager2 dynamically based on the measured height of the currently visible fragment’s view. Additionally, the ViewStateAdapter class now manages a dynamic list of fragments instead of relying on static fragment references. This update includes modifications to the createFragment, getItemCount, and refresh methods to support a variable number of fragments and to invoke updateView on specific fragment types as needed.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CP as ConnectDeliveryProgressFragment
    participant VSA as ViewStateAdapter
    participant F as Fragment

    U->>CP: Select sync action (menu item)
    CP->>CP: onOptionsItemSelected(MenuItem)
    CP->>VSA: Call refresh()
    VSA->>F: Iterate over fragment list
    F-->>VSA: updateView() invoked (if applicable)
Loading
sequenceDiagram
    participant CP as ConnectDeliveryProgressFragment
    participant VP as ViewPager2
    participant CF as Current Fragment

    CP->>CP: onPageSelected(pageIndex)
    CP->>CF: Retrieve current fragment view
    CF-->>CP: Return measured view height
    CP->>VP: Adjust height based on measured value
Loading

Suggested labels

QA Note

Suggested reviewers

  • shubham1g5
  • Jignesh-dimagi

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
app/src/org/commcare/fragments/connect/ConnectDeliveryProgressFragment.java (1)

354-359: Improved refresh method with fragment type checking.

The updated approach properly iterates through all fragments and calls the appropriate update method based on the fragment type. This is more maintainable and avoids static references.

Consider using an interface instead of instanceof checks to make this more extensible:

- for (Fragment fragment : fragmentList) {
-     if (fragment instanceof ConnectDeliveryProgressDeliveryFragment) {
-         ((ConnectDeliveryProgressDeliveryFragment) fragment).updateView();
-     } else if (fragment instanceof ConnectResultsSummaryListFragment) {
-         ((ConnectResultsSummaryListFragment) fragment).updateView();
-     }
- }
+ // Define an interface in another file
+ public interface Updatable {
+     void updateView();
+ }
+ 
+ // Then implement it in both fragment classes
+ 
+ // Here, simply call:
+ for (Fragment fragment : fragmentList) {
+     if (fragment instanceof Updatable) {
+         ((Updatable) fragment).updateView();
+     }
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 489b81a and ce1189a.

📒 Files selected for processing (1)
  • app/src/org/commcare/fragments/connect/ConnectDeliveryProgressFragment.java (5 hunks)
🔇 Additional comments (8)
app/src/org/commcare/fragments/connect/ConnectDeliveryProgressFragment.java (8)

6-6: Added the necessary import for MenuItem handling.

This addition supports the new onOptionsItemSelected method that you'll implement later in the class.


70-70: Good use of @nonnull annotation for type safety.

Adding the @NonNull annotation to the LayoutInflater parameter enhances type safety and helps prevent potential null pointer exceptions.


201-209: Added options menu handling for sync action.

This implementation properly handles the sync menu item selection and refreshes data appropriately.


334-334: Removed static references by using a dynamic fragment list.

This change addresses the potential memory leak issue mentioned in the PR by storing fragments in a dynamic list instead of using static references.


338-339: Proper initialization of fragment instances.

The fragments are now instantiated once during adapter creation and stored in the list, which is cleaner than creating them on demand.


345-345: Simplified fragment creation by retrieving from list.

This change makes the code more maintainable by eliminating conditional fragment creation logic.


350-350: Dynamic item count based on fragment list size.

This change makes the adapter more flexible for potential future changes where the number of fragments might vary.


138-143:

Details

❓ Verification inconclusive

Nice fix for the vertically squished tabs issue.

This change dynamically adjusts the ViewPager2 height based on the measured height of the current fragment's view, which should resolve the UI issue described in the PR.

However, this approach assumes the fragment's view has already been measured. Consider adding a check to handle cases where measurement hasn't occurred yet.


🏁 Script executed:

#!/bin/bash
# Check if there are any similar approaches in the codebase
rg -A 5 "getMeasuredHeight" --glob "*.java" | grep -v "ConnectDeliveryProgressFragment.java"

Length of output: 5326


Suggestion: Add a safeguard to ensure the view has been measured before updating the ViewPager2 height

The fix overall looks good and resolves the issue of squished tabs by dynamically adapting to the fragment’s view height. However, as noted, the current implementation assumes that the fragment’s view has already been measured. This can be risky if the view’s measurement returns 0 (or isn’t ready), potentially leading to layout issues.

Recommendations:

  • In app/src/org/commcare/fragments/connect/ConnectDeliveryProgressFragment.java (lines 138–143), consider checking if view.getMeasuredHeight() returns a positive value before applying it to the ViewPager2’s layout parameters. For example, an extra condition like:
    if(view != null && view.getMeasuredHeight() > 0) {
        pager.getLayoutParams().height = view.getMeasuredHeight();
        pager.requestLayout();
    }
  • Alternatively, if there’s a chance the view is not yet measured, you might defer the height update (for example, by using a layout listener) to ensure that the measured height is reliable.

This approach is similar to other parts of the codebase that rely on getMeasuredHeight() (e.g., in EnhancedWrapContentViewPager.java and widgets within QuestionWidget.java), so consider whether a uniform strategy across similar components could further improve consistency.

Comment on lines +138 to +142
View view = viewStateAdapter.createFragment(position).getView();
if(view != null) {
pager.getLayoutParams().height = view.getMeasuredHeight();
pager.requestLayout();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you talk more about the issue here ? As though why does the view get cut off and can't it be corrected from view xml instead by adding margin to the xml view ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm having a hard time figuring out what the underlying issue is here, it seems to me that the FragmentStateAdapter should be handling the size of the fragments. After spending some time and not making much progress I decided to let Github Copilot try to help me! This was the solution it suggested, and when I tried it out it indeed worked.

But I'm open to looking for a better fix, I'd love to understand what's getting confused such that the fragment ends up too short despite having clear layout params. Another odd thing to note is that changing between the tabs seems to work fine at first. The issue only occurs when the user is on the second tab and presses a button (which causes some UI to change), then navigates back to the first tab.

I don't think I'll be able to get to that before the cohort starts on Monday though, so is the current change acceptable for now to fix the user-facing bug? I can create another ticket to revisit this next week and if I'm still struggling then I'll recruit Jignesh for some fresh eyes.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me, we should probably add a check that view.getMeasuredHeight > 0 before height assignment as well to make this code more fail-safe.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would also be good to add a code comment there to denote why we are doing it as it's not entirely obvious by looking at the code.

@OrangeAndGreen
Copy link
Contributor Author

Thanks Shubham, I created a ticket to revisit this next week. Merging the existing fix for now.

@OrangeAndGreen OrangeAndGreen merged commit 7d9276c into connect_qa Mar 14, 2025
2 checks passed
@OrangeAndGreen OrangeAndGreen deleted the dv/delivery_progress_ui_fix branch March 14, 2025 16:52
This was referenced Mar 31, 2025
@coderabbitai coderabbitai bot mentioned this pull request May 8, 2025
4 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jun 16, 2025
4 tasks
@pm-dimagi pm-dimagi mentioned this pull request Jul 17, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants