Search in sources :

Example 11 with ViewHolder

use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.

the class FlexibleItemAnimator method endAnimation.

@Override
public void endAnimation(ViewHolder item) {
    final View view = item.itemView;
    // This will trigger end callback which should set properties to their target values.
    ViewCompat.animate(view).cancel();
    // TODO: if some other animations are chained to end, how do we cancel them as well?
    for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
        MoveInfo moveInfo = mPendingMoves.get(i);
        if (moveInfo.holder == item) {
            view.setTranslationY(0);
            view.setTranslationX(0);
            dispatchMoveFinished(item);
            mPendingMoves.remove(i);
        }
    }
    endChangeAnimation(mPendingChanges, item);
    if (mPendingRemovals.remove(item)) {
        clear(item.itemView);
        dispatchRemoveFinished(item);
    }
    if (mPendingAdditions.remove(item)) {
        clear(item.itemView);
        dispatchAddFinished(item);
    }
    for (int i = mChangesList.size() - 1; i >= 0; i--) {
        ArrayList<ChangeInfo> changes = mChangesList.get(i);
        endChangeAnimation(changes, item);
        if (changes.isEmpty()) {
            mChangesList.remove(i);
        }
    }
    for (int i = mMovesList.size() - 1; i >= 0; i--) {
        ArrayList<MoveInfo> moves = mMovesList.get(i);
        for (int j = moves.size() - 1; j >= 0; j--) {
            MoveInfo moveInfo = moves.get(j);
            if (moveInfo.holder == item) {
                view.setTranslationY(0);
                view.setTranslationX(0);
                dispatchMoveFinished(item);
                moves.remove(j);
                if (moves.isEmpty()) {
                    mMovesList.remove(i);
                }
                break;
            }
        }
    }
    for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
        ArrayList<ViewHolder> additions = mAdditionsList.get(i);
        if (additions.remove(item)) {
            clear(item.itemView);
            dispatchAddFinished(item);
            if (additions.isEmpty()) {
                mAdditionsList.remove(i);
            }
        }
    }
    // Animations should be ended by the cancel above.
    // Used during DEBUGGING; Commented in final version.
    // if (mRemoveAnimations.remove(item)) {
    // throw new IllegalStateException(
    // "After animation is cancelled, item should not be in mRemoveAnimations list");
    // }
    // if (mAddAnimations.remove(item)) {
    // throw new IllegalStateException(
    // "After animation is cancelled, item should not be in mAddAnimations list");
    // }
    // if (mChangeAnimations.remove(item)) {
    // throw new IllegalStateException(
    // "After animation is cancelled, item should not be in mChangeAnimations list");
    // }
    // if (mMoveAnimations.remove(item)) {
    // throw new IllegalStateException(
    // "After animation is cancelled, item should not be in mMoveAnimations list");
    // }
    dispatchFinishedWhenDone();
}
Also used : AnimatedViewHolder(eu.davidea.viewholders.AnimatedViewHolder) ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 12 with ViewHolder

use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.

the class FlexibleItemAnimator method animateChangeImpl.

private void animateChangeImpl(final ChangeInfo changeInfo) {
    final ViewHolder holder = changeInfo.oldHolder;
    final View view = holder == null ? null : holder.itemView;
    final ViewHolder newHolder = changeInfo.newHolder;
    final View newView = newHolder != null ? newHolder.itemView : null;
    if (view != null) {
        final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view).setDuration(getChangeDuration());
        mChangeAnimations.add(changeInfo.oldHolder);
        oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
        oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
        oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {

            @Override
            public void onAnimationStart(View view) {
                dispatchChangeStarting(changeInfo.oldHolder, true);
            }

            @Override
            public void onAnimationEnd(View view) {
                oldViewAnim.setListener(null);
                view.setAlpha(1);
                view.setTranslationX(0);
                view.setTranslationY(0);
                dispatchChangeFinished(changeInfo.oldHolder, true);
                mChangeAnimations.remove(changeInfo.oldHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
    if (newView != null) {
        final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView);
        mChangeAnimations.add(changeInfo.newHolder);
        newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1).setListener(new VpaListenerAdapter() {

            @Override
            public void onAnimationStart(View view) {
                dispatchChangeStarting(changeInfo.newHolder, false);
            }

            @Override
            public void onAnimationEnd(View view) {
                newViewAnimation.setListener(null);
                newView.setAlpha(1);
                newView.setTranslationX(0);
                newView.setTranslationY(0);
                dispatchChangeFinished(changeInfo.newHolder, false);
                mChangeAnimations.remove(changeInfo.newHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
}
Also used : AnimatedViewHolder(eu.davidea.viewholders.AnimatedViewHolder) ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) ViewPropertyAnimatorCompat(androidx.core.view.ViewPropertyAnimatorCompat) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 13 with ViewHolder

use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.

the class FlexibleItemAnimator method runRemoveAnimation.

// 1st Remove
private void runRemoveAnimation() {
    // Reverse sorting removal animations
    Collections.sort(mPendingRemovals, new Comparator<ViewHolder>() {

        @Override
        public int compare(ViewHolder vh1, ViewHolder vh2) {
            return (int) (vh2.getItemId() - vh1.getItemId());
        }
    });
    Runnable remover = new Runnable() {

        @Override
        public void run() {
            int index = 0;
            for (ViewHolder holder : mPendingRemovals) {
                doAnimateRemove(holder, index++);
            }
            mPendingRemovals.clear();
        }
    };
    remover.run();
}
Also used : AnimatedViewHolder(eu.davidea.viewholders.AnimatedViewHolder) ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder)

Example 14 with ViewHolder

use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project Signal-Android by signalapp.

the class StickyHeaderDecoration method getHeader.

@NonNull
protected ViewHolder getHeader(RecyclerView parent, StickyHeaderAdapter adapter, int position) {
    final long key = adapter.getHeaderId(position);
    ViewHolder headerHolder = headerCache.get(key);
    if (headerHolder == null) {
        if (key != StickyHeaderAdapter.NO_HEADER_ID) {
            headerHolder = adapter.onCreateHeaderViewHolder(parent, position, type);
            // noinspection unchecked
            adapter.onBindHeaderViewHolder(headerHolder, position, type);
        }
        if (headerHolder == null) {
            headerHolder = new RecyclerView.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.null_recyclerview_header, parent, false)) {
            };
        }
        headerCache.put(key, headerHolder);
    }
    final View header = headerHolder.itemView;
    int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED);
    int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width);
    int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height);
    header.measure(childWidth, childHeight);
    header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
    return headerHolder;
}
Also used : ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) NonNull(androidx.annotation.NonNull)

Example 15 with ViewHolder

use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project Signal-Android by WhisperSystems.

the class StickyHeaderDecoration method getHeader.

@NonNull
protected ViewHolder getHeader(RecyclerView parent, StickyHeaderAdapter adapter, int position) {
    final long key = adapter.getHeaderId(position);
    ViewHolder headerHolder = headerCache.get(key);
    if (headerHolder == null) {
        if (key != StickyHeaderAdapter.NO_HEADER_ID) {
            headerHolder = adapter.onCreateHeaderViewHolder(parent, position, type);
            // noinspection unchecked
            adapter.onBindHeaderViewHolder(headerHolder, position, type);
        }
        if (headerHolder == null) {
            headerHolder = new RecyclerView.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.null_recyclerview_header, parent, false)) {
            };
        }
        headerCache.put(key, headerHolder);
    }
    final View header = headerHolder.itemView;
    int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED);
    int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width);
    int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height);
    header.measure(childWidth, childHeight);
    header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
    return headerHolder;
}
Also used : ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) NonNull(androidx.annotation.NonNull)

Aggregations

ViewHolder (androidx.recyclerview.widget.RecyclerView.ViewHolder)23 View (android.view.View)16 RecyclerView (androidx.recyclerview.widget.RecyclerView)16 AnimatedViewHolder (eu.davidea.viewholders.AnimatedViewHolder)6 ArrayList (java.util.ArrayList)4 ViewPropertyAnimatorCompat (androidx.core.view.ViewPropertyAnimatorCompat)3 NonNull (androidx.annotation.NonNull)2 Animator (android.animation.Animator)1 ValueAnimator (android.animation.ValueAnimator)1 ViewParent (android.view.ViewParent)1 Nullable (androidx.annotation.Nullable)1