use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ArrowOS.
the class WidgetsListContentEntryTest method unsortedWidgets_diffLabels_shouldSortWidgetItems.
@Test
public void unsortedWidgets_diffLabels_shouldSortWidgetItems() {
// GIVEN a list of widgets in unsorted order.
// Cat 2x3
WidgetItem widgetItem1 = createWidgetItem(mWidget1, /* spanX= */
2, /* spanY= */
3);
// Dog 2x3
WidgetItem widgetItem2 = createWidgetItem(mWidget2, /* spanX= */
2, /* spanY= */
3);
// Bird 2x3
WidgetItem widgetItem3 = createWidgetItem(mWidget3, /* spanX= */
2, /* spanY= */
3);
// WHEN creates a WidgetsListRowEntry with the unsorted widgets.
WidgetsListContentEntry widgetsListRowEntry = new WidgetsListContentEntry(mPackageItemInfo1, /* titleSectionName= */
"T", List.of(widgetItem1, widgetItem2, widgetItem3));
// THEN the widgets list is sorted by their labels alphabetically: [Bird, Cat, Dog].
assertThat(widgetsListRowEntry.mWidgets).containsExactly(widgetItem3, widgetItem1, widgetItem2).inOrder();
assertThat(widgetsListRowEntry.mTitleSectionName).isEqualTo("T");
assertThat(widgetsListRowEntry.mPkgItem).isEqualTo(mPackageItemInfo1);
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ArrowOS.
the class WidgetsListContentEntryTest method equals_entriesWithDifferentPackageItemInfo_returnFalse.
@Test
public void equals_entriesWithDifferentPackageItemInfo_returnFalse() {
WidgetItem widgetItem1 = createWidgetItem(mWidget1, /* spanX= */
2, /* spanY= */
3);
WidgetsListContentEntry widgetsListRowEntry1 = new WidgetsListContentEntry(mPackageItemInfo1, /* titleSectionName= */
"T", List.of(widgetItem1), /* maxSpanSizeInCells= */
3);
WidgetsListContentEntry widgetsListRowEntry2 = new WidgetsListContentEntry(mPackageItemInfo2, /* titleSectionName= */
"T", List.of(widgetItem1), /* maxSpanSizeInCells= */
3);
assertThat(widgetsListRowEntry1.equals(widgetsListRowEntry2)).isFalse();
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ArrowOS.
the class WidgetsListTableViewHolderBinderTest method bindViewHolder_appWith3Widgets_shouldHave3Widgets.
@Test
public void bindViewHolder_appWith3Widgets_shouldHave3Widgets() throws Exception {
WidgetsRowViewHolder viewHolder = mViewHolderBinder.newViewHolder(new FrameLayout(mContext));
WidgetsListContentEntry entry = generateSampleAppWithWidgets(APP_NAME, TEST_PACKAGE, /* numOfWidgets= */
3);
mViewHolderBinder.bindViewHolder(viewHolder, entry, /* position= */
0, EMPTY_LIST);
Executors.MAIN_EXECUTOR.submit(() -> {
}).get();
// THEN the table container has one row, which contains 3 widgets.
// View: .SampleWidget0 | .SampleWidget1 | .SampleWidget2
assertThat(viewHolder.tableContainer.getChildCount()).isEqualTo(1);
TableRow row = (TableRow) viewHolder.tableContainer.getChildAt(0);
assertThat(row.getChildCount()).isEqualTo(3);
// Widget 0 label is .SampleWidget0.
assertWidgetCellWithLabel(row.getChildAt(0), ".SampleWidget0");
// Widget 1 label is .SampleWidget1.
assertWidgetCellWithLabel(row.getChildAt(1), ".SampleWidget1");
// Widget 2 label is .SampleWidget2.
assertWidgetCellWithLabel(row.getChildAt(2), ".SampleWidget2");
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ArrowOS.
the class WidgetsDiffReporterTest method headersContentsMix_contentMaxSpanSizeModified_shouldInvokeCorrectCallbacks.
@Test
public void headersContentsMix_contentMaxSpanSizeModified_shouldInvokeCorrectCallbacks() {
// GIVEN the current list has app headers [A, B, E content].
ArrayList<WidgetsListBaseEntry> currentList = new ArrayList<>(List.of(mHeaderA, mHeaderB, mContentE));
// GIVEN the new list has max span size in "E content" modified.
List<WidgetsListBaseEntry> newList = List.of(mHeaderA, mHeaderB, new WidgetsListContentEntry(mContentE.mPkgItem, mContentE.mTitleSectionName, mContentE.mWidgets, mContentE.getMaxSpanSizeInCells() + 1));
// WHEN computing the list difference.
mWidgetsDiffReporter.process(currentList, newList, COMPARATOR);
// THEN notify "E content" has been changed.
verify(mAdapter).notifyItemChanged(/* position= */
2);
// THEN the current list contains all elements from the new list.
assertThat(currentList).containsExactlyElementsIn(newList);
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.
the class PopupDataProvider method getRecommendedWidgets.
/**
* Returns a list of recommended widgets.
*/
public List<WidgetItem> getRecommendedWidgets() {
HashMap<ComponentKey, WidgetItem> allWidgetItems = new HashMap<>();
mAllWidgets.stream().filter(entry -> entry instanceof WidgetsListContentEntry).forEach(entry -> ((WidgetsListContentEntry) entry).mWidgets.forEach(widget -> allWidgetItems.put(new ComponentKey(widget.componentName, widget.user), widget)));
return mRecommendedWidgets.stream().map(recommendedWidget -> allWidgetItems.get(new ComponentKey(recommendedWidget.getTargetComponent(), recommendedWidget.user))).filter(Objects::nonNull).collect(Collectors.toList());
}
Aggregations