Add task thumbnails to the Recents Go loader.
This CL adds thumbnails to the content loading for Recents Go so that they are fully loaded before recents show. We utilize the underlying recents model thumbnail cache to make the loading faster. Bug: 114136250 Test: Build Launcher3GoIconRecents Change-Id: Ib21f617e83d307621364c2eeb6fef84aad49814b
This commit is contained in:
parent
9db9d62b27
commit
b9ebd812a4
|
@ -85,34 +85,40 @@ public final class TaskListLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads task content for a list of tasks, including the label and the icon. Uses the list of
|
* Loads task content for a list of tasks, including the label, icon, and thumbnail. For content
|
||||||
* tasks since the last load as a cache for loaded content.
|
* that isn't cached, load the content asynchronously in the background.
|
||||||
*
|
*
|
||||||
* @param tasksToLoad list of tasks that need to load their content
|
* @param tasksToLoad list of tasks that need to load their content
|
||||||
* @param onLoadedCallback runnable to run after all tasks have loaded their content
|
* @param onFullyLoadedCallback runnable to run after all tasks have loaded their content
|
||||||
*/
|
*/
|
||||||
private void loadTaskContents(ArrayList<Task> tasksToLoad,
|
private void loadTaskContents(ArrayList<Task> tasksToLoad,
|
||||||
@Nullable Runnable onLoadedCallback) {
|
@Nullable Runnable onFullyLoadedCallback) {
|
||||||
AtomicInteger loadRequestsCount = new AtomicInteger(0);
|
// Make two load requests per task, one for the icon/title and one for the thumbnail.
|
||||||
|
AtomicInteger loadRequestsCount = new AtomicInteger(tasksToLoad.size() * 2);
|
||||||
|
Runnable itemLoadedRunnable = () -> {
|
||||||
|
if (loadRequestsCount.decrementAndGet() == 0 && onFullyLoadedCallback != null) {
|
||||||
|
onFullyLoadedCallback.run();
|
||||||
|
}
|
||||||
|
};
|
||||||
for (Task task : tasksToLoad) {
|
for (Task task : tasksToLoad) {
|
||||||
|
// Load icon and title.
|
||||||
int index = mTaskList.indexOf(task);
|
int index = mTaskList.indexOf(task);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
// If we've already loaded the task and have its content then just copy it over.
|
// If we've already loaded the task and have its content then just copy it over.
|
||||||
Task loadedTask = mTaskList.get(index);
|
Task loadedTask = mTaskList.get(index);
|
||||||
task.titleDescription = loadedTask.titleDescription;
|
task.titleDescription = loadedTask.titleDescription;
|
||||||
task.icon = loadedTask.icon;
|
task.icon = loadedTask.icon;
|
||||||
|
itemLoadedRunnable.run();
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, load the content in the background.
|
// Otherwise, load the content in the background.
|
||||||
loadRequestsCount.getAndIncrement();
|
mRecentsModel.getIconCache().updateIconInBackground(task,
|
||||||
mRecentsModel.getIconCache().updateIconInBackground(task, loadedTask -> {
|
loadedTask -> itemLoadedRunnable.run());
|
||||||
if (loadRequestsCount.decrementAndGet() == 0 && onLoadedCallback != null) {
|
|
||||||
onLoadedCallback.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (loadRequestsCount.get() == 0 && onLoadedCallback != null) {
|
// Load the thumbnail. May return immediately and synchronously if the thumbnail is
|
||||||
onLoadedCallback.run();
|
// cached.
|
||||||
|
mRecentsModel.getThumbnailCache().updateThumbnailInBackground(task,
|
||||||
|
thumbnail -> itemLoadedRunnable.run());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue