-
Notifications
You must be signed in to change notification settings - Fork 78
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
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThe 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
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
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
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
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
📒 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()
andsetDismissed()
- 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.
Code Coverage Debug
|
"16-1" -> { | ||
val template =cleverTapAPI?.getActiveContextForTemplate("template-a") | ||
Log.i(TAG, "Active Template for Context = $template") | ||
} |
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.
why not print all registered templates?
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.
approved with logging comment.
https://wizrocket.atlassian.net/browse/SDK-4887
Summary by CodeRabbit