Skip to content

task(SDK-4887) - Adds basic UI for custom code templates #825

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Anush-Shand
Copy link
Contributor

@Anush-Shand Anush-Shand commented Jun 10, 2025

https://wizrocket.atlassian.net/browse/SDK-4887

Summary by CodeRabbit

  • New Features
    • Added support for custom in-app message templates and functions within the app.
    • Introduced new options on the home screen to sync registered templates and retrieve the active template context.
  • Enhancements
    • Improved logging for template and function presentation events to provide more detailed runtime information.

Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

Walkthrough

The changes introduce support for custom in-app message templates in a CleverTap demo application. A new object defines and registers custom templates and functions, which are integrated into the application initialization. The home screen model and view model are updated to expose and handle new commands for syncing templates and retrieving active template contexts.

Changes

File(s) Change Summary
.../MyApplication.kt Added import and registration of CustomInAppTemplates with CleverTap during app initialization.
.../ui/main/CustomInAppTemplates.kt Introduced CustomInAppTemplates object to define/register custom templates and functions, with presenters and logging.
.../ui/main/HomeScreenModel.kt Extended listData map to include "CUSTOM CODE TEMPLATES" with two new entries.
.../ui/main/HomeScreenViewModel.kt Added handling for two new commands: sync registered templates and get active context for a template, with logging.

Sequence Diagram(s)

sequenceDiagram
    participant App as MyApplication
    participant CTAPI as CleverTapAPI
    participant Templates as CustomInAppTemplates

    App->>Templates: registerCustomTemplates()
    App->>CTAPI: registerCustomInAppTemplates(lambda)
    Note right of CTAPI: Custom templates and functions registered
Loading
sequenceDiagram
    participant User
    participant HomeScreen
    participant ViewModel as HomeScreenViewModel
    participant CTAPI as CleverTapAPI

    User->>HomeScreen: Select "Sync Registered Templates"
    HomeScreen->>ViewModel: onChildClick("16-0")
    ViewModel->>CTAPI: syncRegisteredInAppTemplates()

    User->>HomeScreen: Select "Get Active Template for Context"
    HomeScreen->>ViewModel: onChildClick("16-1")
    ViewModel->>CTAPI: getActiveContextForTemplate("template-a")
    ViewModel->>ViewModel: Log active context
Loading
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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
Contributor

@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 (2)
sample/src/main/java/com/clevertap/demo/ui/main/HomeScreenViewModel.kt (1)

761-764: Consider making the template name configurable.

The implementation correctly retrieves and logs the active template context. However, the hardcoded template name "template-a" reduces flexibility.

Consider extracting the template name as a constant or making it configurable:

+private const val DEMO_TEMPLATE_NAME = "template-a"

"16-1" -> {
-    val template = cleverTapAPI?.getActiveContextForTemplate("template-a")
+    val template = cleverTapAPI?.getActiveContextForTemplate(DEMO_TEMPLATE_NAME)
    Log.i(TAG, "Active Template for Context = $template")
}
sample/src/main/java/com/clevertap/demo/ui/main/CustomInAppTemplates.kt (1)

26-26: Clean up commented code.

The commented line should be removed or documented if it's meant to be an example.

-//        context.triggerActionArgument("actionArg", this)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aaf4f79 and dc9b4e5.

📒 Files selected for processing (4)
  • sample/src/main/java/com/clevertap/demo/MyApplication.kt (2 hunks)
  • sample/src/main/java/com/clevertap/demo/ui/main/CustomInAppTemplates.kt (1 hunks)
  • sample/src/main/java/com/clevertap/demo/ui/main/HomeScreenModel.kt (1 hunks)
  • sample/src/main/java/com/clevertap/demo/ui/main/HomeScreenViewModel.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-staticChecks-test-build
🔇 Additional comments (8)
sample/src/main/java/com/clevertap/demo/MyApplication.kt (2)

28-28: LGTM: Clean import addition.

The import for CustomInAppTemplates is correctly placed and follows the existing import organization.


76-76: LGTM: Proper template registration placement.

The custom in-app template registration is correctly placed in the cleverTapPreAppCreated() method, ensuring templates are registered before the SDK is fully initialized. The lambda syntax is clean and idiomatic Kotlin.

sample/src/main/java/com/clevertap/demo/ui/main/HomeScreenModel.kt (1)

114-117: LGTM: Consistent UI data structure addition.

The new "CUSTOM CODE TEMPLATES" section follows the existing pattern and provides clear, descriptive labels for the template management functionality.

sample/src/main/java/com/clevertap/demo/ui/main/HomeScreenViewModel.kt (1)

758-760: LGTM: Clean template sync implementation.

The sync operation is implemented correctly and follows the existing command pattern.

sample/src/main/java/com/clevertap/demo/ui/main/CustomInAppTemplates.kt (4)

11-12: LGTM: Good object structure and constants.

Using an object for stateless template definitions is appropriate, and the TAG constant follows logging conventions.


14-29: LGTM: Excellent template presenter implementation.

The template presenter correctly handles lifecycle events and demonstrates proper usage of the context API:

  • Proper logging for debugging
  • Correct state management with setPresented() and setDismissed()
  • Good demonstration of argument retrieval with different types
  • Shows nested key access (folder1.var3)

31-38: LGTM: Clean function presenter implementation.

The function presenter is well-implemented using a lambda, demonstrating concise syntax while maintaining proper functionality and logging.


40-86: LGTM: Comprehensive template and function definitions.

Excellent demonstration of the template DSL with:

  • Multiple template types with different argument configurations
  • Both visual and non-visual functions
  • Various argument types (boolean, string, double, action, map, file)
  • Nested argument structures
  • Consistent naming and default values

This provides a good foundation for understanding the custom template capabilities.

Copy link

Code Coverage Debug

Metric (instruction) Coverage Threshold Δ Coverage Status
Overall 50.85% 75.0% +0.04%
Changed Files 0.0% 75.0% 0.0%
Report Coverage (O/Ch) Threshold (O/Ch) Δ Coverage (O/Ch) Status (O/Ch)
clevertap-core 53.16% / 0.0% 75.0% / 75.0% +0.04% / 0.0% ❌/✅
clevertap-hms 70.96% / 0.0% 75.0% / 75.0% 0.0% / 0.0% ❌/✅
clevertap-pushtemplates 23.74% / 0.0% 75.0% / 75.0% 0.0% / 0.0% ❌/✅

@vasct
Copy link
Contributor

vasct commented Jun 10, 2025

This is what Nikola has done in the iOS starter project:
image
Shouldn't we have something similar in the sample ?

Comment on lines +761 to +764
"16-1" -> {
val template =cleverTapAPI?.getActiveContextForTemplate("template-a")
Log.i(TAG, "Active Template for Context = $template")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not print all registered templates?

Copy link
Collaborator

@CTLalit CTLalit left a comment

Choose a reason for hiding this comment

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

approved with logging comment.

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.

3 participants