Skip to content

Add Koin dependency and create ViewModel - #1

Open
dees91 wants to merge 6 commits into
mainfrom
claude/add-koin-viewmodel-015nd5nvjENNL9MJzR8TAGrn
Open

Add Koin dependency and create ViewModel#1
dees91 wants to merge 6 commits into
mainfrom
claude/add-koin-viewmodel-015nd5nvjENNL9MJzR8TAGrn

Conversation

@dees91

@dees91 dees91 commented Nov 18, 2025

Copy link
Copy Markdown
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

claude and others added 6 commits November 18, 2025 16:00
- 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.
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.

2 participants