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

Commit 6f5d4bb8 authored by Thiru Ramasamy's avatar Thiru Ramasamy Committed by Android (Google) Code Review
Browse files

Merge "Fixes NPE with system shortcuts." into rvc-dev

parents 19797b41 43bf8838
Loading
Loading
Loading
Loading
+16 −11
Original line number Original line Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.launcher3.util.MainThreadInitializedObject;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalInt;
import java.util.stream.IntStream;
import java.util.stream.IntStream;


@@ -315,16 +314,22 @@ public class PredictionUiStateManager implements StateListener<LauncherState>,
     * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
     * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
     */
     */
    public OptionalInt getAllAppsRank(@Nullable ItemInfo itemInfo) {
    public OptionalInt getAllAppsRank(@Nullable ItemInfo itemInfo) {
        Optional<ComponentKey> componentKey = Optional.ofNullable(itemInfo)
        if (itemInfo == null || itemInfo.getTargetComponent() == null || itemInfo.user == null) {
                .filter(item -> item.itemType == ITEM_TYPE_APPLICATION
            return OptionalInt.empty();
                        || item.itemType == ITEM_TYPE_SHORTCUT
        }
                        || item.itemType == ITEM_TYPE_DEEP_SHORTCUT)

                .map(ItemInfo::getTargetComponent)
        if (itemInfo.itemType == ITEM_TYPE_APPLICATION
                .map(componentName -> new ComponentKey(componentName, itemInfo.user));
                || itemInfo.itemType == ITEM_TYPE_SHORTCUT

                || itemInfo.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
        return componentKey.map(key -> IntStream.range(0, getCurrentState().apps.size())
            ComponentKey key = new ComponentKey(itemInfo.getTargetComponent(),
                .filter(index -> key.equals(getCurrentState().apps.get(index).getComponentKey()))
                    itemInfo.user);
                .findFirst()).orElseGet(OptionalInt::empty);
            final List<ComponentKeyMapper> apps = getCurrentState().apps;
            return IntStream.range(0, apps.size())
                    .filter(index -> key.equals(apps.get(index).getComponentKey()))
                    .findFirst();
        }

        return OptionalInt.empty();
    }
    }


    /**
    /**
+6 −2
Original line number Original line Diff line number Diff line
@@ -655,11 +655,15 @@ public class HotseatPredictionController implements DragController.DragListener,
                            + ",launchLocation:" + itemInfo.container);
                            + ",launchLocation:" + itemInfo.container);
        }
        }


        final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
        if (itemInfo.getTargetComponent() == null || itemInfo.user == null) {
            return;
        }

        final ComponentKey key = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);


        final List<ComponentKeyMapper> predictedApps = new ArrayList<>(mComponentKeyMappers);
        final List<ComponentKeyMapper> predictedApps = new ArrayList<>(mComponentKeyMappers);
        OptionalInt rank = IntStream.range(0, predictedApps.size())
        OptionalInt rank = IntStream.range(0, predictedApps.size())
                .filter((i) -> k.equals(predictedApps.get(i).getComponentKey()))
                .filter(index -> key.equals(predictedApps.get(index).getComponentKey()))
                .findFirst();
                .findFirst();
        if (!rank.isPresent()) {
        if (!rank.isPresent()) {
            return;
            return;