From fb8764bcd732c15e6f6584bd6c73ca51dd00efb7 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 2 Jun 2023 22:08:03 +0200 Subject: [PATCH] refactor ancestry, fix case regarding reply line fix case where reply line was removed despite having no direct ancestor --- .../fragments/BaseStatusListFragment.java | 6 +++--- .../android/fragments/ThreadFragment.java | 6 ++++-- .../displayitems/FooterStatusDisplayItem.java | 4 ++-- .../ui/displayitems/StatusDisplayItem.java | 21 ++++++------------- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 9a636c3cf..ef8a420d1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -357,10 +357,10 @@ public abstract class BaseStatusListFragment exten if (firstIndex < 0) firstIndex = i; lastIndex = i; StatusDisplayItem item = h.getItem(); - hasDescendant = item.hasDescendantNeighbor(); + hasDescendant = item.hasDescendantNeighbor; // no for direct descendants because main status (right above) is // being displayed with an extended footer - no connected layout - hasAncestor = item.hasAncestoringNeighbor() && !item.isDirectDescendant; + hasAncestor = item.hasAncestoringNeighbor && !item.isDirectDescendant; list.getDecoratedBoundsWithMargins(child, tmpRect); outRect.left=Math.min(outRect.left, tmpRect.left); outRect.top=Math.min(outRect.top, tmpRect.top); @@ -797,7 +797,7 @@ public abstract class BaseStatusListFragment exten RecyclerView.ViewHolder siblingHolder=parent.getChildViewHolder(bottomSibling); if(holder instanceof StatusDisplayItem.Holder ih && siblingHolder instanceof StatusDisplayItem.Holder sh && (!ih.getItemID().equals(sh.getItemID()) || sh instanceof ExtendedFooterStatusDisplayItem.Holder) && ih.getItem().getType()!=StatusDisplayItem.Type.GAP){ - if (!ih.getItem().isMainStatus && ih.getItem().hasDescendantNeighbor()) continue; + if (!ih.getItem().isMainStatus && ih.getItem().hasDescendantNeighbor) continue; drawDivider(child, bottomSibling, holder, siblingHolder, parent, c, dividerPaint); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java index 256af6401..d25ad6765 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java @@ -92,7 +92,8 @@ public class ThreadFragment extends StatusListFragment implements ProvidesAssist NeighborAncestryInfo ancestryInfo = ancestryMap.get(s.id); if (ancestryInfo != null) { item.setAncestryInfo( - ancestryInfo, + ancestryInfo.hasDescendantNeighbor(), + ancestryInfo.hasAncestoringNeighbor(), s.id.equals(mainStatus.id), ancestryInfo.getAncestoringNeighbor() .map(ancestor -> ancestor.id.equals(mainStatus.id)) @@ -100,7 +101,8 @@ public class ThreadFragment extends StatusListFragment implements ProvidesAssist ); } - if (item instanceof ReblogOrReplyLineStatusDisplayItem && !item.isDirectDescendant) { + if (item instanceof ReblogOrReplyLineStatusDisplayItem && + (!item.isDirectDescendant && item.hasAncestoringNeighbor)) { deleteTheseItems.add(i); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java index ad423b8a7..75b24fc45 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java @@ -136,7 +136,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{ bindButton(favorite, item.status.favouritesCount); // in thread view, direct descendant posts display one direct reply to themselves, // hence in that case displaying whether there is another reply - int compareTo = item.isMainStatus || !item.hasDescendantNeighbor() ? 0 : 1; + int compareTo = item.isMainStatus || !item.hasDescendantNeighbor ? 0 : 1; reply.setSelected(item.status.repliesCount > compareTo); boost.setSelected(item.status.reblogged); favorite.setSelected(item.status.favourited); @@ -147,7 +147,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{ int nextPos = getAbsoluteAdapterPosition() + 1; boolean nextIsWarning = item.parentFragment.getDisplayItems().size() > nextPos && item.parentFragment.getDisplayItems().get(nextPos) instanceof WarningFilteredStatusDisplayItem; - boolean condenseBottom = !item.isMainStatus && item.hasDescendantNeighbor() && + boolean condenseBottom = !item.isMainStatus && item.hasDescendantNeighbor && !nextIsWarning; ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) itemView.getLayoutParams(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 3d2e3e161..c55c4f925 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -47,29 +47,20 @@ public abstract class StatusDisplayItem{ public final BaseStatusListFragment parentFragment; public boolean inset; public int index; - private ThreadFragment.NeighborAncestryInfo ancestryInfo; public boolean + hasDescendantNeighbor = false, + hasAncestoringNeighbor = false, isMainStatus = true, isDirectDescendant = false; - public boolean hasDescendantNeighbor() { - return Optional.ofNullable(ancestryInfo) - .map(ThreadFragment.NeighborAncestryInfo::hasDescendantNeighbor) - .orElse(false); - } - - public boolean hasAncestoringNeighbor() { - return Optional.ofNullable(ancestryInfo) - .map(ThreadFragment.NeighborAncestryInfo::hasAncestoringNeighbor) - .orElse(false); - } - public void setAncestryInfo( - ThreadFragment.NeighborAncestryInfo ancestryInfo, + boolean hasDescendantNeighbor, + boolean hasAncestoringNeighbor, boolean isMainStatus, boolean isDirectDescendant ) { - this.ancestryInfo = ancestryInfo; + this.hasDescendantNeighbor = hasDescendantNeighbor; + this.hasAncestoringNeighbor = hasAncestoringNeighbor; this.isMainStatus = isMainStatus; this.isDirectDescendant = isDirectDescendant; }