eu.davidea.viewholders.FlexibleViewHolder Java Examples
The following examples show how to use
eu.davidea.viewholders.FlexibleViewHolder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StickyHeaderHelper.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
private void resetHeader(FlexibleViewHolder header) { restoreHeaderItemVisibility(); // Clean the header container final View view = header.getContentView(); removeViewFromParent(view); // Reset translation on removed header view.setTranslationX(0); view.setTranslationY(0); if (!header.itemView.equals(view)) { addViewToParent(((ViewGroup) header.itemView), view); } header.setIsRecyclable(true); // #294 - Expandable header is not resized / redrawn on automatic configuration change when sticky headers are enabled header.itemView.getLayoutParams().width = view.getLayoutParams().width; header.itemView.getLayoutParams().height = view.getLayoutParams().height; }
Example #2
Source File: SelectableAdapter.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
@Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List payloads) { // Bind the correct view elevation if (holder instanceof FlexibleViewHolder) { FlexibleViewHolder flexHolder = (FlexibleViewHolder) holder; flexHolder.getContentView().setActivated(isSelected(position)); if (flexHolder.getContentView().isActivated() && flexHolder.getActivationElevation() > 0) { ViewCompat.setElevation(flexHolder.getContentView(), flexHolder.getActivationElevation()); } else if (flexHolder.getActivationElevation() > 0) { // Leave unaltered the default elevation ViewCompat.setElevation(flexHolder.getContentView(), 0); } if (flexHolder.isRecyclable()) { mBoundViewHolders.add(flexHolder); log.v("onViewBound viewSize=%s %s %s", mBoundViewHolders.size(), getClassName(holder), holder); } else { log.v("onViewBound recyclable=%s %s %s", holder.isRecyclable(), getClassName(holder), holder); } } else { // When user scrolls, this line binds the correct selection status holder.itemView.setActivated(isSelected(position)); } }
Example #3
Source File: StickyHeaderHelper.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
private void updateHeader(int headerPosition, boolean updateHeaderContent) { // Check if there is a new header to be sticky if (mHeaderPosition != headerPosition && mStickyHolderLayout != null) { // #244 - Don't animate if header is already visible at the first layout position int firstVisibleItemPosition = mAdapter.getFlexibleLayoutManager().findFirstVisibleItemPosition(); // Animate if headers were hidden, but don't if configuration changed (rotation) if (displayWithAnimation && mHeaderPosition == RecyclerView.NO_POSITION && headerPosition != firstVisibleItemPosition) { displayWithAnimation = false; mStickyHolderLayout.setAlpha(0); mStickyHolderLayout.animate().alpha(1).start(); } else { mStickyHolderLayout.setAlpha(1); } int oldHeaderPosition = mHeaderPosition; mHeaderPosition = headerPosition; FlexibleViewHolder holder = getHeaderViewHolder(headerPosition); // Swapping header swapHeader(holder, oldHeaderPosition); } else if (updateHeaderContent) { // #299 - ClassCastException after click on expanded sticky header when auto-collapse is enabled. // #594 - Checking same item view type and increased delay to 100ms. if (mStickyHeaderViewHolder.getItemViewType() == mAdapter.getItemViewType(headerPosition)) { mAdapter.onBindViewHolder(mStickyHeaderViewHolder, headerPosition); } else { Log.e("updateHeader Wrong itemViewType for StickyViewHolder=%s, PositionViewHolder=%s", getClassName(mStickyHeaderViewHolder), getClassName(getHeaderViewHolder(headerPosition))); } ensureHeaderParent(); } translateHeader(); }
Example #4
Source File: StickyHeaderHelper.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
private void swapHeader(FlexibleViewHolder newHeader, int oldHeaderPosition) { Log.d("swapHeader newHeaderPosition=%s", mHeaderPosition); if (mStickyHeaderViewHolder != null) { resetHeader(mStickyHeaderViewHolder); // #568, #575 - Header ViewHolder out of the top screen must be recycled manually if (mHeaderPosition > oldHeaderPosition) { mAdapter.onViewRecycled(mStickyHeaderViewHolder); } } mStickyHeaderViewHolder = newHeader; mStickyHeaderViewHolder.setIsRecyclable(false); ensureHeaderParent(); onStickyHeaderChange(mHeaderPosition, oldHeaderPosition); }
Example #5
Source File: SelectableAdapter.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
private void notifySelectionChanged(int positionStart, int itemCount) { if (itemCount > 0) { // Avoid to rebind the VH, direct call to the itemView activation for (FlexibleViewHolder flexHolder : mBoundViewHolders) { flexHolder.toggleActivation(); } // Use classic notification, in case FlexibleViewHolder is not implemented if (mBoundViewHolders.isEmpty()) { notifyItemRangeChanged(positionStart, itemCount, Payload.SELECTION); } } }
Example #6
Source File: SelectableAdapter.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof FlexibleViewHolder) { boolean recycled = mBoundViewHolders.remove(holder); log.v("onViewRecycled viewSize=%s %s %s recycled=%s", mBoundViewHolders.size(), getClassName(holder), holder, recycled); } }
Example #7
Source File: ItemComparatorTest.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@Override public FlexibleViewHolder createViewHolder(View view, FlexibleAdapter adapter) { return null; }
Example #8
Source File: ItemComparatorTest.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@Override public FlexibleViewHolder createViewHolder(View view, FlexibleAdapter adapter) { return null; }
Example #9
Source File: AnimatorAdapter.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
/** * Performs checks to scroll animate the itemView and in case, it animates the view. * <p><b>Note:</b> If you have to change at runtime the LayoutManager <i>and</i> add * Scrollable Headers too, consider to add them in post, using a {@code delay >= 0}, * otherwise scroll animations on all items will not start correctly.</p> * * @param holder the ViewHolder just bound * @param position the current item position * @since 5.0.0-b1 */ protected final void animateView(final RecyclerView.ViewHolder holder, final int position) { if (mRecyclerView == null) { return; } // Use always the max child count reached if (mMaxChildViews < mRecyclerView.getChildCount()) { mMaxChildViews = mRecyclerView.getChildCount(); } // Animate only during initial loading? if (onlyEntryAnimation && mLastAnimatedPosition >= mMaxChildViews) { isForwardEnabled = false; } int lastVisiblePosition = getFlexibleLayoutManager().findLastVisibleItemPosition(); // log.v("animateView isForwardEnabled=%s isReverseEnabled=%s isFastScroll=%s isNotified=%s mLastAnimatedPosition=%s mMaxChildViews=%s %s", // isForwardEnabled, isReverseEnabled, isFastScroll, mAnimatorNotifierObserver.isPositionNotified(), mLastAnimatedPosition, // mMaxChildViews, (!isReverseEnabled ? " Pos>LasVisPos=" + (position > lastVisiblePosition) : "") // ); if ((isForwardEnabled || isReverseEnabled) && !isFastScroll && holder instanceof FlexibleViewHolder && (!mAnimatorNotifierObserver.isPositionNotified() || isScrollableHeaderOrFooter(position)) && (isScrollableHeaderOrFooter(position) || (isForwardEnabled && position > lastVisiblePosition) || (isReverseEnabled && position < lastVisiblePosition) || (position == 0 && mMaxChildViews == 0))) { // Cancel animation is necessary when fling int hashCode = holder.itemView.hashCode(); cancelExistingAnimation(hashCode); // User animators List<Animator> animators = new ArrayList<>(); FlexibleViewHolder flexibleViewHolder = (FlexibleViewHolder) holder; flexibleViewHolder.scrollAnimators(animators, position, position >= lastVisiblePosition); // Execute the animations together AnimatorSet set = new AnimatorSet(); set.playTogether(animators); set.setInterpolator(mInterpolator); // Single view duration long duration = mDuration; for (Animator animator : animators) { if (animator.getDuration() != DEFAULT_DURATION) { duration = animator.getDuration(); } } set.setDuration(duration); set.addListener(new HelperAnimatorListener(hashCode)); if (mEntryStep) { // Stop stepDelay when screen is filled set.setStartDelay(calculateAnimationDelay(holder, position)); } set.start(); mAnimators.put(hashCode, set); //log.v("animateView Scroll animation on position %s", position); } mAnimatorNotifierObserver.clearNotified(); // Update last animated position mLastAnimatedPosition = position; }
Example #10
Source File: ItemComparatorTest.java From FlexibleAdapter with Apache License 2.0 | 2 votes |
@Override public void bindViewHolder(FlexibleAdapter adapter, FlexibleViewHolder holder, int position, List payloads) { }
Example #11
Source File: ItemComparatorTest.java From FlexibleAdapter with Apache License 2.0 | 2 votes |
@Override public void bindViewHolder(FlexibleAdapter adapter, FlexibleViewHolder holder, int position, List payloads) { }
Example #12
Source File: SelectableAdapter.java From FlexibleAdapter with Apache License 2.0 | 2 votes |
/** * Usually {@code RecyclerView} binds 3 items more than the visible items. * * @return a Set with all bound FlexibleViewHolders * @since 5.0.0-rc1 */ public Set<FlexibleViewHolder> getAllBoundViewHolders() { return Collections.unmodifiableSet(mBoundViewHolders); }