Package 

Class SortedList.Callback

  • All Implemented Interfaces:
    java.util.Comparator , tds.androidx.recyclerview.widget.ListUpdateCallback

    
    public abstract class SortedList.Callback<T2>
     implements Comparator<T2>, ListUpdateCallback
                        

    The class that controls the behavior of the SortedList.

    It defines how items should be sorted and how duplicates should be handled.

    SortedList calls the callback methods on this class to notify changes about the underlyingdata.

    • Method Summary

      Modifier and Type Method Description
      abstract int compare(T2 o1, T2 o2) Similar to compare, should compare two andreturn how they should be ordered.
      abstract void onChanged(int position, int count) Called by the SortedList when the item at the given position is updated.
      void onChanged(int position, int count, Object payload) Called when {@code count} number of items are updated at the given position.
      abstract boolean areContentsTheSame(T2 oldItem, T2 newItem) Called by the SortedList when it wants to check whether two items have the same dataor not.
      abstract boolean areItemsTheSame(T2 item1, T2 item2) Called by the SortedList to decide whether two objects represent the same Item or not.
      Object getChangePayload(T2 item1, T2 item2) When areItemsTheSame returns {@code true} for two items and areContentsTheSame returns false for them, Callback calls thismethod to get a payload about the change.
      • Methods inherited from class java.util.Comparator

        compare, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reverseOrder, reversed, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
      • Methods inherited from class tds.androidx.recyclerview.widget.ListUpdateCallback

        onChanged, onInserted, onMoved, onRemoved
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • compare

         abstract int compare(T2 o1, T2 o2)

        Similar to compare, should compare two andreturn how they should be ordered.

        Parameters:
        o1 - The first object to compare.
        o2 - The second object to compare.
      • onChanged

         abstract void onChanged(int position, int count)

        Called by the SortedList when the item at the given position is updated.

        Parameters:
        position - The position of the item which has been updated.
        count - The number of items which has changed.
      • onChanged

         void onChanged(int position, int count, Object payload)

        Called when {@code count} number of items are updated at the given position.

        Parameters:
        position - The position of the item which has been updated.
        count - The number of items which has changed.
      • areContentsTheSame

         abstract boolean areContentsTheSame(T2 oldItem, T2 newItem)

        Called by the SortedList when it wants to check whether two items have the same dataor not. SortedList uses this information to decide whether it should call onChanged or not.

        SortedList uses this method to check equality instead of equals sothat you can change its behavior depending on your UI.

        For example, if you are using SortedList with a RecyclerView.Adapter, you shouldreturn whether the items' visual representations are the same or not.

        Parameters:
        oldItem - The previous representation of the object.
        newItem - The new object that replaces the previous one.
      • areItemsTheSame

         abstract boolean areItemsTheSame(T2 item1, T2 item2)

        Called by the SortedList to decide whether two objects represent the same Item or not.

        For example, if your items have unique ids, this method should check their equality.

        Parameters:
        item1 - The first item to check.
        item2 - The second item to check.
      • getChangePayload

        @Nullable() Object getChangePayload(T2 item1, T2 item2)

        When areItemsTheSame returns {@code true} for two items and areContentsTheSame returns false for them, Callback calls thismethod to get a payload about the change.

        For example, if you are using Callback with RecyclerView, you can return the particular field thatchanged in the item and your ItemAnimator can use thatinformation to run the correct animation.

        Default implementation returns {@code null}.

        Parameters:
        item1 - The first item to check.
        item2 - The second item to check.