Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
ffa4c33d
Commit
ffa4c33d
authored
Jan 04, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DividerItemDecoration.kt
parent
c16f27c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
DividerItemDecoration.kt
.../java/chat/rocket/android/widget/DividerItemDecoration.kt
+63
-0
No files found.
app/src/main/java/chat/rocket/android/widget/DividerItemDecoration.kt
0 → 100644
View file @
ffa4c33d
package
chat.rocket.android.widget
import
android.content.Context
import
android.graphics.Canvas
import
android.graphics.drawable.Drawable
import
android.support.annotation.DrawableRes
import
android.support.v4.content.ContextCompat
import
android.support.v7.widget.RecyclerView
/**
* Adds a default or custom divider to specific item views from the adapter's data set.
* @see RecyclerView.ItemDecoration
*/
class
DividerItemDecoration
()
:
RecyclerView
.
ItemDecoration
()
{
private
lateinit
var
divider
:
Drawable
private
var
boundStart
=
0
private
var
boundRight
=
0
// Default divider will be used.
constructor
(
context
:
Context
)
:
this
()
{
val
attrs
=
intArrayOf
(
android
.
R
.
attr
.
listDivider
)
val
styledAttributes
=
context
.
obtainStyledAttributes
(
attrs
)
divider
=
styledAttributes
.
getDrawable
(
0
)
styledAttributes
.
recycle
()
}
// Default divider with custom boundaries (start and right) will be used.
constructor
(
context
:
Context
,
boundStart
:
Int
,
boundRight
:
Int
)
:
this
()
{
val
attrs
=
intArrayOf
(
android
.
R
.
attr
.
listDivider
)
val
styledAttributes
=
context
.
obtainStyledAttributes
(
attrs
)
divider
=
styledAttributes
.
getDrawable
(
0
)
styledAttributes
.
recycle
()
this
.
boundStart
=
boundStart
this
.
boundRight
=
boundRight
}
// Custom divider will be used.
constructor
(
context
:
Context
,
@DrawableRes
drawableResId
:
Int
)
:
this
()
{
val
customDrawable
=
ContextCompat
.
getDrawable
(
context
,
drawableResId
)
if
(
customDrawable
!=
null
)
{
divider
=
customDrawable
}
}
override
fun
onDraw
(
c
:
Canvas
,
parent
:
RecyclerView
,
state
:
RecyclerView
.
State
)
{
val
left
=
parent
.
paddingLeft
+
boundStart
val
right
=
(
parent
.
width
-
parent
.
paddingRight
)
-
boundRight
val
childCount
=
parent
.
childCount
for
(
i
in
0
until
childCount
)
{
val
child
=
parent
.
getChildAt
(
i
)
val
params
=
child
.
layoutParams
as
RecyclerView
.
LayoutParams
val
top
=
child
.
bottom
+
params
.
bottomMargin
val
bottom
=
top
+
divider
.
intrinsicHeight
divider
.
setBounds
(
left
,
top
,
right
,
bottom
)
divider
.
draw
(
c
)
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment