Skip to content

Commit

Permalink
Internal refactoring
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 360256525
  • Loading branch information
java-team-github-bot authored and Dagger Team committed Mar 1, 2021
1 parent f39bc87 commit 2192014
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.activity.ComponentActivity;
Expand Down Expand Up @@ -82,23 +84,26 @@ protected void onCleared() {
private final Object componentLock = new Object();

ActivityRetainedComponentManager(ComponentActivity activity) {
this.viewModelProvider =
new ViewModelProvider(
activity,
new ViewModelProvider.Factory() {
@NonNull
@Override
@SuppressWarnings("unchecked")
public <T extends ViewModel> T create(@NonNull Class<T> aClass) {
ActivityRetainedComponent component =
EntryPoints.get(
activity.getApplication(),
ActivityRetainedComponentBuilderEntryPoint.class)
.retainedComponentBuilder()
.build();
return (T) new ActivityRetainedComponentViewModel(component);
}
});
this.viewModelProvider = getViewModelProvider(activity, activity.getApplication());
}

private ViewModelProvider getViewModelProvider(
ViewModelStoreOwner owner, Context applicationContext) {
return new ViewModelProvider(
owner,
new ViewModelProvider.Factory() {
@NonNull
@Override
@SuppressWarnings("unchecked")
public <T extends ViewModel> T create(@NonNull Class<T> aClass) {
ActivityRetainedComponent component =
EntryPoints.get(
applicationContext, ActivityRetainedComponentBuilderEntryPoint.class)
.retainedComponentBuilder()
.build();
return (T) new ActivityRetainedComponentViewModel(component);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void testProdComponents() {
.contains(
JOINER.join(
" public abstract static class SingletonC implements"
+ " HiltWrapper_ActivityRetainedComponentManager"
+ "_ActivityRetainedComponentBuilderEntryPoint,",
+ " HiltWrapper_ActivityRetainedComponentManager"
+ "_ActivityRetainedComponentBuilderEntryPoint,",
" ServiceComponentManager.ServiceComponentBuilderEntryPoint,",
" SingletonComponent,",
" GeneratedComponent,",
Expand Down Expand Up @@ -103,8 +103,8 @@ public void testTestComponents() {
.contains(
JOINER.join(
" public abstract static class SingletonC implements"
+ " HiltWrapper_ActivityRetainedComponentManager"
+ "_ActivityRetainedComponentBuilderEntryPoint,",
+ " HiltWrapper_ActivityRetainedComponentManager"
+ "_ActivityRetainedComponentBuilderEntryPoint,",
" ServiceComponentManager.ServiceComponentBuilderEntryPoint,",
" SingletonComponent,",
" TestSingletonComponent,",
Expand Down

0 comments on commit 2192014

Please sign in to comment.