Actually form thread lines properly in the thread view. Closes #57
This commit is contained in:
parent
df07ab2600
commit
af1d92c965
4 changed files with 72 additions and 15 deletions
|
|
@ -22,32 +22,62 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.View;
|
||||
|
||||
import com.keylesspalace.tusky.R;
|
||||
import com.keylesspalace.tusky.adapter.ThreadAdapter;
|
||||
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
||||
|
||||
public class ConversationLineItemDecoration extends RecyclerView.ItemDecoration {
|
||||
private final Context mContext;
|
||||
private final Drawable mDivider;
|
||||
private final Context context;
|
||||
private final Drawable divider;
|
||||
|
||||
public ConversationLineItemDecoration(Context context, Drawable divider) {
|
||||
mContext = context;
|
||||
mDivider = divider;
|
||||
this.context = context;
|
||||
this.divider = divider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
int dividerLeft = parent.getPaddingLeft() + mContext.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin);
|
||||
int dividerRight = dividerLeft + mDivider.getIntrinsicWidth();
|
||||
int dividerLeft = parent.getPaddingLeft()
|
||||
+ context.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin);
|
||||
int dividerRight = dividerLeft + divider.getIntrinsicWidth();
|
||||
|
||||
int childCount = parent.getChildCount();
|
||||
int avatarMargin = mContext.getResources().getDimensionPixelSize(R.dimen.account_avatar_margin);
|
||||
int avatarMargin = context.getResources()
|
||||
.getDimensionPixelSize(R.dimen.account_avatar_margin);
|
||||
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
View child = parent.getChildAt(i);
|
||||
|
||||
int dividerTop = child.getTop() + (i == 0 ? avatarMargin : 0);
|
||||
int dividerBottom = (i == childCount - 1 ? child.getTop() + avatarMargin : child.getBottom());
|
||||
int position = parent.getChildAdapterPosition(child);
|
||||
ThreadAdapter adapter = (ThreadAdapter) parent.getAdapter();
|
||||
StatusViewData current = adapter.getItem(position);
|
||||
int dividerTop, dividerBottom;
|
||||
if (current != null) {
|
||||
StatusViewData above = adapter.getItem(position - 1);
|
||||
if (above != null && above.getId().equals(current.getInReplyToId())) {
|
||||
dividerTop = child.getTop();
|
||||
} else {
|
||||
dividerTop = child.getTop() + avatarMargin;
|
||||
}
|
||||
StatusViewData below = adapter.getItem(position + 1);
|
||||
if (below != null && current.getId().equals(below.getInReplyToId())) {
|
||||
dividerBottom = child.getBottom();
|
||||
} else {
|
||||
dividerBottom = child.getTop() + avatarMargin;
|
||||
}
|
||||
} else {
|
||||
dividerTop = child.getTop();
|
||||
if (i == 0) {
|
||||
dividerTop += avatarMargin;
|
||||
}
|
||||
if (i == childCount - 1) {
|
||||
dividerBottom = child.getTop() + avatarMargin;
|
||||
} else {
|
||||
dividerBottom = child.getBottom();
|
||||
}
|
||||
}
|
||||
|
||||
mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
|
||||
mDivider.draw(c);
|
||||
divider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
|
||||
divider.draw(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue