-
Notifications
You must be signed in to change notification settings - Fork 38
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 #180 from MostafaMohamed2002/feature/rv_divider
Refactor RecyclerView item decoration in AboutFragment and SettingsFr…
- Loading branch information
Showing
12 changed files
with
117 additions
and
39 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
42 changes: 42 additions & 0 deletions
42
app/src/main/java/be/scri/views/CustomDividerItemDecoration.kt
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,42 @@ | ||
import android.graphics.Canvas | ||
import android.graphics.Rect | ||
import android.graphics.drawable.Drawable | ||
import android.view.View | ||
import androidx.annotation.NonNull | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
class CustomDividerItemDecoration( | ||
private val drawable: Drawable, | ||
private val width: Int, | ||
private val marginLeft: Int, | ||
private val marginRight: Int, | ||
) : RecyclerView.ItemDecoration() { | ||
override fun onDraw( | ||
@NonNull canvas: Canvas, | ||
@NonNull parent: RecyclerView, | ||
@NonNull state: RecyclerView.State, | ||
) { | ||
val left = parent.paddingLeft + marginLeft | ||
val right = parent.width - parent.paddingRight - marginRight | ||
|
||
val childCount = parent.childCount | ||
for (i in 0 until childCount - 1) { // Exclude the last item | ||
val child = parent.getChildAt(i) | ||
val params = child.layoutParams as RecyclerView.LayoutParams | ||
val top = child.bottom + params.bottomMargin | ||
val bottom = top + width | ||
|
||
drawable.setBounds(left, top, right, bottom) | ||
drawable.draw(canvas) | ||
} | ||
} | ||
|
||
override fun getItemOffsets( | ||
outRect: Rect, | ||
view: View, | ||
parent: RecyclerView, | ||
state: RecyclerView.State, | ||
) { | ||
outRect.set(0, 0, 0, width) | ||
} | ||
} |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<size android:height="1dp" /> | ||
<corners android:radius="10dp" /> | ||
<solid android:color="@color/rv_divider" /> | ||
</shape> |
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
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
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
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