/** * Gets group view type from a raw view type. * * @param rawViewType raw view type value (return value of {@link androidx.recyclerview.widget.RecyclerView.ViewHolder#getItemViewType()}) * @return Group view type for the given raw view type. */ public static int getGroupViewType(int rawViewType) { return ItemViewTypeComposer.extractWrappedViewTypePart(rawViewType); }
/** * Gets child view type from a raw view type. * * @param rawViewType raw view type value (return value of {@link androidx.recyclerview.widget.RecyclerView.ViewHolder#getItemViewType()}) * @return Child view type for the given raw view type. */ public static int getChildViewType(int rawViewType) { return ItemViewTypeComposer.extractWrappedViewTypePart(rawViewType); }
@Test public void extractWrappedViewTypePart() throws Exception { // zero assertThat(ItemViewTypeComposer.extractWrappedViewTypePart(0), is(0)); // one assertThat(ItemViewTypeComposer.extractWrappedViewTypePart(1 << ItemViewTypeComposer.BIT_OFFSET_WRAPPED_VIEW_TYPE), is(1)); // full bits assertThat(ItemViewTypeComposer.extractWrappedViewTypePart(ItemViewTypeComposer.BIT_MASK_WRAPPED_VIEW_TYPE), is(-1)); // min assertThat(ItemViewTypeComposer.extractWrappedViewTypePart(ItemViewTypeComposer.MIN_WRAPPED_VIEW_TYPE << ItemViewTypeComposer.BIT_OFFSET_WRAPPED_VIEW_TYPE), is(ItemViewTypeComposer.MIN_WRAPPED_VIEW_TYPE)); // max assertThat(ItemViewTypeComposer.extractWrappedViewTypePart(ItemViewTypeComposer.MAX_WRAPPED_VIEW_TYPE << ItemViewTypeComposer.BIT_OFFSET_WRAPPED_VIEW_TYPE), is(ItemViewTypeComposer.MAX_WRAPPED_VIEW_TYPE)); // etc - 1 assertThat(ItemViewTypeComposer.extractWrappedViewTypePart(ItemViewTypeComposer.BIT_MASK_EXPANDABLE_FLAG), is(0)); // etc - 2 assertThat(ItemViewTypeComposer.extractWrappedViewTypePart(ItemViewTypeComposer.BIT_MASK_SEGMENT), is(0)); }