private void setupRecyclerView() { Drawable shadow = ContextCompat.getDrawable(getContext(), R.drawable.list_drag_shadow); ItemDecoration background = new DragBackgroundDecoration(R.id.song_drag_root); ItemDecoration divider = new DragDividerDecoration(getContext(), true, R.id.instance_blank); ItemDecoration dragShadow = new DragDropDecoration((NinePatchDrawable) shadow); mRecyclerView.addItemDecoration(background); mRecyclerView.addItemDecoration(divider); mRecyclerView.addItemDecoration(dragShadow); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); boolean portrait = getResources().getConfiguration().orientation != ORIENTATION_LANDSCAPE; boolean tablet = getResources().getConfiguration().smallestScreenWidthDp >= 600; if (portrait || !tablet) { // Add an inner shadow at the top of the list mRecyclerView.addItemDecoration(new InsetDecoration( ContextCompat.getDrawable(getContext(), R.drawable.inset_top_shadow), (int) getResources().getDimension(R.dimen.inset_top_shadow_height), Gravity.TOP)); } else { // Add an inner shadow at the bottom of the list mRecyclerView.addItemDecoration(new InsetDecoration( ContextCompat.getDrawable(getContext(), R.drawable.inset_bottom_shadow), getResources().getDimensionPixelSize(R.dimen.inset_bottom_shadow_height), Gravity.BOTTOM)); } }
@Bindable public ItemDecoration[] getItemDecorations() { NinePatchDrawable dragShadow = (NinePatchDrawable) ContextCompat.getDrawable( getContext(), R.drawable.list_drag_shadow); return new ItemDecoration[] { new DragBackgroundDecoration(R.id.song_drag_root), new DragDividerDecoration(R.id.song_drag_root, getContext(), R.id.empty_layout), new DragDropDecoration(dragShadow) }; }
@Bindable public ItemDecoration[] getItemDecorations() { return new ItemDecoration[] { new BackgroundDecoration(R.id.loading_frame, R.id.artist_bio_card, R.id.relatedCard), new DividerDecoration(getContext(), R.id.artist_bio_card, R.id.album_view, R.id.subheader_frame, R.id.relatedCard, R.id.empty_layout), new GridSpacingDecoration( (int) getResources().getDimension(R.dimen.grid_margin), mAlbumColumnCount, mAlbumSection.getTypeId()), new GridSpacingDecoration( (int) getResources().getDimension(R.dimen.card_margin), mRelatedColumnCount, mRelatedArtistSection.getTypeId()) }; }
@Bindable public ItemDecoration[] getItemDecorations() { return new ItemDecoration[] { new BackgroundDecoration(), new DividerDecoration(getContext(), R.id.empty_layout) }; }
@BindingAdapter("itemDecorations") public static void setItemDecorations(RecyclerView recyclerView, ItemDecoration... decor) { for (ItemDecoration decoration : decor) { recyclerView.addItemDecoration(decoration); } }
/** * Implement this with the ItemDecoration of your choice. * * if you don't want decoration, @return null * else @return ItemDecoration */ protected abstract ItemDecoration getItemDecoration();
/** * Implement this with the ItemDecoration of your choice. * * if you don't want decoration, @return null * else @return ItemDecoration */ @Override protected ItemDecoration getItemDecoration() { return new DividerDecoration(this, DividerDecoration.VERTICAL_LIST); }