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

[Identity] Dagger - Move injection to IdentityActivity #5249

Merged
merged 4 commits into from Jul 6, 2022

Conversation

ccen-stripe
Copy link
Collaborator

Summary

Move the injection from IdentityViewModel to IdentityActivity to preserve state in IdentityViewModel

This is a change required to make IdentityViewModelFactory preserving state after process kill by implementing AbstractSavedStateViewModelFactory, the reason is as follows:

  • IdentityActivity needs to set a IdentityFragmentFactory in order to create different Fragments. This factory is created by dagger graph, and needs to be set in IdentityActivity before super.onCreate()

  • However in order to make the IdentityViewModel to preserve state with AbstractSavedStateViewModelFactory, it could only be initialized after super.onCreate() - note this is not a requirement if it's just a regular ViewModelFactory

  • Before the change, the IdentityViewModel(and IdentityFragmentFactory) are all created before super.onCreate() call

  • After the change, IdentityFragmentFactory is created before the onCreate() call, the dependencies required IdentityViewModel is also created before the onCreate() call, they are all passed to the Factory. The actual creation of IdentityViewModel will be after onCreate() call.

Motivation

Preserve IdentityViewModelState

Testing

  • Added tests
  • Modified tests
  • Manually verified

Screenshots

Before After
before screenshot after screenshot

Changelog

@ccen-stripe ccen-stripe marked this pull request as ready for review July 5, 2022 20:43
@ccen-stripe ccen-stripe merged commit 55a9da7 into master Jul 6, 2022
@ccen-stripe ccen-stripe deleted the ccen/recoverWhenDestroyed branch July 6, 2022 19:55
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.

None yet

2 participants