parent
4fd941febd
commit
5d1a86d472
@ -0,0 +1,41 @@ |
||||
package com.keylesspalace.tusky; |
||||
|
||||
import android.content.Context; |
||||
import android.content.res.Resources; |
||||
import android.graphics.Canvas; |
||||
import android.graphics.drawable.Drawable; |
||||
import android.support.v7.widget.RecyclerView; |
||||
import android.util.TypedValue; |
||||
import android.view.View; |
||||
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP; |
||||
|
||||
class ConversationLineItemDecoration extends RecyclerView.ItemDecoration { |
||||
private final Context mContext; |
||||
private final Drawable mDivider; |
||||
|
||||
public ConversationLineItemDecoration(Context context, Drawable divider) { |
||||
mContext = context; |
||||
mDivider = divider; |
||||
} |
||||
|
||||
@Override |
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { |
||||
// Fun fact: this method draws in pixels, but all layouts are in DP, so I'm using the divider's
|
||||
// own 2dp width to calculate what I want
|
||||
int dividerLeft = parent.getPaddingLeft() + mContext.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin); |
||||
int dividerRight = dividerLeft + mDivider.getIntrinsicWidth(); |
||||
|
||||
int childCount = parent.getChildCount(); |
||||
|
||||
for (int i = 0; i < childCount - 1; i++) { |
||||
View child = parent.getChildAt(i); |
||||
|
||||
int dividerTop = child.getTop() + (i == 0 ? mContext.getResources().getDimensionPixelSize(R.dimen.account_avatar_margin) : 0); |
||||
int dividerBottom = (i == childCount - 2 ? dividerTop + mContext.getResources().getDimensionPixelSize(R.dimen.account_avatar_margin) : child.getBottom()); |
||||
|
||||
mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom); |
||||
mDivider.draw(c); |
||||
} |
||||
} |
||||
} |
@ -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:width="2dp" /> |
||||
<solid android:color="@color/color_primary_dark_dark" /> |
||||
</shape> |
Loading…
Reference in new issue