Revert "Fix 'No Apps' UI issues of ManageApplications"

This reverts commit 4a97095e36.

Reason for revert: <It has abnormal scroll behavior when there is no profile tab>

Bug: 191945032
Bug: 191944934
Change-Id: Id6c71fbec4f490034bc07f6d8c9efabcb877d110
This commit is contained in:
Arc Wang
2021-06-24 07:45:15 +00:00
parent 4a97095e36
commit 0358562a9b
6 changed files with 102 additions and 115 deletions

View File

@@ -72,11 +72,7 @@ public class RunningServices extends SettingsPreferenceFragment {
public void onResume() {
super.onResume();
boolean haveData = mRunningProcessesView.doResume(this, mRunningProcessesAvail);
if (haveData) {
mLoadingViewController.showContent(false /* animate */);
} else {
mLoadingViewController.showLoadingView();
}
mLoadingViewController.handleLoadingContainer(haveData /* done */, false /* animate */);
}
@Override

View File

@@ -208,6 +208,7 @@ public class ManageApplications extends InstrumentedFragment
private ApplicationsAdapter mApplications;
private View mLoadingContainer;
private View mListContainer;
private SearchView mSearchView;
// Size resource used for packages whose size computation failed for some reason
@@ -401,21 +402,25 @@ public class ManageApplications extends InstrumentedFragment
mRootView = inflater.inflate(R.layout.manage_applications_apps, null);
mLoadingContainer = mRootView.findViewById(R.id.loading_container);
mEmptyView = mRootView.findViewById(android.R.id.empty);
mRecyclerView = mRootView.findViewById(R.id.apps_list);
mListContainer = mRootView.findViewById(R.id.list_container);
if (mListContainer != null) {
// Create adapter and list view here
mEmptyView = mListContainer.findViewById(android.R.id.empty);
mApplications = new ApplicationsAdapter(mApplicationsState, this, mFilter,
savedInstanceState);
if (savedInstanceState != null) {
mApplications.mHasReceivedLoadEntries =
savedInstanceState.getBoolean(EXTRA_HAS_ENTRIES, false);
mApplications.mHasReceivedBridgeCallback =
savedInstanceState.getBoolean(EXTRA_HAS_BRIDGE, false);
mApplications = new ApplicationsAdapter(mApplicationsState, this, mFilter,
savedInstanceState);
if (savedInstanceState != null) {
mApplications.mHasReceivedLoadEntries =
savedInstanceState.getBoolean(EXTRA_HAS_ENTRIES, false);
mApplications.mHasReceivedBridgeCallback =
savedInstanceState.getBoolean(EXTRA_HAS_BRIDGE, false);
}
mRecyclerView = mListContainer.findViewById(R.id.apps_list);
mRecyclerView.setItemAnimator(null);
mRecyclerView.setLayoutManager(new LinearLayoutManager(
getContext(), RecyclerView.VERTICAL, false /* reverseLayout */));
mRecyclerView.setAdapter(mApplications);
}
mRecyclerView.setItemAnimator(null);
mRecyclerView.setLayoutManager(new LinearLayoutManager(
getContext(), RecyclerView.VERTICAL, false /* reverseLayout */));
mRecyclerView.setAdapter(mApplications);
// We have to do this now because PreferenceFrameLayout looks at it
// only when the view is added.
@@ -980,8 +985,16 @@ public class ManageApplications extends InstrumentedFragment
// overlapped by floating filter.
if (hasFilter) {
mManageApplications.mSpinnerHeader.setVisibility(View.VISIBLE);
mManageApplications.mRecyclerView.setPadding(0 /* left */,
mContext.getResources().getDimensionPixelSize(
R.dimen.app_bar_height) /* top */,
0 /* right */,
0 /* bottom */);
} else {
mManageApplications.mSpinnerHeader.setVisibility(View.GONE);
mManageApplications.mRecyclerView.setPadding(0 /* left */, 0 /* top */,
0 /* right */,
0 /* bottom */);
}
}
}
@@ -1031,8 +1044,7 @@ public class ManageApplications extends InstrumentedFragment
mManageApplications = manageApplications;
mLoadingViewController = new LoadingViewController(
mManageApplications.mLoadingContainer,
mManageApplications.mRecyclerView,
mManageApplications.mEmptyView
mManageApplications.mListContainer
);
mContext = manageApplications.getActivity();
mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
@@ -1291,9 +1303,11 @@ public class ManageApplications extends InstrumentedFragment
mOriginalEntries = entries;
notifyDataSetChanged();
if (getItemCount() == 0) {
mLoadingViewController.showEmpty(false /* animate */);
mManageApplications.mRecyclerView.setVisibility(View.GONE);
mManageApplications.mEmptyView.setVisibility(View.VISIBLE);
} else {
mLoadingViewController.showContent(false /* animate */);
mManageApplications.mEmptyView.setVisibility(View.GONE);
mManageApplications.mRecyclerView.setVisibility(View.VISIBLE);
if (mManageApplications.mSearchView != null
&& mManageApplications.mSearchView.isVisibleToUser()) {
@@ -1310,6 +1324,10 @@ public class ManageApplications extends InstrumentedFragment
mLastIndex = -1;
}
if (mSession.getAllApps().size() != 0
&& mManageApplications.mListContainer.getVisibility() != View.VISIBLE) {
mLoadingViewController.showContent(true /* animate */);
}
if (mManageApplications.mListType == LIST_TYPE_USAGE_ACCESS) {
// No enabled or disabled filters for usage access.
return;

View File

@@ -22,66 +22,34 @@ import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import androidx.annotation.Nullable;
/**
* A helper class that manages show/hide loading spinner, content view and empty view (optional).
* A helper class that manages show/hide loading spinner.
*/
public class LoadingViewController {
private static final long DELAY_SHOW_LOADING_CONTAINER_THRESHOLD_MS = 100L;
private final Handler mFgHandler;
private final View mLoadingView;
private final View mContentView;
private final View mEmptyView;
public final Handler mFgHandler;
public final View mLoadingView;
public final View mContentView;
public LoadingViewController(View loadingView, View contentView) {
this(loadingView, contentView, null /* emptyView*/);
}
public LoadingViewController(View loadingView, View contentView, @Nullable View emptyView) {
mLoadingView = loadingView;
mContentView = contentView;
mEmptyView = emptyView;
mFgHandler = new Handler(Looper.getMainLooper());
}
private Runnable mShowLoadingContainerRunnable = new Runnable() {
public void run() {
showLoadingView();
handleLoadingContainer(false /* done */, false /* animate */);
}
};
/**
* Shows content view and hides loading view & empty view.
*/
public void showContent(boolean animate) {
// Cancel any pending task to show the loading animation and show the list of
// apps directly.
mFgHandler.removeCallbacks(mShowLoadingContainerRunnable);
handleLoadingContainer(true /* showContent */, false /* showEmpty*/, animate);
}
/**
* Shows empty view and hides loading view & content view.
*/
public void showEmpty(boolean animate) {
if (mEmptyView == null) {
return;
}
// Cancel any pending task to show the loading animation and show the list of
// apps directly.
mFgHandler.removeCallbacks(mShowLoadingContainerRunnable);
handleLoadingContainer(false /* showContent */, true /* showEmpty */, animate);
}
/**
* Shows loading view and hides content view & empty view.
*/
public void showLoadingView() {
handleLoadingContainer(false /* showContent */, false /* showEmpty */, false /* animate */);
handleLoadingContainer(true /* show */, animate);
}
public void showLoadingViewDelayed() {
@@ -89,9 +57,8 @@ public class LoadingViewController {
mShowLoadingContainerRunnable, DELAY_SHOW_LOADING_CONTAINER_THRESHOLD_MS);
}
private void handleLoadingContainer(boolean showContent, boolean showEmpty, boolean animate) {
handleLoadingContainer(mLoadingView, mContentView, mEmptyView,
showContent, showEmpty, animate);
public void handleLoadingContainer(boolean done, boolean animate) {
handleLoadingContainer(mLoadingView, mContentView, done, animate);
}
/**
@@ -108,25 +75,6 @@ public class LoadingViewController {
setViewShown(content, done, animate);
}
/**
* Show/hide loading view and content view and empty view.
*
* @param loading The loading spinner view
* @param content The content view
* @param empty The empty view shows no item summary to users.
* @param showContent If true, content is set visible and loading is set invisible.
* @param showEmpty If true, empty is set visible and loading is set invisible.
* @param animate Whether or not content/loading views should animate in/out.
*/
public static void handleLoadingContainer(View loading, View content, View empty,
boolean showContent, boolean showEmpty, boolean animate) {
if (empty != null) {
setViewShown(empty, showEmpty, animate);
}
setViewShown(content, showContent, animate);
setViewShown(loading, !showContent && !showEmpty, animate);
}
private static void setViewShown(final View view, boolean shown, boolean animate) {
if (animate) {
Animation animation = AnimationUtils.loadAnimation(view.getContext(),