Add Koin dependency and create ViewModel - #1
Open
dees91 wants to merge 6 commits into
Open
Conversation
dees91
commented
Nov 18, 2025
Owner
- Add io.insert-koin:koin-android 4.1.1 and koin-androidx-compose dependencies
- Create GetGreetingUseCase as an example domain use case
- Create MainViewModel with GetGreetingUseCase as constructor dependency
- Create Koin module (AppModule) with definitions for use case and view model
- Set up KoinIssueApplication to initialize Koin with androidContext and androidLogger
- Update MainActivity to inject MainViewModel using koinViewModel() composable
- Add basic UI interaction with button to trigger greeting update via ViewModel
- Register KoinIssueApplication in AndroidManifest.xml
- Add io.insert-koin:koin-android 4.1.1 and koin-androidx-compose dependencies - Create GetGreetingUseCase as an example domain use case - Create MainViewModel with GetGreetingUseCase as constructor dependency - Create Koin module (AppModule) with definitions for use case and view model - Set up KoinIssueApplication to initialize Koin with androidContext and androidLogger - Update MainActivity to inject MainViewModel using koinViewModel() composable - Add basic UI interaction with button to trigger greeting update via ViewModel - Register KoinIssueApplication in AndroidManifest.xml
- Replace XML layout with ComposeView in onCreateView - Create WelcomeContent composable with different naming from MainActivity's MainScreen - Use koinViewModel() for ViewModel injection in composable - Add interactive UI with text display and button - Button triggers updateGreeting with "Fragment User" parameter - Use larger font size (24.sp) for differentiation
- Modify GetGreetingUseCase to maintain shared call counter - Add getCallCount() method to expose counter state - Update MainViewModel to track and display shared call count - Create SecondViewModel with same GetGreetingUseCase dependency - Create SecondFragment with DisplayContent composable - Update BlankFragment's WelcomeContent to show shared counter - Add periodic refresh (1s) in both fragments to observe counter changes - Modify activity_main.xml to show both fragments side by side - Update MainActivity to load both fragments Both fragments now display the same shared call count, proving they use the same singleton instance of GetGreetingUseCase. When either fragment calls the use case, the counter increments and both fragments see the update.
…hared UseCase - Create ThirdViewModel with GetGreetingUseCase dependency - Create ThirdFragment with AnotherContent composable - Displays "Fragment 3 (From Second Activity)" header - Shows greeting text and shared call count - Periodically refreshes counter every 1 second - Button labeled "Call UseCase from Second Activity" - Create SecondActivity implementing ContainerScope and AndroidScopeComponent - Uses retainedScope similar to MainActivity - Hosts ThirdFragment in activity_second.xml layout - Update MainActivity to add "Open Second Activity" button - Button launches SecondActivity via Intent - Register SecondActivity in AndroidManifest.xml - Add ThirdViewModel to Koin AppModule in ContainerScope All three fragments (across two activities) now share the same singleton GetGreetingUseCase instance. The shared call counter increments across all fragments regardless of which activity they belong to, proving the singleton scope works correctly across activities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.