Java源码示例:eu.davidea.viewholders.FlexibleViewHolder

示例1
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;
}
 
示例2
@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));
    }
}
 
示例3
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();
}
 
示例4
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);
}
 
示例5
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);
        }
    }
}
 
示例6
@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);
    }
}
 
示例7
@Override
public FlexibleViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
    return null;
}
 
示例8
@Override
public FlexibleViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
    return null;
}
 
示例9
/**
     * 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;
    }
 
示例10
@Override
public void bindViewHolder(FlexibleAdapter adapter, FlexibleViewHolder holder, int position, List payloads) {

}
 
示例11
@Override
public void bindViewHolder(FlexibleAdapter adapter, FlexibleViewHolder holder, int position, List payloads) {

}
 
示例12
/**
 * 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);
}