# 16. Implement Android state management (StateFlow/LiveData)

meta:
  id: native-business-logic-migration-16
  feature: native-business-logic-migration
  priority: P0
  depends_on: [native-business-logic-migration-13]
  tags: [implementation, android, state-management]

objective:
- Implement reactive state management using StateFlow and LiveData

deliverables:
- FeedRepository.kt
- SubscriptionRepository.kt
- FeedViewModel.kt
- SubscriptionViewModel.kt
- State sealed class
- Error handling types

tests:
- Unit: Test repository methods
- Unit: Test ViewModel state transitions
- Unit: Test StateFlow emission
- Integration: Test UI updates

acceptance_criteria:
- Repositories provide StateFlow
- ViewModels manage state properly
- Error states handled
- Loading states implemented
- Lifecycle-aware updates

validation:
- Run `./gradlew test`
- Test with Espresso for UI updates

notes:
- Use StateFlow for new code
- Use LiveData for UI binding
- Follow Repository pattern
