use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsDiffReporter method process.
/**
* Notifies the difference between {@code currentEntries} & {@code newEntries} by calling the
* relevant {@link androidx.recyclerview.widget.RecyclerView.RecyclerViewDataObserver} methods.
*/
public void process(ArrayList<WidgetsListBaseEntry> currentEntries, List<WidgetsListBaseEntry> newEntries, WidgetListBaseRowEntryComparator comparator) {
if (DEBUG) {
Log.d(TAG, "process oldEntries#=" + currentEntries.size() + " newEntries#=" + newEntries.size());
}
// Early exit if either of the list is empty
if (currentEntries.isEmpty() || newEntries.isEmpty()) {
// when the bind actually completes.
if (currentEntries.size() != newEntries.size()) {
currentEntries.clear();
currentEntries.addAll(newEntries);
mListener.notifyDataSetChanged();
}
return;
}
ArrayList<WidgetsListBaseEntry> orgEntries = (ArrayList<WidgetsListBaseEntry>) currentEntries.clone();
Iterator<WidgetsListBaseEntry> orgIter = orgEntries.iterator();
Iterator<WidgetsListBaseEntry> newIter = newEntries.iterator();
WidgetsListBaseEntry orgRowEntry = orgIter.next();
WidgetsListBaseEntry newRowEntry = newIter.next();
do {
int diff = compareAppNameAndType(orgRowEntry, newRowEntry, comparator);
if (DEBUG) {
Log.d(TAG, String.format("diff=%d orgRowEntry (%s) newRowEntry (%s)", diff, orgRowEntry != null ? orgRowEntry.toString() : null, newRowEntry != null ? newRowEntry.toString() : null));
}
int index = -1;
if (diff < 0) {
index = currentEntries.indexOf(orgRowEntry);
mListener.notifyItemRemoved(index);
if (DEBUG) {
Log.d(TAG, String.format("notifyItemRemoved called (%d)%s", index, orgRowEntry.mTitleSectionName));
}
currentEntries.remove(index);
orgRowEntry = orgIter.hasNext() ? orgIter.next() : null;
} else if (diff > 0) {
index = orgRowEntry != null ? currentEntries.indexOf(orgRowEntry) : currentEntries.size();
currentEntries.add(index, newRowEntry);
if (DEBUG) {
Log.d(TAG, String.format("notifyItemInserted called (%d)%s", index, newRowEntry.mTitleSectionName));
}
newRowEntry = newIter.hasNext() ? newIter.next() : null;
mListener.notifyItemInserted(index);
} else {
// or did the widget size and desc, span, etc change?
if (!isSamePackageItemInfo(orgRowEntry.mPkgItem, newRowEntry.mPkgItem) || hasHeaderUpdated(orgRowEntry, newRowEntry) || hasWidgetsListContentChanged(orgRowEntry, newRowEntry)) {
index = currentEntries.indexOf(orgRowEntry);
currentEntries.set(index, newRowEntry);
mListener.notifyItemChanged(index);
if (DEBUG) {
Log.d(TAG, String.format("notifyItemChanged called (%d)%s", index, newRowEntry.mTitleSectionName));
}
}
orgRowEntry = orgIter.hasNext() ? orgIter.next() : null;
newRowEntry = newIter.hasNext() ? newIter.next() : null;
}
} while (orgRowEntry != null || newRowEntry != null);
}
use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsListAdapter method ensureAllPreviewsReady.
/**
* Checks that all preview images are loaded and starts loading for those that aren't ready.
*
* @return true if all previews are ready and the data can be updated, false otherwise.
*/
private boolean ensureAllPreviewsReady() {
boolean allReady = true;
BaseActivity activity = BaseActivity.fromContext(mContext);
for (WidgetsListBaseEntry entry : mAllEntries) {
if (!(entry instanceof WidgetsListContentEntry))
continue;
WidgetsListContentEntry contentEntry = (WidgetsListContentEntry) entry;
if (!matchesKey(entry, mWidgetsContentVisiblePackageUserKey)) {
// If the entry isn't visible, clear any loaded previews.
mCachingPreviewLoader.clearPreviews(contentEntry.mWidgets);
continue;
}
for (int i = 0; i < entry.mWidgets.size(); i++) {
WidgetItem widgetItem = entry.mWidgets.get(i);
DeviceProfile deviceProfile = activity.getDeviceProfile();
Size widgetSize = WidgetSizes.getWidgetItemSizePx(mContext, deviceProfile, widgetItem);
if (widgetItem.isShortcut()) {
widgetSize = new Size(widgetSize.getWidth() + mShortcutPreviewPadding, widgetSize.getHeight() + mShortcutPreviewPadding);
}
if (widgetItem.hasPreviewLayout() || mCachingPreviewLoader.isPreviewLoaded(widgetItem, widgetSize)) {
// preview bitmap is in the cache.
continue;
}
// If we've reached this point, we should load the preview for the widget.
allReady = false;
mCachingPreviewLoader.loadPreview(activity, widgetItem, widgetSize, mPreviewLoadedCallback);
}
}
return allReady;
}
use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsListAdapter method updateVisibleEntries.
private void updateVisibleEntries() {
// loads.
if (!ensureAllPreviewsReady())
return;
// 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)).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.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsListAdapter method shouldClearVisibleEntries.
/**
* Returns {@code true} if there is a change in {@link #mAllEntries} that results in an
* invalidation of {@link #mVisibleEntries}. e.g. there is change in the device language.
*/
private boolean shouldClearVisibleEntries() {
Map<PackageUserKey, PackageItemInfo> packagesInfo = mAllEntries.stream().filter(entry -> entry instanceof WidgetsListHeaderEntry).map(entry -> entry.mPkgItem).collect(Collectors.toMap(entry -> new PackageUserKey(entry.packageName, entry.user), entry -> entry));
for (WidgetsListBaseEntry visibleEntry : mVisibleEntries) {
PackageUserKey key = new PackageUserKey(visibleEntry.mPkgItem.packageName, visibleEntry.mPkgItem.user);
PackageItemInfo packageItemInfo = packagesInfo.get(key);
if (packageItemInfo != null && !visibleEntry.mPkgItem.title.equals(packageItemInfo.title)) {
return true;
}
}
return false;
}
use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int pos) {
ViewHolderBinder viewHolderBinder = mViewHolderBinders.get(getItemViewType(pos));
WidgetsListBaseEntry entry = mVisibleEntries.get(pos);
viewHolderBinder.bindViewHolder(holder, mVisibleEntries.get(pos), pos);
holder.itemView.setTag(R.id.tag_widget_entry, entry);
}
Aggregations