Reduce flickers when launching Storage Settings

This change remove unnecessary UI dpdate of
StorageItemPreferenceController.

- For StorageItemPreferenceController:
  Remove UI update at #displayPreference since onLoadFinished will update.
  Don't update order at #setVolume since onLoadFinished will update.

- StorageDashboardFragment & StorageCategoryFragment update
  StorageItemPreferenceController only when both StorageInfo
  and StorageResult are loaded.

Bug: 185547228
Test: atest com.android.settings.deviceinfo
      atest com.android.settings.deviceinfo.storage
      make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo
      make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo.storage
      manual visual
      Click each file category to count files size is the same as
      displayed in Storage Settings.
      manual visual
Change-Id: Id449003827a3e340e7a90f706152100b5568f834
This commit is contained in:
Arc Wang
2021-05-26 14:22:28 +08:00
parent aab74b24c0
commit 96b6106f2f
4 changed files with 43 additions and 80 deletions

View File

@@ -232,14 +232,16 @@ public class StorageDashboardFragment extends DashboardFragment
mOptionMenuController.setSelectedStorageEntry(mSelectedStorageEntry);
getActivity().invalidateOptionsMenu();
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
if (!mSelectedStorageEntry.isMounted()) {
// Set null volume to hide category stats.
mPreferenceController.setVolume(null);
return;
}
if (mSelectedStorageEntry.isPrivate()) {
mStorageInfo = null;
mAppsResult = null;
maybeSetLoading(isQuotaSupported());
// Stats data is only available on private volumes.
getLoaderManager().restartLoader(STORAGE_JOB_ID, Bundle.EMPTY, this);
getLoaderManager()
@@ -315,7 +317,6 @@ public class StorageDashboardFragment extends DashboardFragment
public void onViewCreated(View v, Bundle savedInstanceState) {
super.onViewCreated(v, savedInstanceState);
initializeCacheProvider();
maybeSetLoading(isQuotaSupported());
EntityHeaderController.newInstance(getActivity(), this /*fragment*/,
null /* header view */)
@@ -350,33 +351,27 @@ public class StorageDashboardFragment extends DashboardFragment
}
private void onReceivedSizes() {
boolean stopLoading = false;
if (mStorageInfo != null) {
final long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
final AbstractPreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) {
SecondaryUserController userController = (SecondaryUserController) controller;
userController.setTotalSize(mStorageInfo.totalBytes);
}
}
stopLoading = true;
if (mStorageInfo == null || mAppsResult == null) {
return;
}
if (mAppsResult != null) {
mPreferenceController.onLoadFinished(mAppsResult, mUserId);
updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);
stopLoading = true;
final long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
final AbstractPreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) {
SecondaryUserController userController = (SecondaryUserController) controller;
userController.setTotalSize(mStorageInfo.totalBytes);
}
}
// setLoading always causes a flicker, so let's avoid doing it.
if (stopLoading) {
if (getView().findViewById(R.id.loading_container).getVisibility() == View.VISIBLE) {
setLoading(false, true);
}
mPreferenceController.onLoadFinished(mAppsResult, mUserId);
updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);
if (getView().findViewById(R.id.loading_container).getVisibility() == View.VISIBLE) {
setLoading(false, true);
}
}