public int getItemCount() { int size = 0; for (int i = 0; i < getGroupCount(); i++) { Group group = getGroup(i); size += group.getItemCount(); } return size; }
private void hidePlaceholder() { if (!isPlaceholderVisible || placeholder == null) return; isPlaceholderVisible = false; notifyItemRangeRemoved(getHeaderItemCount(), placeholder.getItemCount()); }
@Override public int getSpanSize(int position) { try { return getItem(position).getSpanSize(spanCount, position); } catch (IndexOutOfBoundsException e) { // Bug in support lib? TODO investigate further return spanCount; } } };
@Test public void childAddNotificationWhenExpanded() { ExpandableGroup expandableGroup = new ExpandableGroup(parent); expandableGroup.onToggleExpanded(); expandableGroup.registerGroupDataObserver(groupAdapter); Section section = new Section(); DummyItem item = new DummyItem(); expandableGroup.add(section); section.add(item); Mockito.verify(groupAdapter).onItemRangeInserted(expandableGroup, 1, 1); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); base = args.getString(EXTRA_BASE); repository = args.getParcelable(EXTRA_REPOSITORY); mainSection.add(commitSection); mainSection.add(filesSection); mainSection.add(commentSection); adapter.add(mainSection); adapter.setOnItemClickListener(this); }
@Override public void onItemClick(@NonNull Item item, @NonNull View view) { if (item instanceof LabelDialogItem) { LabelDialogItem labelDialogItem = (LabelDialogItem) item; labelDialogItem.toggleSelected(); selectedChoices[adapter.getAdapterPosition(item)] = labelDialogItem.isSelected(); item.notifyChanged(); } } }
private void showPlaceholder() { if (isPlaceholderVisible || placeholder == null) return; isPlaceholderVisible = true; notifyItemRangeInserted(getHeaderItemCount(), placeholder.getItemCount()); }
public void onToggleExpanded() { int oldSize = getItemCount(); isExpanded = !isExpanded; int newSize = getItemCount(); if (oldSize > newSize) { notifyItemRangeRemoved(newSize, oldSize - newSize); } else { notifyItemRangeInserted(oldSize, newSize - oldSize); } }
/** * Notify the underlying adapter that the data set has changed. * * @return this fragment */ protected ItemListFragment notifyDataSetChanged() { getListAdapter().notifyDataSetChanged(); return this; }
protected int getItemCountBeforeGroup(final int groupIndex) { int size = 0; for (int i = 0; i < groupIndex; i++) { final Group currentGroup = getGroup(i); size += currentGroup.getItemCount(); } return size; }
private int getHeaderItemCount() { return getHeaderCount() == 0 ? 0 : header.getItemCount(); }
public CarouselItem(RecyclerView.ItemDecoration itemDecoration, GroupAdapter adapter) { this.carouselDecoration = itemDecoration; this.adapter = adapter; adapter.setOnItemClickListener(this); }
@Override public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { Item oldItem = getItem(oldBodyGroups, oldItemPosition); Item newItem = getItem(newBodyGroups, newItemPosition); return newItem.isSameAs(oldItem); }
public void notifyChanged() { if (parentDataObserver != null) { parentDataObserver.onItemChanged(this, 0); } }
@Override public void onChanged(int position, int count, Object payload) { notifyItemRangeChanged(position, count, payload); } };
private static int getItemCount(Collection<? extends Group> groups) { int count = 0; for (Group group : groups) { count += group.getItemCount(); } return count; }
@Test public void noChildAddNotificationWhenCollapsed() { ExpandableGroup expandableGroup = new ExpandableGroup(parent); expandableGroup.registerGroupDataObserver(groupAdapter); Section section = new Section(); DummyItem item = new DummyItem(); expandableGroup.add(section); section.add(item); Mockito.verify(groupAdapter, Mockito.never()).onItemRangeInserted(expandableGroup, 1, 1); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainSection.add(commitsSection); mainSection.add(filesSection); adapter.add(mainSection); adapter.setOnItemClickListener(this); diffStyler = new DiffStyler(getResources()); compareCommits(); }
@Override public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { Item oldItem = getItem(oldGroups, oldItemPosition); Item newItem = getItem(newGroups, newItemPosition); return newItem.isSameAs(oldItem); }