예제 #1
0
            /**
             * Dispatches the update events to the given adapter.
             * <p>
             * For example, if you have an {@link RecyclerView.Adapter Adapter}
             * that is backed by a {@link List}, you can swap the list with the new one then call this
             * method to dispatch all updates to the RecyclerView.
             * <pre>
             *     List oldList = mAdapter.getData();
             *     DiffResult result = DiffUtil.calculateDiff(new MyCallback(oldList, newList));
             *     mAdapter.setData(newList);
             *     result.dispatchUpdatesTo(mAdapter);
             * </pre>
             * <p>
             * Note that the RecyclerView requires you to dispatch adapter updates immediately when you
             * change the data (you cannot defer {@code notify*} calls). The usage above adheres to this
             * rule because updates are sent to the adapter right after the backing data is changed,
             * before RecyclerView tries to read it.
             * <p>
             * On the other hand, if you have another
             * {@link RecyclerView.AdapterDataObserver AdapterDataObserver}
             * that tries to process events synchronously, this may confuse that observer because the
             * list is instantly moved to its final state while the adapter updates are dispatched later
             * on, one by one. If you have such an
             * {@link RecyclerView.AdapterDataObserver AdapterDataObserver},
             * you can use
             * {@link #dispatchUpdatesTo(ListUpdateCallback)} to handle each modification
             * manually.
             *
             * @param adapter A RecyclerView adapter which was displaying the old list and will start
             *                displaying the new list.
             * @see AdapterListUpdateCallback
             */
            //public void dispatchUpdatesTo(@NonNull final RecyclerView.Adapter adapter)
            //{
            //    dispatchUpdatesTo(new AdapterListUpdateCallback(adapter));
            //}

            /**
             * Dispatches update operations to the given Callback.
             * <p>
             * These updates are atomic such that the first update call affects every update call that
             * comes after it (the same as RecyclerView).
             *
             * @param updateCallback The callback to receive the update operations.
             * @see #dispatchUpdatesTo(RecyclerView.Adapter)
             */
            public void DispatchUpdatesTo <T>(MvxObservableCollection <T> updateCallback, IList <T> source)
            {
                // These are add/remove ops that are converted to moves. We track their positions until
                // their respective update operations are processed.
                List <PostponedUpdate> postponedUpdates = new List <PostponedUpdate>();
                int posOld = mOldListSize;
                int posNew = mNewListSize;

                for (int snakeIndex = mSnakes.Count - 1; snakeIndex >= 0; snakeIndex--)
                {
                    Snake snake     = mSnakes[snakeIndex];
                    int   snakeSize = snake.size;
                    int   endX      = snake.x + snakeSize;
                    int   endY      = snake.y + snakeSize;
                    if (endX < posOld)
                    {
                        DispatchRemovals(postponedUpdates, updateCallback, source, endX, posOld - endX, endX);
                    }

                    if (endY < posNew)
                    {
                        DispatchAdditions(postponedUpdates, updateCallback, source, endX, posNew - endY,
                                          endY);
                    }
                    for (int i = snakeSize - 1; i >= 0; i--)
                    {
                        if ((mOldItemStatuses[snake.x + i] & FLAG_MASK) == FLAG_CHANGED)
                        {
                            //updateCallback.onChanged(snake.x + i, 1,
                            //        mCallback.getChangePayload(snake.x + i, snake.y + i));
                            updateCallback.Change(snake.x + i);
                        }
                    }
                    posOld = snake.x;
                    posNew = snake.y;
                }
                //batchingCallback.dispatchLastEvent();
            }