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

318 lines
12 KiB
Java

package androidx.fragment.app;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import c.d.b.a.a;
import java.util.ArrayList;
@Deprecated
public class FragmentTabHost extends TabHost implements TabHost.OnTabChangeListener {
private boolean mAttached;
private int mContainerId;
private Context mContext;
private FragmentManager mFragmentManager;
private TabInfo mLastTab;
private TabHost.OnTabChangeListener mOnTabChangeListener;
private FrameLayout mRealTabContent;
private final ArrayList<TabInfo> mTabs = new ArrayList<>();
public static class DummyTabFactory implements TabHost.TabContentFactory {
private final Context mContext;
public DummyTabFactory(Context context) {
this.mContext = context;
}
@Override // android.widget.TabHost.TabContentFactory
public View createTabContent(String str) {
View view = new View(this.mContext);
view.setMinimumWidth(0);
view.setMinimumHeight(0);
return view;
}
}
public static class SavedState extends View.BaseSavedState {
public static final Parcelable.Creator<SavedState> CREATOR = new AnonymousClass1();
public String curTab;
/* renamed from: androidx.fragment.app.FragmentTabHost$SavedState$1 reason: invalid class name */
public class AnonymousClass1 implements Parcelable.Creator<SavedState> {
@Override // android.os.Parcelable.Creator
public SavedState createFromParcel(Parcel parcel) {
return new SavedState(parcel);
}
@Override // android.os.Parcelable.Creator
public SavedState[] newArray(int i) {
return new SavedState[i];
}
}
public SavedState(Parcel parcel) {
super(parcel);
this.curTab = parcel.readString();
}
public SavedState(Parcelable parcelable) {
super(parcelable);
}
@Override // java.lang.Object
@NonNull
public String toString() {
StringBuilder L = a.L("FragmentTabHost.SavedState{");
L.append(Integer.toHexString(System.identityHashCode(this)));
L.append(" curTab=");
return a.D(L, this.curTab, "}");
}
@Override // android.view.View.BaseSavedState, android.os.Parcelable, android.view.AbsSavedState
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeString(this.curTab);
}
}
public static final class TabInfo {
@Nullable
public final Bundle args;
@NonNull
public final Class<?> clss;
public Fragment fragment;
@NonNull
public final String tag;
public TabInfo(@NonNull String str, @NonNull Class<?> cls, @Nullable Bundle bundle) {
this.tag = str;
this.clss = cls;
this.args = bundle;
}
}
@Deprecated
public FragmentTabHost(@NonNull Context context) {
super(context, null);
initFragmentTabHost(context, null);
}
@Deprecated
public FragmentTabHost(@NonNull Context context, @Nullable AttributeSet attributeSet) {
super(context, attributeSet);
initFragmentTabHost(context, attributeSet);
}
@Nullable
private FragmentTransaction doTabChanged(@Nullable String str, @Nullable FragmentTransaction fragmentTransaction) {
Fragment fragment;
TabInfo tabInfoForTag = getTabInfoForTag(str);
if (this.mLastTab != tabInfoForTag) {
if (fragmentTransaction == null) {
fragmentTransaction = this.mFragmentManager.beginTransaction();
}
TabInfo tabInfo = this.mLastTab;
if (!(tabInfo == null || (fragment = tabInfo.fragment) == null)) {
fragmentTransaction.detach(fragment);
}
if (tabInfoForTag != null) {
Fragment fragment2 = tabInfoForTag.fragment;
if (fragment2 == null) {
Fragment instantiate = this.mFragmentManager.getFragmentFactory().instantiate(this.mContext.getClassLoader(), tabInfoForTag.clss.getName());
tabInfoForTag.fragment = instantiate;
instantiate.setArguments(tabInfoForTag.args);
fragmentTransaction.add(this.mContainerId, tabInfoForTag.fragment, tabInfoForTag.tag);
} else {
fragmentTransaction.attach(fragment2);
}
}
this.mLastTab = tabInfoForTag;
}
return fragmentTransaction;
}
private void ensureContent() {
if (this.mRealTabContent == null) {
FrameLayout frameLayout = (FrameLayout) findViewById(this.mContainerId);
this.mRealTabContent = frameLayout;
if (frameLayout == null) {
StringBuilder L = a.L("No tab content FrameLayout found for id ");
L.append(this.mContainerId);
throw new IllegalStateException(L.toString());
}
}
}
private void ensureHierarchy(Context context) {
if (findViewById(16908307) == null) {
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(1);
addView(linearLayout, new FrameLayout.LayoutParams(-1, -1));
TabWidget tabWidget = new TabWidget(context);
tabWidget.setId(16908307);
tabWidget.setOrientation(0);
linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(-1, -2, 0.0f));
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setId(16908305);
linearLayout.addView(frameLayout, new LinearLayout.LayoutParams(0, 0, 0.0f));
FrameLayout frameLayout2 = new FrameLayout(context);
this.mRealTabContent = frameLayout2;
frameLayout2.setId(this.mContainerId);
linearLayout.addView(frameLayout2, new LinearLayout.LayoutParams(-1, 0, 1.0f));
}
}
@Nullable
private TabInfo getTabInfoForTag(String str) {
int size = this.mTabs.size();
for (int i = 0; i < size; i++) {
TabInfo tabInfo = this.mTabs.get(i);
if (tabInfo.tag.equals(str)) {
return tabInfo;
}
}
return null;
}
private void initFragmentTabHost(Context context, AttributeSet attributeSet) {
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{16842995}, 0, 0);
this.mContainerId = obtainStyledAttributes.getResourceId(0, 0);
obtainStyledAttributes.recycle();
super.setOnTabChangedListener(this);
}
@Deprecated
public void addTab(@NonNull TabHost.TabSpec tabSpec, @NonNull Class<?> cls, @Nullable Bundle bundle) {
tabSpec.setContent(new DummyTabFactory(this.mContext));
String tag = tabSpec.getTag();
TabInfo tabInfo = new TabInfo(tag, cls, bundle);
if (this.mAttached) {
Fragment findFragmentByTag = this.mFragmentManager.findFragmentByTag(tag);
tabInfo.fragment = findFragmentByTag;
if (findFragmentByTag != null && !findFragmentByTag.isDetached()) {
FragmentTransaction beginTransaction = this.mFragmentManager.beginTransaction();
beginTransaction.detach(tabInfo.fragment);
beginTransaction.commit();
}
}
this.mTabs.add(tabInfo);
addTab(tabSpec);
}
@Override // android.view.View, android.view.ViewGroup
@Deprecated
public void onAttachedToWindow() {
super.onAttachedToWindow();
String currentTabTag = getCurrentTabTag();
int size = this.mTabs.size();
FragmentTransaction fragmentTransaction = null;
for (int i = 0; i < size; i++) {
TabInfo tabInfo = this.mTabs.get(i);
Fragment findFragmentByTag = this.mFragmentManager.findFragmentByTag(tabInfo.tag);
tabInfo.fragment = findFragmentByTag;
if (findFragmentByTag != null && !findFragmentByTag.isDetached()) {
if (tabInfo.tag.equals(currentTabTag)) {
this.mLastTab = tabInfo;
} else {
if (fragmentTransaction == null) {
fragmentTransaction = this.mFragmentManager.beginTransaction();
}
fragmentTransaction.detach(tabInfo.fragment);
}
}
}
this.mAttached = true;
FragmentTransaction doTabChanged = doTabChanged(currentTabTag, fragmentTransaction);
if (doTabChanged != null) {
doTabChanged.commit();
this.mFragmentManager.executePendingTransactions();
}
}
@Override // android.view.View, android.view.ViewGroup
@Deprecated
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
this.mAttached = false;
}
@Override // android.view.View
@Deprecated
public void onRestoreInstanceState(@SuppressLint({"UnknownNullness"}) Parcelable parcelable) {
if (!(parcelable instanceof SavedState)) {
super.onRestoreInstanceState(parcelable);
return;
}
SavedState savedState = (SavedState) parcelable;
super.onRestoreInstanceState(savedState.getSuperState());
setCurrentTabByTag(savedState.curTab);
}
@Override // android.view.View
@NonNull
@Deprecated
public Parcelable onSaveInstanceState() {
SavedState savedState = new SavedState(super.onSaveInstanceState());
savedState.curTab = getCurrentTabTag();
return savedState;
}
@Override // android.widget.TabHost.OnTabChangeListener
@Deprecated
public void onTabChanged(@Nullable String str) {
FragmentTransaction doTabChanged;
if (this.mAttached && (doTabChanged = doTabChanged(str, null)) != null) {
doTabChanged.commit();
}
TabHost.OnTabChangeListener onTabChangeListener = this.mOnTabChangeListener;
if (onTabChangeListener != null) {
onTabChangeListener.onTabChanged(str);
}
}
@Override // android.widget.TabHost
@Deprecated
public void setOnTabChangedListener(@Nullable TabHost.OnTabChangeListener onTabChangeListener) {
this.mOnTabChangeListener = onTabChangeListener;
}
@Override // android.widget.TabHost
@Deprecated
public void setup() {
throw new IllegalStateException("Must call setup() that takes a Context and FragmentManager");
}
@Deprecated
public void setup(@NonNull Context context, @NonNull FragmentManager fragmentManager) {
ensureHierarchy(context);
super.setup();
this.mContext = context;
this.mFragmentManager = fragmentManager;
ensureContent();
}
@Deprecated
public void setup(@NonNull Context context, @NonNull FragmentManager fragmentManager, int i) {
ensureHierarchy(context);
super.setup();
this.mContext = context;
this.mFragmentManager = fragmentManager;
this.mContainerId = i;
ensureContent();
this.mRealTabContent.setId(i);
if (getId() == -1) {
setId(16908306);
}
}
}