Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51f29198 authored by Tony Wickham's avatar Tony Wickham
Browse files

Replace OnGlobalLayoutListener with StateListener to update predictions

Previously we were using OnGlobalLayoutListener, which is only called
when AllAppsContainerView or a child is re-laid out or visibility
changes to or from GONE. Since we no longer relayout when already
scrolled to the top, we need a better hook to check whether all apps has
changed visibility for the purpose of updating predictions.

Bug: 140823188
Change-Id: I7c4a0d94c529eb86b55729c75843c8b0bd673d8c
parent d81f60f3
Loading
Loading
Loading
Loading
+11 −7
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.app.prediction.AppPredictor;
import android.app.prediction.AppTarget;
import android.app.prediction.AppTarget;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;


import com.android.launcher3.AppInfo;
import com.android.launcher3.AppInfo;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
@@ -32,6 +31,8 @@ import com.android.launcher3.InvariantDeviceProfile.OnIDPChangeListener;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.Launcher;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager.StateListener;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsStore.OnUpdateListener;
import com.android.launcher3.allapps.AllAppsStore.OnUpdateListener;
@@ -58,7 +59,7 @@ import java.util.List;
 * 4) Maintains the current active client id (for the predictions) and all updates are performed on
 * 4) Maintains the current active client id (for the predictions) and all updates are performed on
 * that client id.
 * that client id.
 */
 */
public class PredictionUiStateManager implements OnGlobalLayoutListener, ItemInfoUpdateReceiver,
public class PredictionUiStateManager implements StateListener, ItemInfoUpdateReceiver,
        OnIDPChangeListener, OnUpdateListener {
        OnIDPChangeListener, OnUpdateListener {


    public static final String LAST_PREDICTION_ENABLED_STATE = "last_prediction_enabled_state";
    public static final String LAST_PREDICTION_ENABLED_STATE = "last_prediction_enabled_state";
@@ -153,7 +154,10 @@ public class PredictionUiStateManager implements OnGlobalLayoutListener, ItemInf
    public void reapplyItemInfo(ItemInfoWithIcon info) { }
    public void reapplyItemInfo(ItemInfoWithIcon info) { }


    @Override
    @Override
    public void onGlobalLayout() {
    public void onStateTransitionStart(LauncherState toState) { }

    @Override
    public void onStateTransitionComplete(LauncherState state) {
        if (mAppsView == null) {
        if (mAppsView == null) {
            return;
            return;
        }
        }
@@ -162,7 +166,8 @@ public class PredictionUiStateManager implements OnGlobalLayoutListener, ItemInf
            mPendingState = null;
            mPendingState = null;
        }
        }
        if (mPendingState == null) {
        if (mPendingState == null) {
            mAppsView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            Launcher.getLauncher(mAppsView.getContext()).getStateManager()
                    .removeStateListener(this);
        }
        }
    }
    }


@@ -170,9 +175,8 @@ public class PredictionUiStateManager implements OnGlobalLayoutListener, ItemInf
        boolean registerListener = mPendingState == null;
        boolean registerListener = mPendingState == null;
        mPendingState = state;
        mPendingState = state;
        if (registerListener) {
        if (registerListener) {
            // OnGlobalLayoutListener is called whenever a view in the view tree changes
            // Add a listener and wait until appsView is invisible again.
            // visibility. Add a listener and wait until appsView is invisible again.
            Launcher.getLauncher(mAppsView.getContext()).getStateManager().addStateListener(this);
            mAppsView.getViewTreeObserver().addOnGlobalLayoutListener(this);
        }
        }
    }
    }