- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
92 lines
4.1 KiB
Java
92 lines
4.1 KiB
Java
package androidx.lifecycle;
|
|
|
|
import android.os.Bundle;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
import androidx.lifecycle.viewmodel.CreationExtras;
|
|
import androidx.savedstate.SavedStateRegistry;
|
|
import androidx.savedstate.SavedStateRegistryOwner;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class AbstractSavedStateViewModelFactory extends ViewModelProvider.OnRequeryFactory implements ViewModelProvider.Factory {
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final String TAG_SAVED_STATE_HANDLE_CONTROLLER = "androidx.lifecycle.savedstate.vm.tag";
|
|
private Bundle defaultArgs;
|
|
private Lifecycle lifecycle;
|
|
private SavedStateRegistry savedStateRegistry;
|
|
|
|
public abstract <T extends ViewModel> T create(String str, Class<T> cls, SavedStateHandle savedStateHandle);
|
|
|
|
public AbstractSavedStateViewModelFactory() {
|
|
}
|
|
|
|
public AbstractSavedStateViewModelFactory(SavedStateRegistryOwner owner, Bundle bundle) {
|
|
Intrinsics.checkNotNullParameter(owner, "owner");
|
|
this.savedStateRegistry = owner.getSavedStateRegistry();
|
|
this.lifecycle = owner.getLifecycle();
|
|
this.defaultArgs = bundle;
|
|
}
|
|
|
|
@Override // androidx.lifecycle.ViewModelProvider.Factory
|
|
public <T extends ViewModel> T create(Class<T> modelClass, CreationExtras extras) {
|
|
Intrinsics.checkNotNullParameter(modelClass, "modelClass");
|
|
Intrinsics.checkNotNullParameter(extras, "extras");
|
|
String str = (String) extras.get(ViewModelProvider.NewInstanceFactory.VIEW_MODEL_KEY);
|
|
if (str == null) {
|
|
throw new IllegalStateException("VIEW_MODEL_KEY must always be provided by ViewModelProvider");
|
|
}
|
|
if (this.savedStateRegistry != null) {
|
|
return (T) create(str, modelClass);
|
|
}
|
|
return (T) create(str, modelClass, SavedStateHandleSupport.createSavedStateHandle(extras));
|
|
}
|
|
|
|
private final <T extends ViewModel> T create(String str, Class<T> cls) {
|
|
SavedStateRegistry savedStateRegistry = this.savedStateRegistry;
|
|
Intrinsics.checkNotNull(savedStateRegistry);
|
|
Lifecycle lifecycle = this.lifecycle;
|
|
Intrinsics.checkNotNull(lifecycle);
|
|
SavedStateHandleController create = LegacySavedStateHandleController.create(savedStateRegistry, lifecycle, str, this.defaultArgs);
|
|
T t = (T) create(str, cls, create.getHandle());
|
|
t.setTagIfAbsent("androidx.lifecycle.savedstate.vm.tag", create);
|
|
return t;
|
|
}
|
|
|
|
@Override // androidx.lifecycle.ViewModelProvider.Factory
|
|
public <T extends ViewModel> T create(Class<T> modelClass) {
|
|
Intrinsics.checkNotNullParameter(modelClass, "modelClass");
|
|
String canonicalName = modelClass.getCanonicalName();
|
|
if (canonicalName == null) {
|
|
throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels");
|
|
}
|
|
if (this.lifecycle == null) {
|
|
throw new UnsupportedOperationException("AbstractSavedStateViewModelFactory constructed with empty constructor supports only calls to create(modelClass: Class<T>, extras: CreationExtras).");
|
|
}
|
|
return (T) create(canonicalName, modelClass);
|
|
}
|
|
|
|
@Override // androidx.lifecycle.ViewModelProvider.OnRequeryFactory
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
|
|
public void onRequery(ViewModel viewModel) {
|
|
Intrinsics.checkNotNullParameter(viewModel, "viewModel");
|
|
SavedStateRegistry savedStateRegistry = this.savedStateRegistry;
|
|
if (savedStateRegistry != null) {
|
|
Intrinsics.checkNotNull(savedStateRegistry);
|
|
Lifecycle lifecycle = this.lifecycle;
|
|
Intrinsics.checkNotNull(lifecycle);
|
|
LegacySavedStateHandleController.attachHandleIfNeeded(viewModel, savedStateRegistry, lifecycle);
|
|
}
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
}
|
|
}
|