diff options
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index eef3980f96..545f4c3999 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -72,6 +72,7 @@ import java.util.HashSet; import java.util.List; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; +import java.util.function.Consumer; import java.util.function.Supplier; /** @@ -376,7 +377,13 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi loaderResults.bindWidgets(); return true; } else { - startLoaderForResults(loaderResults); + stopLoader(); + mLoaderTask = new LoaderTask( + mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, loaderResults); + + // Always post the loader task, instead of running directly + // (even on same thread) so that we exit any nested synchronized blocks + MODEL_EXECUTOR.post(mLoaderTask); } } } @@ -399,25 +406,17 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi } } - public void startLoaderForResults(LoaderResults results) { - synchronized (mLock) { - stopLoader(); - mLoaderTask = new LoaderTask( - mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, results); - - // Always post the loader task, instead of running directly (even on same thread) so - // that we exit any nested synchronized blocks - MODEL_EXECUTOR.post(mLoaderTask); - } - } - - public void startLoaderForResultsIfNotLoaded(LoaderResults results) { + /** + * Loads the model if not loaded + * @param callback called with the data model upon successful load or null on model thread. + */ + public void loadAsync(Consumer<BgDataModel> callback) { synchronized (mLock) { - if (!isModelLoaded()) { - Log.d(TAG, "Workspace not loaded, loading now"); - startLoaderForResults(results); + if (!mModelLoaded && !mIsLoaderTaskRunning) { + startLoader(); } } + MODEL_EXECUTOR.post(() -> callback.accept(isModelLoaded() ? mBgDataModel : null)); } @Override |