Interface GridView

All Known Implementing Classes:
GridViewImpl

@API(status=STABLE, since="2.0.0-milestone.1.0") public interface GridView
Represents a grid view. The grid view internally has a backing list and a view list. The backing list is the logical view of the grid without any filtering or sorting applied. It's the source of truth. The view list has filtering and sorting rules applied and is in sync with the backing list (depending on the view being in "prevent sorting" mode).
  • Method Details

    • setListener

      void setListener(@Nullable Runnable listener)
      Sets a listener that is called when the grid view changes.
      Parameters:
      listener - the listener, can be null
    • setSortingType

      void setSortingType(GridSortingType sortingType)
      Changing the sorting type still requires a call to sort().
      Parameters:
      sortingType - the sorting type
    • setFilterAndSort

      Parameters:
      predicate - the filter
      Returns:
      the previous filtering predicate
    • setPreventSorting

      boolean setPreventSorting(boolean changedPreventSorting)
      Preventing sorting means that the changes will still arrive at the backing list and view list, but, the view list won't be resorted and if a resource is zeroed, will stay in view until sorting is enabled again. This still requires a call to sort() when preventing sorting is disabled again.
      Parameters:
      changedPreventSorting - whether the view should prevent sorting on changes
      Returns:
      whether prevent sorting has changed
    • setSortingDirection

      void setSortingDirection(GridSortingDirection sortingDirection)
      Changing the sorting direction still requires a call to sort().
      Parameters:
      sortingDirection - the sorting direction
    • getTrackedResource

      Optional<TrackedResource> getTrackedResource(ResourceKey resource)
      Parameters:
      resource - the resource
      Returns:
      the tracked resource, if present
    • getAmount

      long getAmount(ResourceKey resource)
      Parameters:
      resource - the resource
      Returns:
      the amount in the view, or zero if not present
    • sort

      void sort()
      Sorts the view list. Applies sorting and filtering rules.
    • onChange

      void onChange(ResourceKey resource, long amount, @Nullable TrackedResource trackedResource)
      Applies a change to a resource. Will update the backing list, and will also update the view list (depending on if the view is preventing sorting).
      Parameters:
      resource - the resource
      amount - the amount, can be negative or positive
      trackedResource - the tracked resource, can be null
    • getViewList

      List<GridResource> getViewList()
      Returns:
      the view list
    • copyBackingList

      ResourceList copyBackingList()
      Returns:
      a copy of the backing list
    • clear

      void clear()
      Clears the backing list, view list and tracked resources index.