Actually form thread lines properly in the thread view. Closes #57

This commit is contained in:
Vavassor 2017-08-03 22:30:37 -04:00
parent df07ab2600
commit af1d92c965
4 changed files with 72 additions and 15 deletions

View file

@ -15,6 +15,7 @@
package com.keylesspalace.tusky.adapter; package com.keylesspalace.tusky.adapter;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -129,6 +130,15 @@ public class ThreadAdapter extends RecyclerView.Adapter {
} }
} }
@Nullable
public StatusViewData getItem(int position) {
if (position != RecyclerView.NO_POSITION && position >= 0 && position < statuses.size()) {
return statuses.get(position);
} else {
return null;
}
}
public void setMediaPreviewEnabled(boolean enabled) { public void setMediaPreviewEnabled(boolean enabled) {
mediaPreviewEnabled = enabled; mediaPreviewEnabled = enabled;
} }

View file

@ -28,6 +28,7 @@ public final class ViewDataUtils {
.setCreatedAt(visibleStatus.createdAt) .setCreatedAt(visibleStatus.createdAt)
.setReblogsCount(visibleStatus.reblogsCount) .setReblogsCount(visibleStatus.reblogsCount)
.setFavouritesCount(visibleStatus.favouritesCount) .setFavouritesCount(visibleStatus.favouritesCount)
.setInReplyToId(visibleStatus.inReplyToId)
.setFavourited(visibleStatus.favourited) .setFavourited(visibleStatus.favourited)
.setReblogged(visibleStatus.reblogged) .setReblogged(visibleStatus.reblogged)
.setIsExpanded(false) .setIsExpanded(false)

View file

@ -22,32 +22,62 @@ import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.adapter.ThreadAdapter;
import com.keylesspalace.tusky.viewdata.StatusViewData;
public class ConversationLineItemDecoration extends RecyclerView.ItemDecoration { public class ConversationLineItemDecoration extends RecyclerView.ItemDecoration {
private final Context mContext; private final Context context;
private final Drawable mDivider; private final Drawable divider;
public ConversationLineItemDecoration(Context context, Drawable divider) { public ConversationLineItemDecoration(Context context, Drawable divider) {
mContext = context; this.context = context;
mDivider = divider; this.divider = divider;
} }
@Override @Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
int dividerLeft = parent.getPaddingLeft() + mContext.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin); int dividerLeft = parent.getPaddingLeft()
int dividerRight = dividerLeft + mDivider.getIntrinsicWidth(); + context.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin);
int dividerRight = dividerLeft + divider.getIntrinsicWidth();
int childCount = parent.getChildCount(); 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++) { for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i); View child = parent.getChildAt(i);
int dividerTop = child.getTop() + (i == 0 ? avatarMargin : 0); int position = parent.getChildAdapterPosition(child);
int dividerBottom = (i == childCount - 1 ? child.getTop() + avatarMargin : child.getBottom()); 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); divider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
mDivider.draw(c); divider.draw(c);
} }
} }
} }

View file

@ -33,6 +33,8 @@ public final class StatusViewData {
private final Date createdAt; private final Date createdAt;
private final String reblogsCount; private final String reblogsCount;
private final String favouritesCount; private final String favouritesCount;
@Nullable
private final String inReplyToId;
// I would rather have something else but it would be too much of a rewrite // I would rather have something else but it would be too much of a rewrite
@Nullable @Nullable
private final Status.Mention[] mentions; private final Status.Mention[] mentions;
@ -46,8 +48,9 @@ public final class StatusViewData {
String rebloggedAvatar, boolean sensitive, boolean isExpanded, String rebloggedAvatar, boolean sensitive, boolean isExpanded,
boolean isShowingSensitiveWarning, String userFullName, String nickname, boolean isShowingSensitiveWarning, String userFullName, String nickname,
String avatar, Date createdAt, String reblogsCount, String avatar, Date createdAt, String reblogsCount,
String favouritesCount, Status.Mention[] mentions, String senderId, String favouritesCount, String inReplyToId, Status.Mention[] mentions,
boolean rebloggingEnabled, Status.Application application) { String senderId, boolean rebloggingEnabled,
Status.Application application) {
this.id = id; this.id = id;
this.content = content; this.content = content;
this.reblogged = reblogged; this.reblogged = reblogged;
@ -66,6 +69,7 @@ public final class StatusViewData {
this.createdAt = createdAt; this.createdAt = createdAt;
this.reblogsCount = reblogsCount; this.reblogsCount = reblogsCount;
this.favouritesCount = favouritesCount; this.favouritesCount = favouritesCount;
this.inReplyToId = inReplyToId;
this.mentions = mentions; this.mentions = mentions;
this.senderId = senderId; this.senderId = senderId;
this.rebloggingEnabled = rebloggingEnabled; this.rebloggingEnabled = rebloggingEnabled;
@ -147,6 +151,11 @@ public final class StatusViewData {
return favouritesCount; return favouritesCount;
} }
@Nullable
public String getInReplyToId() {
return inReplyToId;
}
public String getSenderId() { public String getSenderId() {
return senderId; return senderId;
} }
@ -183,6 +192,7 @@ public final class StatusViewData {
private Date createdAt; private Date createdAt;
private String reblogsCount; private String reblogsCount;
private String favouritesCount; private String favouritesCount;
private String inReplyToId;
private Status.Mention[] mentions; private Status.Mention[] mentions;
private String senderId; private String senderId;
private boolean rebloggingEnabled; private boolean rebloggingEnabled;
@ -210,6 +220,7 @@ public final class StatusViewData {
createdAt = new Date(viewData.createdAt.getTime()); createdAt = new Date(viewData.createdAt.getTime());
reblogsCount = viewData.reblogsCount; reblogsCount = viewData.reblogsCount;
favouritesCount = viewData.favouritesCount; favouritesCount = viewData.favouritesCount;
inReplyToId = viewData.inReplyToId;
mentions = viewData.mentions == null ? null : viewData.mentions.clone(); mentions = viewData.mentions == null ? null : viewData.mentions.clone();
senderId = viewData.senderId; senderId = viewData.senderId;
rebloggingEnabled = viewData.rebloggingEnabled; rebloggingEnabled = viewData.rebloggingEnabled;
@ -306,6 +317,11 @@ public final class StatusViewData {
return this; return this;
} }
public Builder setInReplyToId(String inReplyToId) {
this.inReplyToId = inReplyToId;
return this;
}
public Builder setMentions(Status.Mention[] mentions) { public Builder setMentions(Status.Mention[] mentions) {
this.mentions = mentions; this.mentions = mentions;
return this; return this;
@ -330,8 +346,8 @@ public final class StatusViewData {
return new StatusViewData(id, content, reblogged, favourited, spoilerText, visibility, return new StatusViewData(id, content, reblogged, favourited, spoilerText, visibility,
attachments, rebloggedByUsername, rebloggedAvatar, isSensitive, isExpanded, attachments, rebloggedByUsername, rebloggedAvatar, isSensitive, isExpanded,
isShowingSensitiveContent, userFullName, nickname, avatar, createdAt, isShowingSensitiveContent, userFullName, nickname, avatar, createdAt,
reblogsCount, favouritesCount, mentions, senderId, rebloggingEnabled, reblogsCount, favouritesCount, inReplyToId, mentions, senderId,
application); rebloggingEnabled, application);
} }
} }
} }