android.support.v7.util.SortedList Java Examples

The following examples show how to use android.support.v7.util.SortedList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NonFungibleTokenAdapter.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
protected <T> SortedList<T> addSortedItems(List<TicketRangeElement> sortedList, Token t, int id)
{
    long currentTime = 0;
    for (int i = 0; i < sortedList.size(); i++)
    {
        TicketRangeElement e = sortedList.get(i);
        if (currentRange != null && t.groupWithToken(currentRange, e, currentTime))
        {
            currentRange.tokenIds.add(e.id);
        }
        else
        {
            currentRange = new TicketRange(e.id, t.getAddress());
            final T item = generateType(currentRange, 10 + i, id);
            items.add((SortedItem)item);
            currentTime = e.time;
        }
    }

    return null;
}
 
Example #2
Source File: SortedMessageCollection.java    From Game-of-Thrones with Apache License 2.0 6 votes vote down vote up
public SortedMessageCollection(RecyclerView.Adapter adapter) {
  messageList = new SortedList<Message>(Message.class, new SortedListAdapterCallback<Message>(adapter) {
    @Override
    public int compare(Message o1, Message o2) {
      return o1.compareTo(o2);
    }

    @Override
    public boolean areContentsTheSame(Message oldItem, Message newItem) {
      return oldItem.equals(newItem);
    }

    @Override
    public boolean areItemsTheSame(Message item1, Message item2) {
      return item1.getId().equals(item2.getId());
    }
  });
}
 
Example #3
Source File: AbstractFilePickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Called when a previously created loader has finished its load.
 *
 * @param loader The Loader that has finished.
 * @param data   The data generated by the Loader.
 */
@Override
public void onLoadFinished(final Loader<SortedList<T>> loader,
                           final SortedList<T> data) {
    isLoading = false;
    mCheckedItems.clear();
    mCheckedVisibleViewHolders.clear();
    mFiles = data;
    mAdapter.setList(data);
    if (mCurrentDirView != null) {
        mCurrentDirView.setText(getFullPath(mCurrentPath));
    }
    // Stop loading now to avoid a refresh clearing the user's selections
    getLoaderManager().destroyLoader( 0 );
}
 
Example #4
Source File: AlarmAdapter.java    From android-DirectBoot with Apache License 2.0 5 votes vote down vote up
public AlarmAdapter(Context context, Set<Alarm> alarms) {
    mAlarmList = new SortedList<>(Alarm.class, new SortedListCallback());
    mAlarmList.addAll(alarms);
    mAlarmStorage = new AlarmStorage(context);
    mContext = context;
    mAlarmUtil = new AlarmUtil(context);
    mDateFormat = new SimpleDateFormat("MMM dd", Locale.getDefault());
    mTimeFormat = new SimpleDateFormat("kk:mm", Locale.getDefault());
}
 
Example #5
Source File: LeaderboardAdapter.java    From Leaderboards with Apache License 2.0 5 votes vote down vote up
public LeaderboardAdapter(Context context, Leaderboard leaderboard, FilterSpec filterSpec, int order) {
    this.context = context;
    this.mFilter = new SearchFilter();
    this.backupData = leaderboard.getRows();
    this.searchData = leaderboard.getRows();
    this.classColors = context.getResources().getIntArray(R.array.class_colors);
    this.leaderboardData = new SortedList<>(Row.class, new LeaderboardSortCallback(), leaderboard.getRows().size());
    this.mFilterSpec = (filterSpec == null) ? new FilterSpec() : filterSpec;
    this.currentSortBy = order;
    getFilter().filter("");
}
 
Example #6
Source File: DropboxFilePickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Once loading has finished, show the list and hide the progress bar.
 */
@Override
public void onLoaderReset(Loader<SortedList<Metadata>> loader) {
    progressBar.setVisibility(View.INVISIBLE);
    recyclerView.setVisibility(View.VISIBLE);
    super.onLoaderReset(loader);
}
 
Example #7
Source File: FeedAdapter.java    From dev-summit-architecture-demo with Apache License 2.0 5 votes vote down vote up
public FeedAdapter(Context context) {
    mLayoutInflater = LayoutInflater.from(context);
    mList = new SortedList<>(FeedItem.class,
            new SortedListAdapterCallback<FeedItem>(this) {
                @Override
                public int compare(FeedItem o1, FeedItem o2) {
                    Post p2 = o2.getPost();
                    Post p1 = o1.getPost();
                    if (p1.isPending() != p2.isPending()) {
                        return p1.isPending() ? -1 : 1;
                    }
                    return (int) (p2.getCreated() - p1.getCreated());
                }

                @SuppressWarnings("SimplifiableIfStatement")
                @Override
                public boolean areContentsTheSame(FeedItem oldItem,
                        FeedItem newItem) {
                    Post oldPost = oldItem.getPost();
                    Post newPost = newItem.getPost();
                    if (oldPost.getId() != newPost.getId()) {
                        return false;
                    }
                    if (!oldPost.getText().equals(newPost.getText())) {
                        return false;
                    }
                    if (!oldItem.getUser().getName().equals(newItem.getUser().getName())) {
                        return false;
                    }
                    return oldItem.getPost().isPending() == newItem.getPost().isPending();
                }

                @Override
                public boolean areItemsTheSame(FeedItem item1, FeedItem item2) {
                    return item1.getPost().getId() == item2.getPost().getId();
                }
            });
}
 
Example #8
Source File: AlarmAdapter.java    From security-samples with Apache License 2.0 5 votes vote down vote up
public AlarmAdapter(Context context, Set<Alarm> alarms) {
    mAlarmList = new SortedList<>(Alarm.class, new SortedListCallback());
    mAlarmList.addAll(alarms);
    mAlarmStorage = new AlarmStorage(context);
    mContext = context;
    mAlarmUtil = new AlarmUtil(context);
    mDateFormat = new SimpleDateFormat("MMM dd", Locale.getDefault());
    mTimeFormat = new SimpleDateFormat("kk:mm", Locale.getDefault());
}
 
Example #9
Source File: DropboxFilePickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Once loading has finished, show the list and hide the progress bar.
 */
@Override
public void onLoadFinished(Loader<SortedList<Metadata>> loader, SortedList<Metadata> data) {
    progressBar.setVisibility(View.INVISIBLE);
    recyclerView.setVisibility(View.VISIBLE);
    super.onLoadFinished(loader, data);
}
 
Example #10
Source File: FtpPickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onLoadFinished(Loader<SortedList<FtpFile>> loader, SortedList<FtpFile> data) {
    progressBar.setVisibility(View.INVISIBLE);
    recyclerView.setVisibility(View.VISIBLE);
    super.onLoadFinished(loader, data);
}
 
Example #11
Source File: FileItemAdapter.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 4 votes vote down vote up
public void setList(@Nullable SortedList<T> list) {
    mList = list;
    notifyDataSetChanged();
}
 
Example #12
Source File: FtpPickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onLoaderReset(Loader<SortedList<FtpFile>> loader) {
    progressBar.setVisibility(View.INVISIBLE);
    recyclerView.setVisibility(View.VISIBLE);
    super.onLoaderReset(loader);
}
 
Example #13
Source File: EndlessLinearLayoutActivity.java    From HeaderAndFooterRecyclerView with Apache License 2.0 4 votes vote down vote up
public DataAdapter(Context context) {
    mLayoutInflater = LayoutInflater.from(context);
    mSortedList = new SortedList<>(ItemModel.class, new SortedList.Callback<ItemModel>() {

        /**
         * 返回一个负整数(第一个参数小于第二个)、零(相等)或正整数(第一个参数大于第二个)
         */
        @Override
        public int compare(ItemModel o1, ItemModel o2) {

            if (o1.id < o2.id) {
                return -1;
            } else if (o1.id > o2.id) {
                return 1;
            }

            return 0;
        }

        @Override
        public boolean areContentsTheSame(ItemModel oldItem, ItemModel newItem) {
            return oldItem.title.equals(newItem.title);
        }

        @Override
        public boolean areItemsTheSame(ItemModel item1, ItemModel item2) {
            return item1.id == item2.id;
        }

        @Override
        public void onInserted(int position, int count) {
            notifyItemRangeInserted(position, count);
        }

        @Override
        public void onRemoved(int position, int count) {
            notifyItemRangeRemoved(position, count);
        }

        @Override
        public void onMoved(int fromPosition, int toPosition) {
            notifyItemMoved(fromPosition, toPosition);
        }

        @Override
        public void onChanged(int position, int count) {
            notifyItemRangeChanged(position, count);
        }
    });
}
 
Example #14
Source File: SortedAdapterDataStructure.java    From AutoAdapter with Apache License 2.0 4 votes vote down vote up
public void updateAll(List<OrderableRenderer> list) {
    Stack<OrderableRenderer> itemsToRemove = new Stack<>();
    SortedAdapterDataStructure oldData = this;
    int oldSize = this.size();
    int newSize = list.size();
    ArrayList<OrderableRenderer> newData = new ArrayList<>(list);
    Collections.sort(newData, new Comparator<OrderableRenderer>() {
        @Override
        public int compare(OrderableRenderer o1, OrderableRenderer o2) {
            return o1.compareTo(o2);
        }
    });
    if (oldSize > 0) {
        OrderableRenderer oldItem;
        OrderableRenderer newItem;
        for (int i = 0; i < oldSize; i++) {
            oldItem = oldData.get(i);
            boolean needRemove = true;
            for (int j = 0; j < newSize; j++) {
                newItem = newData.get(j);
                if (oldItem.areItemsTheSame(newItem)) {
                    needRemove = false;
                    break;
                }
            }
            if (needRemove) {
                itemsToRemove.push(oldItem);
            }
        }
    }
    oldData.beginBatchedUpdates();
    while (!itemsToRemove.empty()) {
        oldData.remove(itemsToRemove.pop());
    }
    OrderableRenderer item;
    int oldIndex, newIndex;
    for (int i = 0; i < newSize; i++) {
        item = newData.get(i);
        newIndex = i;
        oldIndex = findSameItem(item);
        if (oldIndex > SortedList.INVALID_POSITION) {
            oldData.updateItemAt(oldIndex, item);
            if (oldIndex != newIndex) {
                oldData.recalculatePositionOfItemAt(oldIndex);
            }
        } else {
            oldData.add(item);
        }
    }
    oldData.endBatchedUpdates();
}
 
Example #15
Source File: Adapter.java    From explorer with Apache License 2.0 3 votes vote down vote up
public Adapter(Context context) {

        this.context = context;

        this.callback = new Callback(context, this);

        this.items = new SortedList<>(File.class, callback);

        this.selectedItems = new SparseBooleanArray();
    }
 
Example #16
Source File: LogicHandler.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Get a loader that lists the files in the current path,
 * and monitors changes.
 */
@NonNull
Loader<SortedList<T>> getLoader();
 
Example #17
Source File: AbstractFilePickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Instantiate and return a new Loader for the given ID.
 *
 * @param id   The ID whose loader is to be created.
 * @param args Any arguments supplied by the caller.
 * @return Return a new Loader instance that is ready to start loading.
 */
@Override
public Loader<SortedList<T>> onCreateLoader(final int id, final Bundle args) {
    return getLoader();
}
 
Example #18
Source File: AbstractFilePickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Called when a previously created loader is being reset, and thus
 * making its data unavailable.  The application should at this point
 * remove any references it has to the Loader's data.
 *
 * @param loader The Loader that is being reset.
 */
@Override
public void onLoaderReset(final Loader<SortedList<T>> loader) {
    isLoading = false;
}