Search in sources :

Example 1 with ConversationListArchivedBorderRow

use of com.waz.zclient.pages.main.conversationlist.views.row.ConversationListArchivedBorderRow in project wire-android by wireapp.

the class ConversationListAdapter method getArchiveBorderRow.

public View getArchiveBorderRow(Context context, int pos) {
    ConversationListArchivedBorderRow view = new ConversationListArchivedBorderRow(context);
    AbsListView.LayoutParams params = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, context.getResources().getDimensionPixelSize(R.dimen.list__archived_border_height));
    view.setLayoutParams(params);
    view.setId(pos);
    return view;
}
Also used : AbsListView(android.widget.AbsListView) ConversationListArchivedBorderRow(com.waz.zclient.pages.main.conversationlist.views.row.ConversationListArchivedBorderRow)

Example 2 with ConversationListArchivedBorderRow

use of com.waz.zclient.pages.main.conversationlist.views.row.ConversationListArchivedBorderRow in project wire-android by wireapp.

the class ConversationListAdapter method animateSortingOfConversation.

private void animateSortingOfConversation() {
    CoreList<IConversation> archivedConversations = conversationList.getArchivedConversations();
    boolean isArchiveVisible = archivedState == ArchivedState.VISIBLE;
    Map<Integer, View> currentViews = new HashMap<>();
    List<Animator> animators = new ArrayList<>();
    // Cache all displayed views and store the last and first to hack views that leave the screen
    View first = null;
    View last = null;
    for (int i = 0; i < listView.getChildCount(); i++) {
        View view = listView.getChildAt(i);
        if (view instanceof ConversationListRow || view instanceof ConversationListArchivedBorderRow) {
            if (first == null) {
                first = view;
            }
            last = view;
            currentViews.put(view.getId(), view);
        }
    }
    final View firstView = first;
    final View lastView = last;
    // run once through the list of all displayed items
    for (int i = 0; i < listView.getChildCount(); i++) {
        if (listView.getChildAt(i) instanceof ConversationListRow) {
            final ConversationListRow row = (ConversationListRow) listView.getChildAt(i);
            // needs to be called - this view cant be used as a convertView no more
            row.redraw();
            int currPos = row.getId();
            final IConversation conversation = row.getConversation();
            int newPos;
            // it is the inbox
            if (currPos == posOfInboxOld) {
                newPos = currPos;
            } else {
                newPos = conversationList.getConversationIndex(conversation.getId());
                // push one up for the inbox
                if (posOfInbox != CONNECT_REQUEST_INBOX_POSITION_NONE && newPos >= posOfInbox) {
                    newPos++;
                }
            }
            // the item is archived
            if (newPos == -1 && isArchiveVisible) {
                for (int j = 0; j < archivedConversations.size(); j++) {
                    if (ConversationUtils.isConversationEqual(archivedConversations.get(j), conversation)) {
                        newPos = getUnarchivedCount() + 1 + j;
                    }
                }
            }
            if (currPos != newPos) {
                if (currentViews.containsKey(newPos)) {
                    float t = currentViews.get(newPos).getY() - row.getY();
                    animators.add(ObjectAnimator.ofFloat(row, View.TRANSLATION_Y, t));
                } else {
                    // its archive target
                    if (newPos == -1) {
                        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(row, View.ALPHA, 0);
                        alphaAnimator.setInterpolator(new Quart.EaseOut());
                        alphaAnimator.setDuration(sortingAnimationDuration);
                        alphaAnimator.start();
                        continue;
                    }
                    // this view goes far north - we need to hack a little around it
                    if (currPos > newPos) {
                        float targetY = row.getY();
                        targetY -= first.getY();
                        animators.add(ObjectAnimator.ofFloat(row, View.TRANSLATION_Y, -targetY));
                        animators.add(ObjectAnimator.ofFloat(row, View.ALPHA, 1, 0, 1));
                        new Handler().postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                IConversation changeConversation = getItem(firstView.getId());
                                if (changeConversation != null) {
                                    row.setConversation(changeConversation);
                                }
                            }
                        }, sortingAnimationDuration / HACK_ANIMATION_FACTOR);
                    }
                    // this view goes far south - we need to hack a little around it
                    if (currPos < newPos) {
                        float targetY = row.getY() - last.getY();
                        boolean isOnlyArchive = conversationList.getArchivedConversations().size() == 1 && row.isArchiveTarget();
                        if (isOnlyArchive) {
                            targetY -= row.getMeasuredHeight();
                        }
                        animators.add(ObjectAnimator.ofFloat(row, View.TRANSLATION_Y, -targetY));
                        animators.add(ObjectAnimator.ofFloat(row, View.ALPHA, 1, 1, 1, 0, 1));
                        new Handler().postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                if (conversation != null && lastView != null && row != null) {
                                    IConversation changeConversation = getItem(lastView.getId());
                                    if (changeConversation != null) {
                                        row.setConversation(changeConversation);
                                    }
                                }
                            }
                        }, sortingAnimationDuration / HACK_ANIMATION_FACTOR);
                    }
                }
            }
        } else if (listView.getChildAt(i) instanceof ConversationListArchivedBorderRow && isArchiveVisible) {
            View row = listView.getChildAt(i);
            int newPos = getUnarchivedCount();
            if (currentViews.containsKey(newPos)) {
                float t = currentViews.get(newPos).getY() - row.getY();
                animators.add(ObjectAnimator.ofFloat(row, View.TRANSLATION_Y, t));
            } else {
                animators.add(ObjectAnimator.ofFloat(row, View.TRANSLATION_Y, ViewUtils.getOrientationIndependentDisplayHeight(listView.getContext())));
            }
        }
    }
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(sortingAnimationDuration);
    animatorSet.playTogether(animators);
    animatorSet.setInterpolator(new Expo.EaseOut());
    animatorSet.setStartDelay(translationDelay);
    animatorSet.start();
    cleanUpSorting();
}
Also used : HashMap(java.util.HashMap) ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) ConversationListRow(com.waz.zclient.pages.main.conversationlist.views.row.ConversationListRow) Handler(android.os.Handler) IConversation(com.waz.api.IConversation) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) SwipeListView(com.waz.zclient.pages.main.conversationlist.views.listview.SwipeListView) AbsListView(android.widget.AbsListView) RightIndicatorView(com.waz.zclient.pages.main.conversationlist.views.row.RightIndicatorView) ListView(android.widget.ListView) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) Quart(com.waz.zclient.ui.animation.interpolators.penner.Quart) Expo(com.waz.zclient.ui.animation.interpolators.penner.Expo) ConversationListArchivedBorderRow(com.waz.zclient.pages.main.conversationlist.views.row.ConversationListArchivedBorderRow)

Aggregations

AbsListView (android.widget.AbsListView)2 ConversationListArchivedBorderRow (com.waz.zclient.pages.main.conversationlist.views.row.ConversationListArchivedBorderRow)2 Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 Handler (android.os.Handler)1 View (android.view.View)1 ListView (android.widget.ListView)1 IConversation (com.waz.api.IConversation)1 SwipeListView (com.waz.zclient.pages.main.conversationlist.views.listview.SwipeListView)1 ConversationListRow (com.waz.zclient.pages.main.conversationlist.views.row.ConversationListRow)1 RightIndicatorView (com.waz.zclient.pages.main.conversationlist.views.row.RightIndicatorView)1 Expo (com.waz.zclient.ui.animation.interpolators.penner.Expo)1 Quart (com.waz.zclient.ui.animation.interpolators.penner.Quart)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1