From 6da85a288a051ffa45d08817246002e2ca762795 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 23 Jun 2023 01:08:41 +0200 Subject: [PATCH] also auto-reveal ancestors closes sk22#603 --- .../android/fragments/ThreadFragment.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) 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 d72b5eadb3..774f0593e8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java @@ -17,7 +17,6 @@ import org.joinmastodon.android.events.StatusCreatedEvent; import org.joinmastodon.android.events.StatusUpdatedEvent; import org.joinmastodon.android.model.Account; -import org.joinmastodon.android.model.Filter; import org.joinmastodon.android.model.FilterContext; import org.joinmastodon.android.model.Status; import org.joinmastodon.android.model.StatusContext; @@ -153,6 +152,26 @@ public void onError(ErrorResponse error) {} }).exec(accountID); } + private void restoreStatusStates(List newData, Map oldData) { + for (Status s : newData) { + if (s == mainStatus) continue; + Status oldStatus = oldData == null ? null : oldData.get(s.id); + // restore previous spoiler/filter revealed states when refreshing + if (oldStatus != null) { + s.spoilerRevealed = oldStatus.spoilerRevealed; + s.sensitiveRevealed = oldStatus.sensitiveRevealed; + s.filterRevealed = oldStatus.filterRevealed; + } + if (GlobalUserPreferences.autoRevealEqualSpoilers != AutoRevealMode.NEVER && + s.spoilerText != null && + s.spoilerText.equals(mainStatus.spoilerText)) { + if (GlobalUserPreferences.autoRevealEqualSpoilers == AutoRevealMode.DISCUSSIONS || Objects.equals(mainStatus.account.id, s.account.id)) { + s.spoilerRevealed = mainStatus.spoilerRevealed; + } + } + } + + } protected void maybeApplyContext() { if (!transitionFinished || result == null || getContext() == null) return; Map oldData = null; @@ -171,6 +190,8 @@ protected void maybeApplyContext() { result.descendants=filterStatuses(result.descendants); result.ancestors=filterStatuses(result.ancestors); + restoreStatusStates(result.descendants, oldData); + restoreStatusStates(result.ancestors, oldData); for (NeighborAncestryInfo i : mapNeighborhoodAncestry(mainStatus, result)) { ancestryMap.put(i.status.id, i); @@ -180,26 +201,9 @@ protected void maybeApplyContext() { footerProgress.setVisibility(View.GONE); data.addAll(result.descendants); - for (Status s : data) { - if (s == mainStatus) continue; - Status oldStatus = oldData == null ? null : oldData.get(s.id); - // restore previous spoiler/filter revealed states when refreshing - if (oldStatus != null) { - s.spoilerRevealed = oldStatus.spoilerRevealed; - s.sensitiveRevealed = oldStatus.sensitiveRevealed; - s.filterRevealed = oldStatus.filterRevealed; - } - if (GlobalUserPreferences.autoRevealEqualSpoilers != AutoRevealMode.NEVER && - s.spoilerText != null && - s.spoilerText.equals(mainStatus.spoilerText)) { - if (GlobalUserPreferences.autoRevealEqualSpoilers == AutoRevealMode.DISCUSSIONS || Objects.equals(mainStatus.account.id, s.account.id)) { - s.spoilerRevealed = mainStatus.spoilerRevealed; - } - } - } - int prevCount=displayItems.size(); onAppendItems(result.descendants); + int count=displayItems.size(); if(!refreshing) adapter.notifyItemRangeInserted(prevCount, count-prevCount); @@ -226,7 +230,6 @@ protected void maybeApplyContext() { result = null; } - protected Object maybeApplyMainStatus() { if (updatedStatus == null || !contextInitiallyRendered) return null;