use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.
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 ProtonAOSP.
the class WidgetsListContentEntryTest method unsortedWidgets_hodgepodge_shouldSortWidgetItems.
@Test
public void unsortedWidgets_hodgepodge_shouldSortWidgetItems() {
// GIVEN a list of widgets in unsorted order.
// Cat 3x3
WidgetItem widgetItem1 = createWidgetItem(mWidget1, /* spanX= */
3, /* spanY= */
3);
// Cat 1x2
WidgetItem widgetItem2 = createWidgetItem(mWidget1, /* spanX= */
1, /* spanY= */
2);
// Dog 2x2
WidgetItem widgetItem3 = createWidgetItem(mWidget2, /* spanX= */
2, /* spanY= */
2);
// Bird 2x2
WidgetItem widgetItem4 = createWidgetItem(mWidget3, /* spanX= */
2, /* spanY= */
2);
// WHEN creates a WidgetsListRowEntry with the unsorted widgets.
WidgetsListContentEntry widgetsListRowEntry = new WidgetsListContentEntry(mPackageItemInfo1, /* titleSectionName= */
"T", List.of(widgetItem1, widgetItem2, widgetItem3, widgetItem4));
// THEN the widgets list is first sorted by labels alphabetically. Then, for widgets with
// same labels, they are sorted by their gird sizes in an ascending order:
// [Bird 2x2, Cat 1x2, Cat 3x3, Dog 2x2]
assertThat(widgetsListRowEntry.mWidgets).containsExactly(widgetItem4, widgetItem2, widgetItem1, widgetItem3).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 ProtonAOSP.
the class SimpleWidgetsSearchAlgorithmTest method createWidgetsContentEntry.
private WidgetsListContentEntry createWidgetsContentEntry(String packageName, String appName, int numOfWidgets) {
List<WidgetItem> widgetItems = generateWidgetItems(packageName, numOfWidgets);
PackageItemInfo pInfo = createPackageItemInfo(packageName, appName, widgetItems.get(0).user);
return new WidgetsListContentEntry(pInfo, /* titleSectionName= */
"", widgetItems);
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.
the class WidgetsListAdapter method scrollToPositionAndMaintainOffset.
/**
* Scrolls to the selected header position with the provided offset. LinearLayoutManager
* scrolls the minimum distance necessary, so this will keep the selected header in place during
* clicks, without interrupting the animation.
*
* @param positionOptional The position too scroll to. No scrolling will be done if empty.
* @param offsetOptional The offset from the top to maintain. If empty, then the list will
* scroll to the top of the position.
*/
private void scrollToPositionAndMaintainOffset(OptionalInt positionOptional, OptionalInt offsetOptional) {
if (!positionOptional.isPresent() || mRecyclerView == null)
return;
int position = positionOptional.getAsInt();
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
if (layoutManager == null)
return;
if (position == mVisibleEntries.size() - 2 && mVisibleEntries.get(mVisibleEntries.size() - 1) instanceof WidgetsListContentEntry) {
// If the selected header is in the last position and its content is showing, then
// scroll to the final position so the last list of widgets will show.
layoutManager.scrollToPosition(mVisibleEntries.size() - 1);
return;
}
// Scroll to the header view's current offset, accounting for the recycler view's padding.
// If the header view couldn't be found, then it will appear at the top of the list.
layoutManager.scrollToPositionWithOffset(position, offsetOptional.orElse(0) - mRecyclerView.getPaddingTop());
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.
the class WidgetsListAdapter method updateVisibleEntries.
private void updateVisibleEntries() {
// Get the current top of the header with the matching key before adjusting the visible
// entries.
OptionalInt previousPositionForPackageUserKey = getPositionForPackageUserKey(mPendingClickHeader);
OptionalInt topForPackageUserKey = getOffsetForPosition(previousPositionForPackageUserKey);
List<WidgetsListBaseEntry> newVisibleEntries = mAllEntries.stream().filter(entry -> ((mFilter == null || mFilter.test(entry)) && mHeaderAndSelectedContentFilter.test(entry)) || entry instanceof WidgetListSpaceEntry).map(entry -> {
if (entry instanceof WidgetsListBaseEntry.Header<?> && matchesKey(entry, mWidgetsContentVisiblePackageUserKey)) {
// Adjust the original entries to expand headers for the selected content.
return ((WidgetsListBaseEntry.Header<?>) entry).withWidgetListShown();
} else if (entry instanceof WidgetsListContentEntry) {
// maxSpanSize.
return ((WidgetsListContentEntry) entry).withMaxSpanSize(mMaxSpanSize);
}
return entry;
}).collect(Collectors.toList());
mDiffReporter.process(mVisibleEntries, newVisibleEntries, mRowComparator);
if (mPendingClickHeader != null) {
// Get the position for the clicked header after adjusting the visible entries. The
// position may have changed if another header had previously been expanded.
OptionalInt positionForPackageUserKey = getPositionForPackageUserKey(mPendingClickHeader);
scrollToPositionAndMaintainOffset(positionForPackageUserKey, topForPackageUserKey);
mPendingClickHeader = null;
}
}
Aggregations