Rabbit-R1/android (non root)/java/sources/androidx/fragment/app/ListFragment.java
2024-05-21 17:08:36 -04:00

243 lines
9 KiB
Java

package androidx.fragment.app;
import android.R;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
/* loaded from: classes2.dex */
public class ListFragment extends Fragment {
static final int INTERNAL_EMPTY_ID = 16711681;
static final int INTERNAL_LIST_CONTAINER_ID = 16711683;
static final int INTERNAL_PROGRESS_CONTAINER_ID = 16711682;
ListAdapter mAdapter;
CharSequence mEmptyText;
View mEmptyView;
ListView mList;
View mListContainer;
boolean mListShown;
View mProgressContainer;
TextView mStandardEmptyView;
private final Handler mHandler = new Handler();
private final Runnable mRequestFocus = new Runnable() { // from class: androidx.fragment.app.ListFragment.1
@Override // java.lang.Runnable
public void run() {
ListFragment.this.mList.focusableViewAvailable(ListFragment.this.mList);
}
};
private final AdapterView.OnItemClickListener mOnClickListener = new AdapterView.OnItemClickListener() { // from class: androidx.fragment.app.ListFragment.2
@Override // android.widget.AdapterView.OnItemClickListener
public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
ListFragment.this.onListItemClick((ListView) adapterView, view, i, j);
}
};
public ListAdapter getListAdapter() {
return this.mAdapter;
}
public void onListItemClick(ListView listView, View view, int i, long j) {
}
@Override // androidx.fragment.app.Fragment
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
Context requireContext = requireContext();
FrameLayout frameLayout = new FrameLayout(requireContext);
LinearLayout linearLayout = new LinearLayout(requireContext);
linearLayout.setId(INTERNAL_PROGRESS_CONTAINER_ID);
linearLayout.setOrientation(1);
linearLayout.setVisibility(8);
linearLayout.setGravity(17);
linearLayout.addView(new ProgressBar(requireContext, null, R.attr.progressBarStyleLarge), new FrameLayout.LayoutParams(-2, -2));
frameLayout.addView(linearLayout, new FrameLayout.LayoutParams(-1, -1));
FrameLayout frameLayout2 = new FrameLayout(requireContext);
frameLayout2.setId(INTERNAL_LIST_CONTAINER_ID);
TextView textView = new TextView(requireContext);
textView.setId(INTERNAL_EMPTY_ID);
textView.setGravity(17);
frameLayout2.addView(textView, new FrameLayout.LayoutParams(-1, -1));
ListView listView = new ListView(requireContext);
listView.setId(R.id.list);
listView.setDrawSelectorOnTop(false);
frameLayout2.addView(listView, new FrameLayout.LayoutParams(-1, -1));
frameLayout.addView(frameLayout2, new FrameLayout.LayoutParams(-1, -1));
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
return frameLayout;
}
@Override // androidx.fragment.app.Fragment
public void onViewCreated(View view, Bundle bundle) {
super.onViewCreated(view, bundle);
ensureList();
}
@Override // androidx.fragment.app.Fragment
public void onDestroyView() {
this.mHandler.removeCallbacks(this.mRequestFocus);
this.mList = null;
this.mListShown = false;
this.mListContainer = null;
this.mProgressContainer = null;
this.mEmptyView = null;
this.mStandardEmptyView = null;
super.onDestroyView();
}
public void setListAdapter(ListAdapter listAdapter) {
boolean z = this.mAdapter != null;
this.mAdapter = listAdapter;
ListView listView = this.mList;
if (listView != null) {
listView.setAdapter(listAdapter);
if (this.mListShown || z) {
return;
}
setListShown(true, requireView().getWindowToken() != null);
}
}
public void setSelection(int i) {
ensureList();
this.mList.setSelection(i);
}
public int getSelectedItemPosition() {
ensureList();
return this.mList.getSelectedItemPosition();
}
public long getSelectedItemId() {
ensureList();
return this.mList.getSelectedItemId();
}
public ListView getListView() {
ensureList();
return this.mList;
}
public void setEmptyText(CharSequence charSequence) {
ensureList();
TextView textView = this.mStandardEmptyView;
if (textView == null) {
throw new IllegalStateException("Can't be used with a custom content view");
}
textView.setText(charSequence);
if (this.mEmptyText == null) {
this.mList.setEmptyView(this.mStandardEmptyView);
}
this.mEmptyText = charSequence;
}
public void setListShown(boolean z) {
setListShown(z, true);
}
public void setListShownNoAnimation(boolean z) {
setListShown(z, false);
}
private void setListShown(boolean z, boolean z2) {
ensureList();
View view = this.mProgressContainer;
if (view == null) {
throw new IllegalStateException("Can't be used with a custom content view");
}
if (this.mListShown == z) {
return;
}
this.mListShown = z;
if (z) {
if (z2) {
view.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.fade_out));
this.mListContainer.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.fade_in));
} else {
view.clearAnimation();
this.mListContainer.clearAnimation();
}
this.mProgressContainer.setVisibility(8);
this.mListContainer.setVisibility(0);
return;
}
if (z2) {
view.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.fade_in));
this.mListContainer.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.fade_out));
} else {
view.clearAnimation();
this.mListContainer.clearAnimation();
}
this.mProgressContainer.setVisibility(0);
this.mListContainer.setVisibility(8);
}
public final ListAdapter requireListAdapter() {
ListAdapter listAdapter = getListAdapter();
if (listAdapter != null) {
return listAdapter;
}
throw new IllegalStateException("ListFragment " + this + " does not have a ListAdapter.");
}
private void ensureList() {
if (this.mList != null) {
return;
}
View view = getView();
if (view == null) {
throw new IllegalStateException("Content view not yet created");
}
if (view instanceof ListView) {
this.mList = (ListView) view;
} else {
TextView textView = (TextView) view.findViewById(INTERNAL_EMPTY_ID);
this.mStandardEmptyView = textView;
if (textView == null) {
this.mEmptyView = view.findViewById(R.id.empty);
} else {
textView.setVisibility(8);
}
this.mProgressContainer = view.findViewById(INTERNAL_PROGRESS_CONTAINER_ID);
this.mListContainer = view.findViewById(INTERNAL_LIST_CONTAINER_ID);
View findViewById = view.findViewById(R.id.list);
if (!(findViewById instanceof ListView)) {
if (findViewById == null) {
throw new RuntimeException("Your content must have a ListView whose id attribute is 'android.R.id.list'");
}
throw new RuntimeException("Content has view with id attribute 'android.R.id.list' that is not a ListView class");
}
ListView listView = (ListView) findViewById;
this.mList = listView;
View view2 = this.mEmptyView;
if (view2 != null) {
listView.setEmptyView(view2);
} else {
CharSequence charSequence = this.mEmptyText;
if (charSequence != null) {
this.mStandardEmptyView.setText(charSequence);
this.mList.setEmptyView(this.mStandardEmptyView);
}
}
}
this.mListShown = true;
this.mList.setOnItemClickListener(this.mOnClickListener);
ListAdapter listAdapter = this.mAdapter;
if (listAdapter != null) {
this.mAdapter = null;
setListAdapter(listAdapter);
} else if (this.mProgressContainer != null) {
setListShown(false, false);
}
this.mHandler.post(this.mRequestFocus);
}
}