Don't put up loading UI if load isn't necessary.

Do not put up the loading UI when we don't need to load (whether that's
because we're already up to date or there is already a load in progress)

Bug: 114136250
Test: Manual; go to recents and see that it doesn't load when updated
Change-Id: Idbcc3731e4ecab8f67b7b5b07a98cb112ed4e07a
This commit is contained in:
Kevin 2019-04-05 13:25:11 -07:00
parent 5a0f7b1c3b
commit 2bd36dd326
2 changed files with 18 additions and 4 deletions

View File

@ -67,17 +67,27 @@ public final class TaskListLoader {
return Collections.unmodifiableList(mTaskList);
}
/**
* Whether or not the loader needs to load data to be up to date. This can return true if the
* task list is already up to date OR there is already a load in progress for the task list to
* become up to date.
*
* @return true if already up to date or load in progress, false otherwise
*/
public boolean needsToLoad() {
return !mRecentsModel.isTaskListValid(mTaskListChangeId);
}
/**
* Fetches the most recent tasks and updates the task list asynchronously. This call does not
* provide guarantees the task content (icon, thumbnail, label) are loaded but will fill in
* what it has. May run the callback immediately if there have been no changes in the task
* list.
* list since the start of the last load.
*
* @param onLoadedCallback callback to run when task list is loaded
*/
public void loadTaskList(@Nullable Consumer<ArrayList<Task>> onLoadedCallback) {
if (mRecentsModel.isTaskListValid(mTaskListChangeId)) {
// Current task list is already up to date. No need to update.
if (!needsToLoad()) {
if (onLoadedCallback != null) {
onLoadedCallback.accept(mTaskList);
}

View File

@ -166,9 +166,13 @@ public final class IconRecentsView extends FrameLayout {
*/
public void onBeginTransitionToOverview() {
mTaskRecyclerView.scheduleLayoutAnimation();
// Load any task changes
if (!mTaskLoader.needsToLoad()) {
return;
}
mTaskAdapter.setIsShowingLoadingUi(true);
mTaskAdapter.notifyDataSetChanged();
// Load any task changes
mTaskLoader.loadTaskList(tasks -> {
mTaskAdapter.setIsShowingLoadingUi(false);
// TODO: Animate the loading UI out and the loaded data in.