private void updateItems(List<GitComment> comments, List<FullCommitFile> files) { filesSection.update(createFileSections(files)); List<CommitCommentItem> items = new ArrayList<>(); for (GitComment comment : comments) { items.add(new CommitCommentItem(avatars, commentImageGetter, comment)); } commentSection.update(items); }
@Override public void onClick(View view) { List<UpdatableItem> shuffled = new ArrayList<>(updatableItems); Collections.shuffle(shuffled); updatingGroup.update(shuffled); // You can also do this by forcing a change with payload binding.recyclerView.post(new Runnable() { @Override public void run() { binding.recyclerView.invalidateItemDecorations(); } }); } };
private void updateFiles(Gist gist) { final Activity activity = getActivity(); if (activity == null) { return; } Map<String, GistFile> files = gist.files(); if (files == null || files.isEmpty()) { filesSection.update(Collections.emptyList()); return; } List<GistFileItem> fileItems = new ArrayList<>(); for (GistFile file : files.values()) { fileItems.add(new GistFileItem(file)); } filesSection.update(fileItems); }
private void addCommitParents(Commit commit) { List<Commit> parents = commit.parents(); if (parents == null || parents.isEmpty()) { return; } List<CommitParentItem> items = new ArrayList<>(); for (Commit parent : parents) { items.add(new CommitParentItem(getActivity(), parent)); } commitSection.update(items); }
/** * Called when the data has loaded. * * @param newItems The items added to the list. */ protected void onDataLoaded(List<Item> newItems) { if (!isAdded()) { return; } isLoading = false; swipeLayout.setRefreshing(false); items.addAll(newItems); mainSection.update(items); showList(); }
private void updateList(CommitCompare compare) { if (!isAdded()) { return; } this.compare = compare; progress.setVisibility(View.GONE); list.setVisibility(View.VISIBLE); List<Commit> commits = compare.commits(); if (!commits.isEmpty()) { String comparingCommits = getString(R.string.comparing_commits); String text = MessageFormat.format(comparingCommits, commits.size()); commitsSection.setHeader( new TextItem(R.layout.commit_details_header, R.id.tv_commit_summary, text) ); List<CommitItem> items = new ArrayList<>(); for (Commit commit : commits) { items.add(new CommitItem(avatars, commit)); } commitsSection.update(items); } List<GitHubFile> files = compare.files(); if (!files.isEmpty()) { filesSection.setHeader( new TextItem(R.layout.commit_compare_file_details_header, R.id.tv_commit_file_summary, CommitUtils.formatStats(files)) ); filesSection.update(createFileSections(files)); } }
private void updateList(Gist gist, List<GitHubComment> comments) { List<GitHubCommentItem> items = new ArrayList<>(); String username = AccountUtils.getLogin(getActivity()); boolean isOwner = isOwner(); for (GitHubComment comment : comments) { items.add( new GitHubCommentItem(avatars, imageGetter, editCommentListener, deleteCommentListener, username, isOwner, comment) ); } commentsSection.update(items); mainSection.removeFooter(); updateHeader(gist); updateFiles(gist); }
@Test public void updateWithTheSameItemAndSameContentsDoesNotNotifyChange() { List<Item> children = new ArrayList<Item>(); Item item = new ContentUpdatingItem(1, "contents"); children.add(item); Section group = new Section(); group.setHeader(new DummyItem()); group.update(children); group.registerGroupDataObserver(groupAdapter); group.update(children); verifyNoMoreInteractions(groupAdapter); }
@Test public void updateWithADifferentItemNotifiesRemoveAndAdd() { Item oldItem = new ContentUpdatingItem(1, "contents"); Section group = new Section(); group.setHeader(new DummyItem()); group.update(Collections.singletonList(oldItem)); group.registerGroupDataObserver(groupAdapter); Item newItem = new ContentUpdatingItem(2, "contents"); group.update(Collections.singletonList(newItem)); verify(groupAdapter).onItemRangeRemoved(group, 1, 1); verify(groupAdapter).onItemRangeInserted(group, 1, 1); }
@Test public void updateGroupChangesRange() { List<Item> children = new ArrayList<Item>(); children.add(new AlwaysUpdatingItem(1)); children.add(new AlwaysUpdatingItem(2)); Section group = new Section(); group.setHeader(new DummyItem()); group.registerGroupDataObserver(groupAdapter); group.update(children); verify(groupAdapter).onItemRangeInserted(group, 1, 2); verifyNoMoreInteractions(groupAdapter); group.update(children); verify(groupAdapter).onItemRangeChanged(group, 1, 2, null); verifyNoMoreInteractions(groupAdapter); }
@Test public void updateWithTheSameItemButDifferentContentsNotifiesChange() { Item oldItem = new ContentUpdatingItem(1, "contents"); Section group = new Section(); group.setHeader(new DummyItem()); group.update(Collections.singletonList(oldItem)); group.registerGroupDataObserver(groupAdapter); Item newItem = new ContentUpdatingItem(1, "new contents"); group.update(Collections.singletonList(newItem)); verify(groupAdapter).onItemRangeChanged(group, 1, 1, null); }
@Test public void updateGroupToEmptyWithPlaceholderNotifiesRemoveAndInsertPlaceholder() { List<Item> children = new ArrayList<Item>(); children.add(new AlwaysUpdatingItem(1)); children.add(new AlwaysUpdatingItem(2)); Section group = new Section(); group.setHeader(new DummyItem()); group.setPlaceholder(new DummyItem()); group.update(children); group.registerGroupDataObserver(groupAdapter); group.update(new ArrayList<Group>()); verify(groupAdapter).onItemRangeRemoved(group, 1, 2); verify(groupAdapter).onItemRangeInserted(group, 1, 1); verifyNoMoreInteractions(groupAdapter); } }
@Test public void updateWithANestedGroupsNotifiesRemoveAndAdd() { Item oldItem = new ContentUpdatingItem(1, "contents"); Section group = new Section(); group.setHeader(new DummyItem()); group.update(Collections.singletonList(oldItem)); group.registerGroupDataObserver(groupAdapter); Item newItem = new ContentUpdatingItem(2, "new contents"); Section newGroup = new Section(); newGroup.add(newItem); group.update(Collections.singletonList(newGroup)); verify(groupAdapter).onItemRangeRemoved(group, 1, 1); verify(groupAdapter).onItemRangeInserted(group, 1, 1); }
@Test public void notifyChangeInAnItemCausesParentToNotifyChange() { List<Item> children = new ArrayList<Item>(); Item item = new DummyItem(); children.add(item); Section group = new Section(); group.setHeader(new DummyItem()); group.update(children); group.registerGroupDataObserver(groupAdapter); item.notifyChanged(); verify(groupAdapter).onItemChanged(group, 1); }
@Test public void updateGroupWithPlaceholderNotifiesRemovePlaceholderAndInsert() { List<Item> children = new ArrayList<Item>(); children.add(new AlwaysUpdatingItem(1)); children.add(new AlwaysUpdatingItem(2)); Section group = new Section(); group.setHeader(new DummyItem()); group.setPlaceholder(new DummyItem()); group.registerGroupDataObserver(groupAdapter); group.update(children); verify(groupAdapter).onItemRangeRemoved(group, 1, 1); verify(groupAdapter).onItemRangeInserted(group, 1, 2); verifyNoMoreInteractions(groupAdapter); }
updatableItems.add(new UpdatableItem(rainbow200[i], i)); updatingGroup.update(updatableItems); updatingSection.add(updatingGroup); groupAdapter.add(updatingSection);