diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index 368a37384d..e34d4c85ae 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -31,6 +31,7 @@ import androidx.recyclerview.widget.RecyclerView.Adapter; import com.android.launcher3.util.ScrollableLayoutManager; import com.android.launcher3.views.ActivityContext; +import java.util.ArrayList; import java.util.List; /** @@ -43,6 +44,31 @@ public class AllAppsGridAdapter extends public static final String TAG = "AppsGridAdapter"; private final AppsGridLayoutManager mGridLayoutMgr; + private final List mOnLayoutCompletedListeners = new ArrayList<>(); + + /** + * Listener for {@link RecyclerView.LayoutManager#onLayoutCompleted(RecyclerView.State)} + */ + public interface OnLayoutCompletedListener { + void onLayoutCompleted(); + } + + /** + * Adds a {@link OnLayoutCompletedListener} to receive a callback when {@link + * RecyclerView.LayoutManager#onLayoutCompleted(RecyclerView.State)} is called + */ + public void addOnLayoutCompletedListener(OnLayoutCompletedListener listener) { + mOnLayoutCompletedListeners.add(listener); + } + + /** + * Removes a {@link OnLayoutCompletedListener} to not receive a callback when {@link + * RecyclerView.LayoutManager#onLayoutCompleted(RecyclerView.State)} is called + */ + public void removeOnLayoutCompletedListener(OnLayoutCompletedListener listener) { + mOnLayoutCompletedListeners.remove(listener); + } + public AllAppsGridAdapter(T activityContext, LayoutInflater inflater, AlphabeticalAppsList apps, BaseAdapterProvider[] adapterProviders) { @@ -132,6 +158,14 @@ public class AllAppsGridAdapter extends return extraRows; } + @Override + public void onLayoutCompleted(RecyclerView.State state) { + super.onLayoutCompleted(state); + for (OnLayoutCompletedListener listener : mOnLayoutCompletedListeners) { + listener.onLayoutCompleted(); + } + } + @Override protected int incrementTotalHeight(Adapter adapter, int position, int heightUntilLastPos) { AllAppsGridAdapter.AdapterItem item = mApps.getAdapterItems().get(position);