Filter shortcuts in the widget picker activity.

In its current state the WidgetPickerActivity only allows adding widget
items, so to match the state, updated it to show only widgets.

manual test - https://screen/cast/NDUxMjg1NjI0MTM0MDQxNnwxMzE4MzNhOS1mZg

Bug: 320495335
Test: atest Launcher3Tests
Flag: N/A
Change-Id: Ifa75f457219efef49e104efc428d369187db2710
This commit is contained in:
Shamali P
2024-01-16 19:22:39 +00:00
parent 4743cb3b87
commit ddde81f4c0
3 changed files with 49 additions and 14 deletions

View File

@@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
/**
* Widgets data model that is used by the adapters of the widget views and controllers.
@@ -47,6 +48,19 @@ public class WidgetsModel {
private static final ArrayList<WidgetsListBaseEntry> EMPTY_WIDGET_LIST = new ArrayList<>();
/**
* Returns a list of {@link WidgetsListBaseEntry} filtered using given widget item filter. All
* {@link WidgetItem}s in a single row are sorted (based on label and user), but the overall
* list of {@link WidgetsListBaseEntry}s is not sorted.
*
* @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
*/
public synchronized ArrayList<WidgetsListBaseEntry> getFilteredWidgetsListForPicker(
Context context,
Predicate<WidgetItem> widgetItemFilter) {
return EMPTY_WIDGET_LIST;
}
/**
* Returns a list of {@link WidgetsListBaseEntry}. All {@link WidgetItem} in a single row are
* sorted (based on label and user), but the overall list of {@link WidgetsListBaseEntry}s is
@@ -88,4 +102,4 @@ public class WidgetsModel {
Context context, ComponentName provider, UserHandle userHandle) {
return new PackageItemInfo(provider.getPackageName(), userHandle);
}
}
}

View File

@@ -158,7 +158,10 @@ public class WidgetPickerActivity extends BaseActivity {
LauncherAppState app = LauncherAppState.getInstance(this);
mModel.update(app, null);
final ArrayList<WidgetsListBaseEntry> widgets =
mModel.getWidgetsListForPicker(app.getContext());
mModel.getFilteredWidgetsListForPicker(
app.getContext(),
/*widgetItemFilter=*/ item -> item.widgetInfo != null
);
MAIN_EXECUTOR.execute(() -> mPopupDataProvider.setAllWidgets(widgets));
});
}

View File

@@ -69,6 +69,34 @@ public class WidgetsModel {
/* Map of widgets and shortcuts that are tracked per package. */
private final Map<PackageItemInfo, List<WidgetItem>> mWidgetsList = new HashMap<>();
/**
* Returns a list of {@link WidgetsListBaseEntry} filtered using given widget item filter. All
* {@link WidgetItem}s in a single row are sorted (based on label and user), but the overall
* list of {@link WidgetsListBaseEntry}s is not sorted.
*
* @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
*/
public synchronized ArrayList<WidgetsListBaseEntry> getFilteredWidgetsListForPicker(
Context context,
Predicate<WidgetItem> widgetItemFilter) {
ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
AlphabeticIndexCompat indexer = new AlphabeticIndexCompat(context);
for (Map.Entry<PackageItemInfo, List<WidgetItem>> entry : mWidgetsList.entrySet()) {
PackageItemInfo pkgItem = entry.getKey();
List<WidgetItem> widgetItems = entry.getValue()
.stream()
.filter(widgetItemFilter).toList();
if (!widgetItems.isEmpty()) {
String sectionName = (pkgItem.title == null) ? "" :
indexer.computeSectionName(pkgItem.title);
result.add(WidgetsListHeaderEntry.create(pkgItem, sectionName, widgetItems));
result.add(new WidgetsListContentEntry(pkgItem, sectionName, widgetItems));
}
}
return result;
}
/**
* Returns a list of {@link WidgetsListBaseEntry}. All {@link WidgetItem} in a single row
* are sorted (based on label and user), but the overall list of
@@ -77,18 +105,8 @@ public class WidgetsModel {
* @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
*/
public synchronized ArrayList<WidgetsListBaseEntry> getWidgetsListForPicker(Context context) {
ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
AlphabeticIndexCompat indexer = new AlphabeticIndexCompat(context);
for (Map.Entry<PackageItemInfo, List<WidgetItem>> entry : mWidgetsList.entrySet()) {
PackageItemInfo pkgItem = entry.getKey();
List<WidgetItem> widgetItems = entry.getValue();
String sectionName = (pkgItem.title == null) ? "" :
indexer.computeSectionName(pkgItem.title);
result.add(WidgetsListHeaderEntry.create(pkgItem, sectionName, widgetItems));
result.add(new WidgetsListContentEntry(pkgItem, sectionName, widgetItems));
}
return result;
// return all items
return getFilteredWidgetsListForPicker(context, /*widgetItemFilter=*/ item -> true);
}
/** Returns a mapping of packages to their widgets without static shortcuts. */