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

Commit 6d3e5465 authored by Hyunyoung Song's avatar Hyunyoung Song
Browse files

Update the suggestFolderName when items are added and deleted from folders

Bug: 149935239
Bug: 149967272
Bug: 148900990

Change-Id: I0ed27236ad22579a1f3dcfd35a32252c5b1f6691
parent 1562d104
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ import com.android.launcher3.userevent.LauncherLogProto.ItemType;
import com.android.launcher3.userevent.LauncherLogProto.LauncherEvent;
import com.android.launcher3.userevent.LauncherLogProto.Target;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.views.ClipPathView;
import com.android.launcher3.widget.PendingAddShortcutInfo;
@@ -426,7 +427,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
        mInfo = info;
        ArrayList<WorkspaceItemInfo> children = info.contents;
        Collections.sort(children, ITEM_POS_COMPARATOR);
        updateItemLocationsInDatabaseBatch();
        updateItemLocationsInDatabaseBatch(true);

        DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
        if (lp == null) {
@@ -444,12 +445,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
            mFolderName.setHint(null);
        } else {
            mFolderName.setText("");
            if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
                mFolderName.setHint("");
            } else {
            mFolderName.setHint(R.string.folder_hint_text);
        }
        }
        // In case any children didn't come across during loading, clean up the folder accordingly
        mFolderIcon.post(() -> {
            if (getItemCount() <= 1) {
@@ -464,8 +461,6 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
     */
    public void showSuggestedTitle(FolderNameInfo[] nameInfos) {
        if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
            mInfo.suggestedFolderNames = new Intent().putExtra(FolderInfo.EXTRA_FOLDER_SUGGESTIONS,
                    nameInfos);
            if (isEmpty(mFolderName.getText().toString())
                    && !mInfo.hasOption(FLAG_MANUAL_FOLDER_NAME)) {
                showLabelSuggestion(nameInfos, true);
@@ -985,7 +980,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo

        // Reordering may have occured, and we need to save the new item locations. We do this once
        // at the end to prevent unnecessary database operations.
        updateItemLocationsInDatabaseBatch();
        updateItemLocationsInDatabaseBatch(false);
        // Use the item count to check for multi-page as the folder UI may not have
        // been refreshed yet.
        if (getItemCount() <= mContent.itemsPerPage()) {
@@ -995,7 +990,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
        }
    }

    private void updateItemLocationsInDatabaseBatch() {
    private void updateItemLocationsInDatabaseBatch(boolean isBind) {
        FolderGridOrganizer verifier = new FolderGridOrganizer(
                mLauncher.getDeviceProfile().inv).setFolderInfo(mInfo);

@@ -1011,6 +1006,18 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
        if (!items.isEmpty()) {
            mLauncher.getModelWriter().moveItemsInDatabase(items, mInfo.id, 0);
        }
        if (FeatureFlags.FOLDER_NAME_SUGGEST.get() && !isBind) {
            Executors.MODEL_EXECUTOR.post(() -> {
                FolderNameInfo[] nameInfos =
                        new FolderNameInfo[FolderNameProvider.SUGGEST_MAX];
                FolderNameProvider fnp = FolderNameProvider.newInstance(getContext());
                fnp.getSuggestedFolderName(
                        getContext(), mInfo.contents, nameInfos);
                mInfo.suggestedFolderNames = new Intent().putExtra(
                        FolderInfo.EXTRA_FOLDER_SUGGESTIONS,
                        nameInfos);
            });
        }
    }

    public void notifyDrop() {
@@ -1315,7 +1322,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
            // We only need to update the locations if it doesn't get handled in
            // #onDropCompleted.
            if (d.dragSource != this) {
                updateItemLocationsInDatabaseBatch();
                updateItemLocationsInDatabaseBatch(false);
            }
        }

@@ -1356,7 +1363,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
        verifier.updateRankAndPos(item, rank);
        mLauncher.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0, item.cellX,
                item.cellY);
        updateItemLocationsInDatabaseBatch();
        updateItemLocationsInDatabaseBatch(false);

        if (mContent.areViewsBound()) {
            mContent.createAndAddViewForRank(item, rank);
+1 −1
Original line number Diff line number Diff line
@@ -84,6 +84,6 @@ public final class FolderNameInfo implements Parcelable {
    @Override
    @NonNull
    public String toString() {
        return mLabel.toString() + ":" + mScore;
        return String.format("%s:%.2f", mLabel, mScore);
    }
}