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

Inject AnalyticsHelper with Hilt #118

Merged

Conversation

ankur141295
Copy link
Contributor

This pull request contains the following changes:

  • Injecting AnalyticsHelper with Hilt

This change addresses #74

Please review the changes and let me know if you have any questions.

Comment on lines +15 to +16
@Inject
lateinit var analyticsHelper: AnalyticsHelper
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe could be important inject AnalyticsHelper using Hilt DSL for Compose screens/components instead inject directly on activity.

I think this because on your approuch you will need pass the analytics value as a cascate to anothers components and screens and one of the DI ideia is: Not depend from another components to receive the value, you could recover the value from anywhere, injecting the value.

My suggestion could be strange here because the AnalyticsHelper wasn't used on ViewModels, and may the best approach is migrate AnalyticsHelper to ViewModels instead.

What do you think about it?

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 considered this approach as well, and that's why I initially discussed it with @waseefakhtar here: #74 (comment).

Given the project's current structure, this was my initial approach to refactoring. I remain open to suggestions, and if this approach proves unsuitable, I can always revert to the second option mentioned in the comment link.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I didn't know about the approach dicussed, thanks for showing to me @ankur141295!

Copy link
Owner

Choose a reason for hiding this comment

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

I agree with the approach of migrating AnalyticsHelper to ViewModels instead! That'd make the code a ton simpler and easy to test.

@ankur141295 my bad regarding the discussion. I might've missed your point there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@waseefakhtar No worries, I'll make the code changes again and inject AnalyticsHelper into ViewModel instead.

@ankur141295 ankur141295 force-pushed the inject_analytics_helper_v1 branch from 17fccb9 to 552bcc8 Compare January 13, 2024 08:55
@ankur141295 ankur141295 reopened this Jan 20, 2024
@ankur141295
Copy link
Contributor Author

@waseefakhtar

I've redone the code changes, injecting AnalyticsHelper directly into ViewModels wherever possible to call logging functions. For composables like BottomAppBar and FAB that lack ViewModels, the AnalyticsHelper dependency is still provided as a parameter.

Kindly review the code changes and let me know if any further changes are required.

Copy link
Owner

@waseefakhtar waseefakhtar left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me! 🚀 Thank you for your contribution @ankur141295! :)

@waseefakhtar waseefakhtar merged commit 21745db into waseefakhtar:main Jan 25, 2024
2 checks passed
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