use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.
the class WidgetsListContentEntryTest method equals_entriesWithDifferentMaxSpanSize_returnFalse.
@Test
public void equals_entriesWithDifferentMaxSpanSize_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(mPackageItemInfo1, /* titleSectionName= */
"T", List.of(widgetItem1), /* maxSpanSizeInCells= */
2);
assertThat(widgetsListRowEntry1.equals(widgetsListRowEntry2)).isFalse();
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_404Launcher by P-404.
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());
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_404Launcher by P-404.
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_404Launcher by P-404.
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;
}
}
use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_404Launcher by P-404.
the class SimpleWidgetsSearchAlgorithm method getFilteredWidgets.
/**
* Returns entries for all matched widgets
*/
public static ArrayList<WidgetsListBaseEntry> getFilteredWidgets(PopupDataProvider dataProvider, String input) {
ArrayList<WidgetsListBaseEntry> results = new ArrayList<>();
dataProvider.getAllWidgets().stream().filter(entry -> entry instanceof WidgetsListHeaderEntry).forEach(headerEntry -> {
List<WidgetItem> matchedWidgetItems = filterWidgetItems(input, headerEntry.mPkgItem.title.toString(), headerEntry.mWidgets);
if (matchedWidgetItems.size() > 0) {
results.add(new WidgetsListSearchHeaderEntry(headerEntry.mPkgItem, headerEntry.mTitleSectionName, matchedWidgetItems));
results.add(new WidgetsListContentEntry(headerEntry.mPkgItem, headerEntry.mTitleSectionName, matchedWidgetItems));
}
});
return results;
}
Aggregations