Skip to content
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

Task/sdk 1556/replace multi layouts with dimens #734

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

Anush-Shand
Copy link
Contributor

@Anush-Shand Anush-Shand commented Jan 20, 2025

Details here
https://wizrocket.atlassian.net/browse/SDK-1556

It will be simpler to review this PR commitwise

Summary by CodeRabbit

  • Refactor

    • Removed multiple layout files across different Android version-specific directories
    • Updated layout files with more flexible dimension references
    • Simplified layout alignment attributes for better internationalization support
  • Style

    • Updated padding and margin values using dimension resources
    • Replaced hardcoded values with resource references
    • Improved layout consistency across different Android versions
  • Chores

    • Added new dimension resources in dimens.xml files
    • Removed deprecated or redundant layout files
    • Standardized layout configuration across various Android API levels

Copy link

coderabbitai bot commented Jan 20, 2025

Walkthrough

This pull request involves a comprehensive refactoring of layout resources in the CleverTap push templates library. The changes include removing several layout files across different Android version-specific directories (v19, v21, v22, v23, v31), updating existing layouts with more flexible dimension references, and introducing new dimension resources. The modifications aim to improve layout consistency, support right-to-left layouts, and enhance resource management through centralized dimension definitions.

Changes

File Path Change Summary
layout-*/content_view_small_*.xml Removed multiple layout files for small message views across different Android versions
layout-*/cv_small_*.xml Removed various small template layout files
layout-*/metadata.xml Removed metadata layout files
layout-v31/* Removed carousel, CTA, and product display template layouts
layout/content_view_small_multi_line_msg.xml Updated padding, margin, and alignment attributes
layout/metadata.xml Changed subtitle max width to use dimension resource
layout/five_cta_*.xml Updated padding to use dimension resource
values/dimens.xml Added new dimension resources: metadata_subtitle_max_width, five_cta_padding, product_display_margin_top
values-v23/dimens.xml Added metadata_subtitle_max_width dimension
values-v31/dimens.xml Added product_display_margin_top and five_cta_padding dimensions

Poem

🐰 Layouts hop and dance with glee,
Dimensions now set, clean and free!
Old files vanish like morning dew,
Resources refactored, crisp and new,
A rabbit's code, both smart and light! 🌟


🪧 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. (Beta)
  • @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.

@Anush-Shand Anush-Shand marked this pull request as ready for review January 21, 2025 06:25
@pranaywarke
Copy link
Member

@coderabbitai review

Copy link

coderabbitai bot commented Jan 23, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 1

🔭 Outside diff range comments (1)
clevertap-pushtemplates/src/main/res/layout/cv_small_zero_bezel.xml (1)

Critical: Layout removal will break existing template implementation

The layout file cv_small_zero_bezel.xml is actively used by ZeroBezelMixedSmallContentView.kt which is not being removed or modified. Removing this layout file without proper migration will cause runtime crashes when the zero bezel template is used.

  • clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/content/ZeroBezelMixedSmallContentView.kt needs to be updated to use the new layout system or removed as well.
🔗 Analysis chain

Line range hint 1-62: Verify the impact of removing this layout file.

According to the AI summary, this file is being removed as part of a broader restructuring effort. Please ensure that:

  1. The functionality provided by this layout is properly migrated to the new dimension-based system
  2. All references to this layout in the codebase are updated accordingly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for references to this layout file in the codebase
rg -l "cv_small_zero_bezel" --type xml --type java --type kotlin

Length of output: 180


Script:

#!/bin/bash
# Check the content and status of the Kotlin file
cat clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/content/ZeroBezelMixedSmallContentView.kt

# Check if this file is being modified/removed in the current changes
git status clevertap-pushtemplates/src/main/java/com/clevertap/android/pushtemplates/content/ZeroBezelMixedSmallContentView.kt

Length of output: 1322

🧹 Nitpick comments (7)
clevertap-pushtemplates/src/main/res/layout/content_view_small_single_line_msg.xml (2)

7-10: Consider using paddingStart/paddingEnd for better RTL support.

While the standardization of padding dimensions is good, consider using paddingStart/paddingEnd instead of paddingLeft/paddingRight for better right-to-left (RTL) language support.

-    android:paddingLeft="@dimen/padding_horizontal"
-    android:paddingRight="@dimen/padding_horizontal"
+    android:paddingStart="@dimen/padding_horizontal"
+    android:paddingEnd="@dimen/padding_horizontal"

Line range hint 1-60: Consider optimizing layout hierarchy.

The layout uses nested RelativeLayouts which can impact performance. Consider:

  1. Flattening the hierarchy by moving the inner RelativeLayout's children to the root
  2. Using ConstraintLayout for better performance and easier maintenance

Would you like me to provide an optimized version using ConstraintLayout?

clevertap-pushtemplates/src/main/res/layout/content_view_small_multi_line_msg.xml (2)

Line range hint 27-34: Consider enhancing text appearance handling.

While the RTL support and margin changes look good, consider extracting text-related attributes (maxLines, ellipsize) into a style to improve maintainability.

-            android:maxLines="1"
-            android:ellipsize="end"
-            android:textAppearance="@style/PushTitle"
+            android:textAppearance="@style/PushTitle.SingleLine"

Then define in styles.xml:

<style name="PushTitle.SingleLine">
    <item name="android:maxLines">1</item>
    <item name="android:ellipsize">end</item>
</style>

Line range hint 1-58: Well-structured layout with good RTL support.

The layout changes effectively support the PR's goal of consolidating layouts and improving RTL support. The consistent use of dimension resources and proper RTL attributes makes the layout more maintainable and globally applicable.

Consider creating a comprehensive design system document that outlines:

  • The dimension hierarchy (@dimen/padding_* values)
  • Text appearance styles and their use cases
  • Layout patterns for push notifications
    This will help maintain consistency as the template system grows.
clevertap-pushtemplates/src/main/res/values/dimens.xml (1)

24-24: LGTM! Consider adding documentation for the new dimensions.

The addition of these dimension resources aligns well with the goal of centralizing layout dimensions. This will make future maintenance easier.

Consider adding comments to document the purpose and usage of these new dimensions:

+    <!-- Maximum width for subtitle text in metadata layout -->
     <dimen name="metadata_subtitle_max_width">80dp</dimen>

+    <!-- Padding for five CTA layout elements -->
     <dimen name="five_cta_padding">6dp</dimen>

+    <!-- Top margin for product display carousel layout -->
     <dimen name="product_display_margin_top">8dp</dimen>

Also applies to: 34-34, 43-43

clevertap-pushtemplates/src/main/res/layout/five_cta_collapsed.xml (1)

6-6: LGTM! Consider enhancing RTL support.

The change to use a dimension resource improves maintainability.

Consider adding start/end padding attributes for better RTL support:

-    android:padding="@dimen/five_cta_padding"
+    android:paddingStart="@dimen/five_cta_padding"
+    android:paddingEnd="@dimen/five_cta_padding"
+    android:paddingTop="@dimen/five_cta_padding"
+    android:paddingBottom="@dimen/five_cta_padding"
clevertap-pushtemplates/src/main/res/layout/cv_small_text_only.xml (1)

17-17: Consider using consistent dimension resources for margins.

While the change to use padding_micro is good, consider creating specific margin dimensions for better semantic meaning.

+    <!-- In dimens.xml -->
+    <dimen name="content_margin_end">3dp</dimen>
+    <dimen name="title_margin_top">3dp</dimen>

-    android:layout_marginEnd="@dimen/padding_micro"
+    android:layout_marginEnd="@dimen/content_margin_end"

-    android:layout_marginTop="@dimen/padding_micro"
+    android:layout_marginTop="@dimen/title_margin_top"

Also applies to: 42-42

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3aa7fc3 and 4322de6.

📒 Files selected for processing (38)
  • clevertap-pushtemplates/src/main/res/layout-v19/content_view_small_multi_line_msg.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v19/content_view_small_single_line_msg.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v19/cv_small_text_only.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v19/cv_small_zero_bezel.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v19/metadata.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v21/content_view_small_multi_line_msg.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v21/content_view_small_single_line_msg.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v21/cv_small_text_only.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v21/cv_small_zero_bezel.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v21/metadata.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v22/content_view_small_multi_line_msg.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v22/content_view_small_single_line_msg.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v22/cv_small_text_only.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v22/cv_small_zero_bezel.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v22/metadata.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v23/content_view_small_multi_line_msg.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v23/content_view_small_single_line_msg.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v23/cv_small_text_only.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v23/cv_small_zero_bezel.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v23/metadata.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v31/auto_carousel.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v31/five_cta_collapsed.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v31/five_cta_expanded.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v31/image_only_big.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v31/manual_carousel.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout-v31/product_display_template.xml (0 hunks)
  • clevertap-pushtemplates/src/main/res/layout/content_view_small_multi_line_msg.xml (2 hunks)
  • clevertap-pushtemplates/src/main/res/layout/content_view_small_single_line_msg.xml (3 hunks)
  • clevertap-pushtemplates/src/main/res/layout/cv_small_text_only.xml (3 hunks)
  • clevertap-pushtemplates/src/main/res/layout/cv_small_zero_bezel.xml (2 hunks)
  • clevertap-pushtemplates/src/main/res/layout/five_cta_collapsed.xml (1 hunks)
  • clevertap-pushtemplates/src/main/res/layout/five_cta_expanded.xml (1 hunks)
  • clevertap-pushtemplates/src/main/res/layout/manual_carousel.xml (2 hunks)
  • clevertap-pushtemplates/src/main/res/layout/metadata.xml (1 hunks)
  • clevertap-pushtemplates/src/main/res/layout/product_display_template.xml (1 hunks)
  • clevertap-pushtemplates/src/main/res/values-v23/dimens.xml (1 hunks)
  • clevertap-pushtemplates/src/main/res/values-v31/dimens.xml (1 hunks)
  • clevertap-pushtemplates/src/main/res/values/dimens.xml (3 hunks)
💤 Files with no reviewable changes (26)
  • clevertap-pushtemplates/src/main/res/layout-v31/auto_carousel.xml
  • clevertap-pushtemplates/src/main/res/layout-v31/five_cta_collapsed.xml
  • clevertap-pushtemplates/src/main/res/layout-v31/five_cta_expanded.xml
  • clevertap-pushtemplates/src/main/res/layout-v21/metadata.xml
  • clevertap-pushtemplates/src/main/res/layout-v31/manual_carousel.xml
  • clevertap-pushtemplates/src/main/res/layout-v23/cv_small_text_only.xml
  • clevertap-pushtemplates/src/main/res/layout-v23/content_view_small_single_line_msg.xml
  • clevertap-pushtemplates/src/main/res/layout-v22/cv_small_text_only.xml
  • clevertap-pushtemplates/src/main/res/layout-v21/content_view_small_single_line_msg.xml
  • clevertap-pushtemplates/src/main/res/layout-v23/metadata.xml
  • clevertap-pushtemplates/src/main/res/layout-v19/content_view_small_multi_line_msg.xml
  • clevertap-pushtemplates/src/main/res/layout-v22/content_view_small_single_line_msg.xml
  • clevertap-pushtemplates/src/main/res/layout-v22/metadata.xml
  • clevertap-pushtemplates/src/main/res/layout-v23/content_view_small_multi_line_msg.xml
  • clevertap-pushtemplates/src/main/res/layout-v22/content_view_small_multi_line_msg.xml
  • clevertap-pushtemplates/src/main/res/layout-v21/content_view_small_multi_line_msg.xml
  • clevertap-pushtemplates/src/main/res/layout-v22/cv_small_zero_bezel.xml
  • clevertap-pushtemplates/src/main/res/layout-v21/cv_small_zero_bezel.xml
  • clevertap-pushtemplates/src/main/res/layout-v21/cv_small_text_only.xml
  • clevertap-pushtemplates/src/main/res/layout-v19/content_view_small_single_line_msg.xml
  • clevertap-pushtemplates/src/main/res/layout-v19/metadata.xml
  • clevertap-pushtemplates/src/main/res/layout-v31/product_display_template.xml
  • clevertap-pushtemplates/src/main/res/layout-v19/cv_small_zero_bezel.xml
  • clevertap-pushtemplates/src/main/res/layout-v31/image_only_big.xml
  • clevertap-pushtemplates/src/main/res/layout-v23/cv_small_zero_bezel.xml
  • clevertap-pushtemplates/src/main/res/layout-v19/cv_small_text_only.xml
✅ Files skipped from review due to trivial changes (4)
  • clevertap-pushtemplates/src/main/res/layout/five_cta_expanded.xml
  • clevertap-pushtemplates/src/main/res/values-v23/dimens.xml
  • clevertap-pushtemplates/src/main/res/values-v31/dimens.xml
  • clevertap-pushtemplates/src/main/res/layout/manual_carousel.xml
🔇 Additional comments (8)
clevertap-pushtemplates/src/main/res/layout/cv_small_zero_bezel.xml (2)

28-29: Consider standardizing dimension resource usage.

The changes replace various padding/margin values with @dimen/padding_micro. While this simplifies the dimension system, consider whether using the same dimension for different spacing contexts (vertical padding vs top margin) is the intended design.

Also applies to: 41-41


Line range hint 20-23: LGTM: Proper RTL support implementation.

The layout correctly implements RTL support by:

  1. Using both paddingLeft/paddingRight with their corresponding paddingStart/paddingEnd
  2. Using layout_alignStart instead of layout_alignLeft for text alignment

Also applies to: 37-38, 51-52

clevertap-pushtemplates/src/main/res/layout/content_view_small_single_line_msg.xml (1)

29-29: LGTM! Good use of standard dimensions.

The margin changes align well with the dimension standardization effort, and the existing RTL support is maintained.

clevertap-pushtemplates/src/main/res/layout/content_view_small_multi_line_msg.xml (2)

7-10: LGTM! Padding values follow Material Design guidelines.

The standardization of padding values using separate dimensions for horizontal and vertical padding improves visual hierarchy and maintains consistency.


Line range hint 49-56: Verify image scaling behavior.

While the RTL support is properly implemented, the centerCrop scale type might cause image distortion for certain aspect ratios. Consider if fitCenter would be more appropriate for your use case, or add content description for accessibility.

✅ Verification successful

centerCrop is the correct choice for notification icons

The centerCrop scale type is consistently used across all similar notification layouts in the codebase to ensure square icons maintain a clean, consistent appearance without empty spaces. Using fitCenter would create visual inconsistencies in the notification UI.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any image resources specifically designed for this layout
fd -e png -e jpg -e webp . clevertap-pushtemplates/src/main/res/drawable* -x file {}

Length of output: 375


Script:

#!/bin/bash
# Check the complete layout file and similar layouts
echo "=== Current layout file ==="
cat clevertap-pushtemplates/src/main/res/layout/content_view_small_multi_line_msg.xml

echo -e "\n=== Similar layout files ==="
rg -l "large_icon" --type xml

echo -e "\n=== Other ImageViews with scaleType ==="
rg "android:scaleType" --type xml -B 1 -A 1

Length of output: 23369

clevertap-pushtemplates/src/main/res/layout/cv_small_text_only.xml (1)

8-10: LGTM! Consistent use of padding_micro dimension.

The standardization of padding values improves consistency.

clevertap-pushtemplates/src/main/res/layout/metadata.xml (1)

41-41: Verify the impact of reduced subtitle width.

The maxWidth has been reduced from 120dp to 80dp, which could affect text truncation.

✅ Verification successful

UI adjustment is safe to proceed with

The reduced maxWidth (80dp) is safe as Android's TextView will handle text truncation automatically. The subtitle text is properly processed for HTML content and uses the platform's native overflow handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for subtitle text length usage in the codebase
rg -l "subtitle" --type java | xargs rg "setText.*subtitle" -B 2 -A 2

Length of output: 2023


Script:

#!/bin/bash
# Search for pt_subtitle initialization and length checks
rg "pt_subtitle" --type java -B 2 -A 2

# Search for UI tests related to subtitle
fd -e java -e kt | grep -i "test" | xargs rg "subtitle" -B 2 -A 2

Length of output: 5154

clevertap-pushtemplates/src/main/res/layout/product_display_template.xml (1)

17-17: LGTM! Good use of dimension resource.

The change improves maintainability while preserving the original spacing.

Comment on lines +51 to +57
<ImageView
android:id="@+id/large_icon"
android:layout_width="@dimen/large_icon"
android:layout_height="@dimen/large_icon"
android:layout_marginStart="@dimen/metadata_title_margin_horizontal"
android:layout_alignParentEnd="true"
android:scaleType="centerCrop"/>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add content description for accessibility.

The ImageView is missing a content description, which is important for accessibility. Consider adding android:contentDescription or android:importantForAccessibility="no" if the image is decorative.

         <ImageView
             android:id="@+id/large_icon"
             android:layout_width="@dimen/large_icon"
             android:layout_height="@dimen/large_icon"
             android:layout_marginStart="@dimen/metadata_title_margin_horizontal"
             android:layout_alignParentEnd="true"
-            android:scaleType="centerCrop"/>
+            android:scaleType="centerCrop"
+            android:contentDescription="@string/notification_large_icon"/>

Committable suggestion skipped: line range outside the PR's diff.

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.

5 participants