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

main
Vavassor 7 years ago
parent 681e68b487
commit 81bcd8dbd1
  1. 10
      app/src/main/java/com/keylesspalace/tusky/adapter/ThreadAdapter.java
  2. 1
      app/src/main/java/com/keylesspalace/tusky/util/ViewDataUtils.java
  3. 52
      app/src/main/java/com/keylesspalace/tusky/view/ConversationLineItemDecoration.java
  4. 24
      app/src/main/java/com/keylesspalace/tusky/viewdata/StatusViewData.java

@ -15,6 +15,7 @@
package com.keylesspalace.tusky.adapter;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
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) {
mediaPreviewEnabled = enabled;
}

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

@ -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);
}
}
}

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

Loading…
Cancel
Save