Moving PredictionHelper to kotlin
Bug: 390572144 Flag: EXEMPT refactor Test: atest PredictionHelperTest Change-Id: If94ae62d7e1412e6760423cf8ab43acba236c3e9
This commit is contained in:
1 parent
53cc9a7806
commit
02a41c7e5c
6 files changed
+395
-298
No files matched your search
@@ -24,20 +24,15 @@ import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APP
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.DESKTOP_ICON_FLAG;
|
||||
import static com.android.launcher3.hybridhotseat.HotseatPredictionModel.convertDataModelToAppTargetBundle;
|
||||
import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG;
|
||||
import static com.android.launcher3.model.PredictionHelper.getAppTargetFromItemInfo;
|
||||
import static com.android.launcher3.model.PredictionHelper.wrapAppTargetWithItemLocation;
|
||||
import static com.android.launcher3.model.PredictionHelper.getBundleForHotseatPredictions;
|
||||
import static com.android.launcher3.model.PredictionHelper.getBundleForWidgetPredictions;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
import static java.util.stream.Collectors.toCollection;
|
||||
|
||||
import android.app.StatsManager;
|
||||
import android.app.prediction.AppPredictionContext;
|
||||
import android.app.prediction.AppTarget;
|
||||
import android.app.prediction.AppTargetEvent;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.StatsEvent;
|
||||
@@ -66,7 +61,6 @@ import com.android.quickstep.util.ContextualSearchStateManager;
|
||||
import com.android.systemui.shared.system.SysUiStatsLog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -76,7 +70,6 @@ import javax.inject.Named;
|
||||
*/
|
||||
public class QuickstepModelDelegate extends ModelDelegate {
|
||||
|
||||
private static final String BUNDLE_KEY_ADDED_APP_WIDGETS = "added_app_widgets";
|
||||
private static final int NUM_OF_RECOMMENDED_WIDGETS_PREDICATION = 20;
|
||||
|
||||
private static final boolean IS_DEBUG = false;
|
||||
@@ -318,7 +311,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
mWidgetsRecommendationState.registerPredictor(mContext,
|
||||
new AppPredictionContext.Builder(mContext)
|
||||
.setUiSurface("widgets")
|
||||
.setExtras(getBundleForWidgetsOnWorkspace(mContext, mDataModel))
|
||||
.setExtras(getBundleForWidgetPredictions(mContext, mDataModel))
|
||||
.setPredictedTargetCount(NUM_OF_RECOMMENDED_WIDGETS_PREDICATION)
|
||||
.build(),
|
||||
mModel,
|
||||
@@ -338,7 +331,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
new AppPredictionContext.Builder(context)
|
||||
.setUiSurface("hotseat")
|
||||
.setPredictedTargetCount(mIDP.numDatabaseHotseatIcons)
|
||||
.setExtras(convertDataModelToAppTargetBundle(context, mDataModel))
|
||||
.setExtras(getBundleForHotseatPredictions(context, mDataModel))
|
||||
.build(),
|
||||
mModel, PredictionUpdateTask::new);
|
||||
}
|
||||
@@ -370,21 +363,4 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
recreateHotseatPredictor();
|
||||
}
|
||||
}
|
||||
|
||||
private Bundle getBundleForWidgetsOnWorkspace(Context context, BgDataModel dataModel) {
|
||||
Bundle bundle = new Bundle();
|
||||
ArrayList<AppTargetEvent> widgetEvents =
|
||||
dataModel.itemsIdMap.stream()
|
||||
.filter(PredictionHelper::isTrackedForWidgetPrediction)
|
||||
.map(item -> {
|
||||
AppTarget target = getAppTargetFromItemInfo(context, item);
|
||||
if (target == null) return null;
|
||||
return wrapAppTargetWithItemLocation(
|
||||
target, AppTargetEvent.ACTION_PIN, item);
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(toCollection(ArrayList::new));
|
||||
bundle.putParcelableArrayList(BUNDLE_KEY_ADDED_APP_WIDGETS, widgetEvents);
|
||||
return bundle;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user