Skip to content

Commit

Permalink
Rename some usages of ViewModelInject to HiltViewModel
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 352108269
  • Loading branch information
Chang-Eric authored and Dagger Team committed Jan 16, 2021
1 parent 896289a commit 8c45caf
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ interface ViewModelModule {
Map<String, ViewModel> hiltViewModelMap();
}

private final Set<String> viewModelInjectKeys;
private final Set<String> hiltViewModelKeys;
private final ViewModelProvider.Factory delegateFactory;
private final AbstractSavedStateViewModelFactory viewModelInjectFactory;
private final AbstractSavedStateViewModelFactory hiltViewModelFactory;

public HiltViewModelFactory(
@NonNull SavedStateRegistryOwner owner,
@Nullable Bundle defaultArgs,
@NonNull Set<String> viewModelInjectKeys,
@NonNull Set<String> hiltViewModelKeys,
@NonNull ViewModelProvider.Factory delegateFactory,
@NonNull ViewModelComponentBuilder viewModelComponentBuilder) {
this.viewModelInjectKeys = viewModelInjectKeys;
this.hiltViewModelKeys = hiltViewModelKeys;
this.delegateFactory = delegateFactory;
this.viewModelInjectFactory =
this.hiltViewModelFactory =
new AbstractSavedStateViewModelFactory(owner, defaultArgs) {
@NonNull
@Override
Expand All @@ -89,10 +89,10 @@ protected <T extends ViewModel> T create(
.get(modelClass.getName());
if (provider == null) {
throw new IllegalStateException(
"Expected the @ViewModelInject-annotated class '"
"Expected the @HiltViewModel-annotated class '"
+ modelClass.getName()
+ "' to be available in the multi-binding of "
+ "@ViewModelInjectMap but none was found.");
+ "@HiltViewModelMap but none was found.");
}
return (T) provider.get();
}
Expand All @@ -102,8 +102,8 @@ protected <T extends ViewModel> T create(
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
if (viewModelInjectKeys.contains(modelClass.getName())) {
return viewModelInjectFactory.create(modelClass);
if (hiltViewModelKeys.contains(modelClass.getName())) {
return hiltViewModelFactory.create(modelClass);
} else {
return delegateFactory.create(modelClass);
}
Expand Down

0 comments on commit 8c45caf

Please sign in to comment.