Merge "Add task item view for Recents Go." into ub-launcher3-master
diff --git a/go/quickstep/src/com/android/quickstep/TaskListLoader.java b/go/quickstep/src/com/android/quickstep/TaskListLoader.java
index 9f359b4..c798cef 100644
--- a/go/quickstep/src/com/android/quickstep/TaskListLoader.java
+++ b/go/quickstep/src/com/android/quickstep/TaskListLoader.java
@@ -85,34 +85,40 @@
}
/**
- * Loads task content for a list of tasks, including the label and the icon. Uses the list of
- * tasks since the last load as a cache for loaded content.
+ * Loads task content for a list of tasks, including the label, icon, and thumbnail. For content
+ * that isn't cached, load the content asynchronously in the background.
*
* @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,
- @Nullable Runnable onLoadedCallback) {
- AtomicInteger loadRequestsCount = new AtomicInteger(0);
+ @Nullable Runnable onFullyLoadedCallback) {
+ // 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) {
+ // Load icon and title.
int index = mTaskList.indexOf(task);
if (index >= 0) {
// If we've already loaded the task and have its content then just copy it over.
Task loadedTask = mTaskList.get(index);
task.titleDescription = loadedTask.titleDescription;
task.icon = loadedTask.icon;
+ itemLoadedRunnable.run();
} else {
// Otherwise, load the content in the background.
- loadRequestsCount.getAndIncrement();
- mRecentsModel.getIconCache().updateIconInBackground(task, loadedTask -> {
- if (loadRequestsCount.decrementAndGet() == 0 && onLoadedCallback != null) {
- onLoadedCallback.run();
- }
- });
+ mRecentsModel.getIconCache().updateIconInBackground(task,
+ loadedTask -> itemLoadedRunnable.run());
}
- }
- if (loadRequestsCount.get() == 0 && onLoadedCallback != null) {
- onLoadedCallback.run();
+
+ // Load the thumbnail. May return immediately and synchronously if the thumbnail is
+ // cached.
+ mRecentsModel.getThumbnailCache().updateThumbnailInBackground(task,
+ thumbnail -> itemLoadedRunnable.run());
}
}
}
diff --git a/src/com/android/launcher3/config/BaseFlags.java b/src/com/android/launcher3/config/BaseFlags.java
index d6e450a..cb239b3 100644
--- a/src/com/android/launcher3/config/BaseFlags.java
+++ b/src/com/android/launcher3/config/BaseFlags.java
@@ -21,6 +21,9 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
+import android.database.ContentObserver;
+import android.os.Handler;
+import android.os.Looper;
import android.provider.Settings;
import androidx.annotation.GuardedBy;
@@ -256,6 +259,16 @@
@Override
public void initialize(Context context) {
contentResolver = context.getContentResolver();
+ contentResolver.registerContentObserver(Settings.Global.getUriFor(getKey()), true,
+ new ContentObserver(new Handler(Looper.getMainLooper())) {
+ @Override
+ public void onChange(boolean selfChange) {
+ superInitialize(context);
+ }});
+ superInitialize(context);
+ }
+
+ private void superInitialize(Context context) {
super.initialize(context);
}
@@ -274,10 +287,5 @@
}
return Settings.Global.getInt(contentResolver, getKey(), defaultValue ? 1 : 0) == 1;
}
-
- @Override
- public boolean get() {
- return getFromStorage(null, getDefaultValue());
- }
}
}