Ensuring that all the pending tasks are run
before marking the ViewOnDrawExecutor as completed.
Also fixing model writer not updated on rotation
Change-Id: I5ecd7ac865b939ffa4c02afe892bd773d9f275c3
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index b87511a..1d474da 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -304,12 +304,11 @@
LauncherAppState app = LauncherAppState.getInstance(this);
mOldConfig = new Configuration(getResources().getConfiguration());
+ mModel = app.setLauncher(this);
initDeviceProfile(app.getInvariantDeviceProfile());
mSharedPrefs = Utilities.getPrefs(this);
mIsSafeModeEnabled = getPackageManager().isSafeMode();
- mModel = app.setLauncher(this);
- mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout());
mIconCache = app.getIconCache();
mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
@@ -434,6 +433,7 @@
display.getSize(mwSize);
mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
}
+ mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout());
}
@Override
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index a4d188f..6646b78 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -444,11 +444,7 @@
if (mCallbacks != null && mCallbacks.get() != null) {
final Callbacks oldCallbacks = mCallbacks.get();
// Clear any pending bind-runnables from the synchronized load process.
- mUiExecutor.execute(new Runnable() {
- public void run() {
- oldCallbacks.clearPendingBinds();
- }
- });
+ mUiExecutor.execute(oldCallbacks::clearPendingBinds);
// If there is already one running, tell it to stop.
stopLoader();
diff --git a/src/com/android/launcher3/model/LoaderResults.java b/src/com/android/launcher3/model/LoaderResults.java
index 24e5b9c..5acc790 100644
--- a/src/com/android/launcher3/model/LoaderResults.java
+++ b/src/com/android/launcher3/model/LoaderResults.java
@@ -162,7 +162,7 @@
// This ensures that the first screen is immediately visible (eg. during rotation)
// In case of !validFirstPage, bind all pages one after other.
final Executor deferredExecutor =
- validFirstPage ? new ViewOnDrawExecutor(mUiExecutor) : mainExecutor;
+ validFirstPage ? new ViewOnDrawExecutor() : mainExecutor;
mainExecutor.execute(new Runnable() {
@Override
diff --git a/src/com/android/launcher3/util/ViewOnDrawExecutor.java b/src/com/android/launcher3/util/ViewOnDrawExecutor.java
index 34bdcc9..acce308 100644
--- a/src/com/android/launcher3/util/ViewOnDrawExecutor.java
+++ b/src/com/android/launcher3/util/ViewOnDrawExecutor.java
@@ -34,20 +34,14 @@
OnAttachStateChangeListener {
private final ArrayList<Runnable> mTasks = new ArrayList<>();
- private final Executor mExecutor;
private Launcher mLauncher;
private View mAttachedView;
private boolean mCompleted;
- private boolean mIsExecuting;
private boolean mLoadAnimationCompleted;
private boolean mFirstDrawCompleted;
- public ViewOnDrawExecutor(Executor executor) {
- mExecutor = executor;
- }
-
public void attachTo(Launcher launcher) {
attachTo(launcher, launcher.getWorkspace(), true /* waitForLoadAnimation */);
}
@@ -89,13 +83,6 @@
mAttachedView.post(this);
}
- /**
- * Returns whether the executor is still queuing tasks and hasn't yet executed them.
- */
- public boolean canQueue() {
- return !mIsExecuting && !mCompleted;
- }
-
public void onLoadAnimationCompleted() {
mLoadAnimationCompleted = true;
if (mAttachedView != null) {
@@ -107,7 +94,6 @@
public void run() {
// Post the pending tasks after both onDraw and onLoadAnimationCompleted have been called.
if (mLoadAnimationCompleted && mFirstDrawCompleted && !mCompleted) {
- mIsExecuting = true;
runAllTasks();
}
}
@@ -115,7 +101,6 @@
public void markCompleted() {
mTasks.clear();
mCompleted = true;
- mIsExecuting = false;
if (mAttachedView != null) {
mAttachedView.getViewTreeObserver().removeOnDrawListener(this);
mAttachedView.removeOnAttachStateChangeListener(this);
@@ -132,7 +117,7 @@
protected void runAllTasks() {
for (final Runnable r : mTasks) {
- mExecutor.execute(r);
+ r.run();
}
markCompleted();
}