From 1832de3aab2cc868851f0add17a5be94700797ab Mon Sep 17 00:00:00 2001 From: Jacocococo Date: Fri, 29 Dec 2023 23:25:06 +0100 Subject: [PATCH 1/3] Fix issues with expandable quoted statuses --- .../android/fragments/BaseStatusListFragment.java | 14 +++++++++----- .../android/fragments/ThreadFragment.java | 8 ++++++++ .../ui/displayitems/HeaderStatusDisplayItem.java | 2 +- .../ui/displayitems/TextStatusDisplayItem.java | 4 ++-- 4 files changed, 20 insertions(+), 8 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 590c98c12e..a48e055e86 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -631,19 +631,23 @@ protected void toggleSpoiler(Status status, boolean isForQuote, String itemID){ list.invalidateItemDecorations(); } - public void onEnableExpandable(TextStatusDisplayItem.Holder holder, boolean expandable) { + public void onEnableExpandable(TextStatusDisplayItem.Holder holder, boolean expandable, boolean isForQuote) { Status s=holder.getItem().status; if(s.textExpandable!=expandable && list!=null) { s.textExpandable=expandable; - HeaderStatusDisplayItem.Holder header=findHolderOfType(holder.getItemID(), HeaderStatusDisplayItem.Holder.class); + List headers=findAllHoldersOfType(holder.getItemID(), HeaderStatusDisplayItem.Holder.class); + HeaderStatusDisplayItem.Holder header=headers.size() > 1 && isForQuote ? headers.get(1) : headers.get(0); if(header!=null) header.bindCollapseButton(); } } - public void onToggleExpanded(Status status, String itemID) { + public void onToggleExpanded(Status status, boolean isForQuote, String itemID) { status.textExpanded = !status.textExpanded; - notifyItemChanged(itemID, TextStatusDisplayItem.class); - HeaderStatusDisplayItem.Holder header=findHolderOfType(itemID, HeaderStatusDisplayItem.Holder.class); + List textItems = findAllHoldersOfType(itemID, TextStatusDisplayItem.Holder.class); + TextStatusDisplayItem.Holder text = textItems.size() > 1 && isForQuote ? textItems.get(1) : textItems.get(0); + adapter.notifyItemChanged(text.getAbsoluteAdapterPosition()); + List headers=findAllHoldersOfType(itemID, HeaderStatusDisplayItem.Holder.class); + HeaderStatusDisplayItem.Holder header=headers.size() > 1 && isForQuote ? headers.get(1) : headers.get(0); if(header!=null) header.animateExpandToggle(); else notifyItemChanged(itemID, HeaderStatusDisplayItem.class); } 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 e85cad37b2..6e5a331f66 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java @@ -181,6 +181,7 @@ private void restoreStatusStates(List newData, Map oldDa s.spoilerRevealed = oldStatus.spoilerRevealed; s.sensitiveRevealed = oldStatus.sensitiveRevealed; s.filterRevealed = oldStatus.filterRevealed; + s.textExpanded = oldStatus.textExpanded; } if (GlobalUserPreferences.autoRevealEqualSpoilers != AutoRevealMode.NEVER && s.spoilerText != null && @@ -257,6 +258,13 @@ protected Object maybeApplyMainStatus() { updatedStatus.filterRevealed = mainStatus.filterRevealed; updatedStatus.spoilerRevealed = mainStatus.spoilerRevealed; updatedStatus.sensitiveRevealed = mainStatus.sensitiveRevealed; + updatedStatus.textExpanded = mainStatus.textExpanded; + if(updatedStatus.quote!=null && mainStatus.quote!=null){ + updatedStatus.quote.filterRevealed = mainStatus.quote.filterRevealed; + updatedStatus.quote.spoilerRevealed = mainStatus.quote.spoilerRevealed; + updatedStatus.quote.sensitiveRevealed = mainStatus.quote.sensitiveRevealed; + updatedStatus.quote.textExpanded = mainStatus.quote.textExpanded; + } // returning fired event object to facilitate testing Object event; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index 0d346608cf..0e51293df8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -173,7 +173,7 @@ protected Holder(Activity activity, @LayoutRes int layout, ViewGroup parent){ fragment.removeNotification(item.notification); } })); - collapseBtn.setOnClickListener(l -> item.parentFragment.onToggleExpanded(item.status, getItemID())); + collapseBtn.setOnClickListener(l -> item.parentFragment.onToggleExpanded(item.status, item.isForQuote, getItemID())); optionsMenu=new PopupMenu(activity, more); optionsMenu.inflate(R.menu.post); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java index ecbf2f3d5e..0f0b3be199 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java @@ -98,7 +98,7 @@ public Holder(Activity activity, ViewGroup parent){ float textCollapsedHeight=activity.getResources().getDimension(R.dimen.text_collapsed_height); collapseParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) textCollapsedHeight); wrapParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - readMore.setOnClickListener(v -> item.parentFragment.onToggleExpanded(item.status, getItemID())); + readMore.setOnClickListener(v -> item.parentFragment.onToggleExpanded(item.status, item.isForQuote, getItemID())); } @Override @@ -152,7 +152,7 @@ public void onBind(TextStatusDisplayItem item){ if (GlobalUserPreferences.collapseLongPosts && !item.status.textExpandable) { boolean tooBig = text.getMeasuredHeight() > textMaxHeight; boolean expandable = tooBig && !item.status.hasSpoiler(); - item.parentFragment.onEnableExpandable(Holder.this, expandable); + item.parentFragment.onEnableExpandable(Holder.this, expandable, item.isForQuote); } boolean expandButtonShown=item.status.textExpandable && !item.status.textExpanded; From c6081fb4d4667e17ae04f1b1f3324a477b110cc5 Mon Sep 17 00:00:00 2001 From: Jacocococo Date: Fri, 29 Dec 2023 23:27:14 +0100 Subject: [PATCH 2/3] Let quoted posts appear in notifications --- .../joinmastodon/android/ui/displayitems/StatusDisplayItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4e6193cebe..a1ecb0642c 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 @@ -295,7 +295,7 @@ public static ArrayList buildItems(BaseStatusListFragment if(statusForContent.card!=null && statusForContent.mediaAttachments.isEmpty() && statusForContent.quote==null && !statusForContent.card.isHashtagUrl(statusForContent.url)){ contentItems.add(new LinkCardStatusDisplayItem(parentID, fragment, statusForContent)); } - if(statusForContent.quote!=null && !(parentObject instanceof Notification)){ + if(statusForContent.quote!=null && (flags & FLAG_INSET)==0){ if(!statusForContent.mediaAttachments.isEmpty() && statusForContent.poll==null) // add spacing if immediately preceded by attachment contentItems.add(new DummyStatusDisplayItem(parentID, fragment)); contentItems.addAll(buildItems(fragment, statusForContent.quote, accountID, parentObject, knownAccounts, filterContext, FLAG_NO_FOOTER | FLAG_INSET | FLAG_NO_EMOJI_REACTIONS | FLAG_IS_FOR_QUOTE)); From 962c094f7e3162263d19a7974535ddbfd2c9a36f Mon Sep 17 00:00:00 2001 From: Jacocococo Date: Fri, 29 Dec 2023 23:34:40 +0100 Subject: [PATCH 3/3] Properly hide content warning in quoted post --- .../joinmastodon/android/fragments/BaseStatusListFragment.java | 2 ++ 1 file changed, 2 insertions(+) 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 a48e055e86..b7b4809fbb 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -619,6 +619,8 @@ protected void toggleSpoiler(Status status, boolean isForQuote, String itemID){ displayItems.addAll(index+1, spoilerItem.contentItems); adapter.notifyItemRangeInserted(index+1, spoilerItem.contentItems.size()); }else{ + if(spoilers.size()>1 && !isForQuote && status.quote.spoilerRevealed) + toggleSpoiler(status.quote, true, itemID); displayItems.subList(index+1, index+1+spoilerItem.contentItems.size()).clear(); adapter.notifyItemRangeRemoved(index+1, spoilerItem.contentItems.size()); }