From 6d3e5465e23ef48bdd7a572c985ada779cbb9f42 Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Wed, 19 Feb 2020 23:32:04 -0800 Subject: [PATCH] Update the suggestFolderName when items are added and deleted from folders Bug: 149935239 Bug: 149967272 Bug: 148900990 Change-Id: I0ed27236ad22579a1f3dcfd35a32252c5b1f6691 --- src/com/android/launcher3/folder/Folder.java | 31 ++++++++++++------- .../launcher3/folder/FolderNameInfo.java | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index c72509edac..f3945e2441 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -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 children = info.contents; Collections.sort(children, ITEM_POS_COMPARATOR); - updateItemLocationsInDatabaseBatch(); + updateItemLocationsInDatabaseBatch(true); DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); if (lp == null) { @@ -444,11 +445,7 @@ 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); - } + mFolderName.setHint(R.string.folder_hint_text); } // In case any children didn't come across during loading, clean up the folder accordingly mFolderIcon.post(() -> { @@ -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); diff --git a/src/com/android/launcher3/folder/FolderNameInfo.java b/src/com/android/launcher3/folder/FolderNameInfo.java index ecbe46c70a..1287219e72 100644 --- a/src/com/android/launcher3/folder/FolderNameInfo.java +++ b/src/com/android/launcher3/folder/FolderNameInfo.java @@ -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); } }