This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from spacecowboy/divider_support
Add ability to define a list divider in theme
- Loading branch information
Showing
5 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
library/src/main/java/com/nononsenseapps/filepicker/DividerItemDecoration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.nononsenseapps.filepicker; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Rect; | ||
import android.graphics.drawable.Drawable; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
|
||
/** | ||
* Basic ItemDecoration which loads a drawable as a divider. | ||
*/ | ||
public class DividerItemDecoration extends RecyclerView.ItemDecoration { | ||
private Drawable mDivider; | ||
|
||
public DividerItemDecoration(Drawable divider) { | ||
mDivider = divider; | ||
} | ||
|
||
@Override | ||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { | ||
super.getItemOffsets(outRect, view, parent, state); | ||
|
||
if (parent.getChildAdapterPosition(view) == 0) { | ||
return; | ||
} | ||
|
||
outRect.top = mDivider.getIntrinsicHeight(); | ||
} | ||
|
||
@Override | ||
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { | ||
int dividerLeft = parent.getPaddingLeft(); | ||
int dividerRight = parent.getWidth() - parent.getPaddingRight(); | ||
|
||
int childCount = parent.getChildCount(); | ||
for (int i = 0; i < childCount - 1; i++) { | ||
View child = parent.getChildAt(i); | ||
|
||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); | ||
|
||
int dividerTop = child.getBottom() + params.bottomMargin; | ||
int dividerBottom = dividerTop + mDivider.getIntrinsicHeight(); | ||
|
||
mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom); | ||
mDivider.draw(canvas); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters