Refactor FolderNameInfos.

Bug: 159508969

Change-Id: I984e7a4fc321392d06157c705392c1ba5672f348
This commit is contained in:
Jayaprakash Sundararaj committed 2020-06-19 23:12:22 -07:00
1 parent 9024c85742
commit 1d96ba03ab
8 files changed
+185 -209

No files matched your search

+11 -29
View File
@@ -28,16 +28,12 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED;
import static com.android.launcher3.model.data.FolderInfo.FLAG_MANUAL_FOLDER_NAME;
import static java.util.Arrays.asList;
import static java.util.Optional.ofNullable;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.annotation.SuppressLint;
import android.appwidget.AppWidgetHostView;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
@@ -104,6 +100,7 @@ import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Represents a set of icons chosen by the user or generated by the system.
@@ -327,11 +324,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
public void startEditingFolderName() {
post(() -> {
if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
ofNullable(mInfo)
.map(info -> info.suggestedFolderNames)
.map(folderNames -> (FolderNameInfo[]) folderNames
.getParcelableArrayExtra(FolderInfo.EXTRA_FOLDER_SUGGESTIONS))
.ifPresent(this::showLabelSuggestions);
showLabelSuggestions();
}
mFolderName.setHint("");
mIsEditingName = true;
@@ -461,32 +454,24 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
* Show suggested folder title in FolderEditText if the first suggestion is non-empty, push
* rest of the suggestions to InputMethodManager.
*/
private void showLabelSuggestions(FolderNameInfo[] nameInfos) {
if (nameInfos == null) {
private void showLabelSuggestions() {
if (mInfo.suggestedFolderNames == null) {
return;
}
// Open the Folder and Keyboard when the first or second suggestion is valid non-empty
// string.
boolean shouldOpen = nameInfos.length > 0 && nameInfos[0] != null && !isEmpty(
nameInfos[0].getLabel())
|| nameInfos.length > 1 && nameInfos[1] != null && !isEmpty(
nameInfos[1].getLabel());
if (shouldOpen) {
if (mInfo.suggestedFolderNames.hasSuggestions()) {
// update the primary suggestion if the folder name is empty.
if (isEmpty(mFolderName.getText())) {
CharSequence firstLabel = nameInfos[0] == null ? "" : nameInfos[0].getLabel();
if (!isEmpty(firstLabel)) {
if (mInfo.suggestedFolderNames.hasPrimary()) {
mFolderName.setHint("");
mFolderName.setText(firstLabel);
mFolderName.setText(mInfo.suggestedFolderNames.getLabels()[0]);
mFolderName.selectAll();
}
}
mFolderName.showKeyboard();
mFolderName.displayCompletions(
asList(nameInfos).subList(0, nameInfos.length).stream()
Stream.of(mInfo.suggestedFolderNames.getLabels())
.filter(Objects::nonNull)
.map(s -> s.getLabel().toString())
.map(Object::toString)
.filter(s -> !s.isEmpty())
.filter(s -> !s.equalsIgnoreCase(mFolderName.getText().toString()))
.collect(Collectors.toList()));
@@ -1021,14 +1006,11 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (FeatureFlags.FOLDER_NAME_SUGGEST.get() && !isBind
&& total > 1 /* no need to update if there's one icon */) {
Executors.MODEL_EXECUTOR.post(() -> {
FolderNameInfo[] nameInfos =
new FolderNameInfo[FolderNameProvider.SUGGEST_MAX];
FolderNameInfos nameInfos = new FolderNameInfos();
FolderNameProvider fnp = FolderNameProvider.newInstance(getContext());
fnp.getSuggestedFolderName(
getContext(), mInfo.contents, nameInfos);
mInfo.suggestedFolderNames = new Intent().putExtra(
FolderInfo.EXTRA_FOLDER_SUGGESTIONS,
nameInfos);
mInfo.suggestedFolderNames = nameInfos;
});
}
}