discord-jadx/app/src/main/java/androidx/fragment/app/FragmentLayoutInflaterFacto...

108 lines
5.4 KiB
Java

package androidx.fragment.app;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.R;
import c.d.b.a.a;
public class FragmentLayoutInflaterFactory implements LayoutInflater.Factory2 {
private static final String TAG = "FragmentManager";
private final FragmentManager mFragmentManager;
public FragmentLayoutInflaterFactory(FragmentManager fragmentManager) {
this.mFragmentManager = fragmentManager;
}
@Override // android.view.LayoutInflater.Factory2
@Nullable
public View onCreateView(@Nullable View view, @NonNull String str, @NonNull Context context, @NonNull AttributeSet attributeSet) {
FragmentStateManager fragmentStateManager;
if (FragmentContainerView.class.getName().equals(str)) {
return new FragmentContainerView(context, attributeSet, this.mFragmentManager);
}
Fragment fragment = null;
if (!"fragment".equals(str)) {
return null;
}
String attributeValue = attributeSet.getAttributeValue(null, "class");
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.Fragment);
if (attributeValue == null) {
attributeValue = obtainStyledAttributes.getString(R.styleable.Fragment_android_name);
}
int resourceId = obtainStyledAttributes.getResourceId(R.styleable.Fragment_android_id, -1);
String string = obtainStyledAttributes.getString(R.styleable.Fragment_android_tag);
obtainStyledAttributes.recycle();
if (attributeValue == null || !FragmentFactory.isFragmentClass(context.getClassLoader(), attributeValue)) {
return null;
}
int id2 = view != null ? view.getId() : 0;
if (id2 == -1 && resourceId == -1 && string == null) {
throw new IllegalArgumentException(attributeSet.getPositionDescription() + ": Must specify unique android:id, android:tag, or have a parent with an id for " + attributeValue);
}
if (resourceId != -1) {
fragment = this.mFragmentManager.findFragmentById(resourceId);
}
if (fragment == null && string != null) {
fragment = this.mFragmentManager.findFragmentByTag(string);
}
if (fragment == null && id2 != -1) {
fragment = this.mFragmentManager.findFragmentById(id2);
}
if (fragment == null) {
fragment = this.mFragmentManager.getFragmentFactory().instantiate(context.getClassLoader(), attributeValue);
fragment.mFromLayout = true;
fragment.mFragmentId = resourceId != 0 ? resourceId : id2;
fragment.mContainerId = id2;
fragment.mTag = string;
fragment.mInLayout = true;
FragmentManager fragmentManager = this.mFragmentManager;
fragment.mFragmentManager = fragmentManager;
fragment.mHost = fragmentManager.getHost();
fragment.onInflate(this.mFragmentManager.getHost().getContext(), attributeSet, fragment.mSavedFragmentState);
fragmentStateManager = this.mFragmentManager.createOrGetFragmentStateManager(fragment);
this.mFragmentManager.addFragment(fragment);
if (FragmentManager.isLoggingEnabled(2)) {
Log.v("FragmentManager", "Fragment " + fragment + " has been inflated via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
}
} else if (!fragment.mInLayout) {
fragment.mInLayout = true;
FragmentManager fragmentManager2 = this.mFragmentManager;
fragment.mFragmentManager = fragmentManager2;
fragment.mHost = fragmentManager2.getHost();
fragment.onInflate(this.mFragmentManager.getHost().getContext(), attributeSet, fragment.mSavedFragmentState);
fragmentStateManager = this.mFragmentManager.createOrGetFragmentStateManager(fragment);
if (FragmentManager.isLoggingEnabled(2)) {
Log.v("FragmentManager", "Retained Fragment " + fragment + " has been re-attached via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
}
} else {
throw new IllegalArgumentException(attributeSet.getPositionDescription() + ": Duplicate id 0x" + Integer.toHexString(resourceId) + ", tag " + string + ", or parent id 0x" + Integer.toHexString(id2) + " with another fragment for " + attributeValue);
}
fragment.mContainer = (ViewGroup) view;
fragmentStateManager.moveToExpectedState();
fragmentStateManager.ensureInflatedView();
View view2 = fragment.mView;
if (view2 != null) {
if (resourceId != 0) {
view2.setId(resourceId);
}
if (fragment.mView.getTag() == null) {
fragment.mView.setTag(string);
}
return fragment.mView;
}
throw new IllegalStateException(a.u("Fragment ", attributeValue, " did not create a view."));
}
@Override // android.view.LayoutInflater.Factory
@Nullable
public View onCreateView(@NonNull String str, @NonNull Context context, @NonNull AttributeSet attributeSet) {
return onCreateView(null, str, context, attributeSet);
}
}