mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-16 17:18:21 +00:00
Recreate hotseat predictor whenever we query it due to workspace change
Fix: b/289013842 Test: unit test, also verified moving icons will recreate hotseat predictor Change-Id: I1f19b17654b87156132a4e4dee26e12312589dba
This commit is contained in:
@@ -52,6 +52,7 @@ import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
@@ -93,11 +94,14 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
private static final boolean IS_DEBUG = false;
|
||||
private static final String TAG = "QuickstepModelDelegate";
|
||||
|
||||
private final PredictorState mAllAppsState =
|
||||
@VisibleForTesting
|
||||
final PredictorState mAllAppsState =
|
||||
new PredictorState(CONTAINER_PREDICTION, "all_apps_predictions");
|
||||
private final PredictorState mHotseatState =
|
||||
@VisibleForTesting
|
||||
final PredictorState mHotseatState =
|
||||
new PredictorState(CONTAINER_HOTSEAT_PREDICTION, "hotseat_predictions");
|
||||
private final PredictorState mWidgetsRecommendationState =
|
||||
@VisibleForTesting
|
||||
final PredictorState mWidgetsRecommendationState =
|
||||
new PredictorState(CONTAINER_WIDGETS_PREDICTION, "widgets_prediction");
|
||||
|
||||
private final InvariantDeviceProfile mIDP;
|
||||
@@ -348,12 +352,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
.build()));
|
||||
|
||||
// TODO: get bundle
|
||||
registerPredictor(mHotseatState, apm.createAppPredictionSession(
|
||||
new AppPredictionContext.Builder(context)
|
||||
.setUiSurface("hotseat")
|
||||
.setPredictedTargetCount(mIDP.numDatabaseHotseatIcons)
|
||||
.setExtras(convertDataModelToAppTargetBundle(context, mDataModel))
|
||||
.build()));
|
||||
registerHotseatPredictor(apm, context);
|
||||
|
||||
registerWidgetsPredictor(apm.createAppPredictionSession(
|
||||
new AppPredictionContext.Builder(context)
|
||||
@@ -363,6 +362,29 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
.build()));
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private void recreateHotseatPredictor() {
|
||||
mHotseatState.destroyPredictor();
|
||||
if (!mActive) {
|
||||
return;
|
||||
}
|
||||
Context context = mApp.getContext();
|
||||
AppPredictionManager apm = context.getSystemService(AppPredictionManager.class);
|
||||
if (apm == null) {
|
||||
return;
|
||||
}
|
||||
registerHotseatPredictor(apm, context);
|
||||
}
|
||||
|
||||
private void registerHotseatPredictor(AppPredictionManager apm, Context context) {
|
||||
registerPredictor(mHotseatState, apm.createAppPredictionSession(
|
||||
new AppPredictionContext.Builder(context)
|
||||
.setUiSurface("hotseat")
|
||||
.setPredictedTargetCount(mIDP.numDatabaseHotseatIcons)
|
||||
.setExtras(convertDataModelToAppTargetBundle(context, mDataModel))
|
||||
.build()));
|
||||
}
|
||||
|
||||
private void registerPredictor(PredictorState state, AppPredictor predictor) {
|
||||
state.setTargets(Collections.emptyList());
|
||||
state.predictor = predictor;
|
||||
@@ -393,7 +415,8 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
mWidgetsRecommendationState.predictor.requestPredictionUpdate();
|
||||
}
|
||||
|
||||
private void onAppTargetEvent(AppTargetEvent event, int client) {
|
||||
@VisibleForTesting
|
||||
void onAppTargetEvent(AppTargetEvent event, int client) {
|
||||
PredictorState state;
|
||||
switch(client) {
|
||||
case CONTAINER_PREDICTION:
|
||||
@@ -411,6 +434,13 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
state.predictor.notifyAppTargetEvent(event);
|
||||
Log.d(TAG, "notifyAppTargetEvent action=" + event.getAction()
|
||||
+ " launchLocation=" + event.getLaunchLocation());
|
||||
if (state == mHotseatState
|
||||
&& (event.getAction() == AppTargetEvent.ACTION_PIN
|
||||
|| event.getAction() == AppTargetEvent.ACTION_UNPIN)) {
|
||||
// Recreate hot seat predictor when we need to query for hot seat due to pin or
|
||||
// unpin app icons.
|
||||
recreateHotseatPredictor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user