From d43cbe642ff153752b6e469461ee0ef80bf404a1 Mon Sep 17 00:00:00 2001 From: sk Date: Wed, 18 Jan 2023 11:39:49 +0100 Subject: [PATCH] disable translating scheduled posts closes sk22#318 --- .../android/fragments/AnnouncementsFragment.java | 2 +- .../android/fragments/ScheduledStatusListFragment.java | 2 +- .../android/ui/displayitems/StatusDisplayItem.java | 6 +++++- .../android/ui/displayitems/TextStatusDisplayItem.java | 7 +++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/AnnouncementsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/AnnouncementsFragment.java index 74ea115e8..385d3464c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/AnnouncementsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/AnnouncementsFragment.java @@ -66,7 +66,7 @@ public class AnnouncementsFragment extends BaseStatusListFragment instanceUser.avatar = instanceUser.avatarStatic = instance.thumbnail; instanceUser.emojis = List.of(); Status fakeStatus = a.toStatus(); - TextStatusDisplayItem textItem = new TextStatusDisplayItem(a.id, HtmlParser.parse(a.content, a.emojis, a.mentions, a.tags, accountID), this, fakeStatus); + TextStatusDisplayItem textItem = new TextStatusDisplayItem(a.id, HtmlParser.parse(a.content, a.emojis, a.mentions, a.tags, accountID), this, fakeStatus, true); textItem.textSelectable = true; return List.of( HeaderStatusDisplayItem.fromAnnouncement(a, fakeStatus, instanceUser, this, accountID, this::onMarkAsRead), diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ScheduledStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ScheduledStatusListFragment.java index 35525a406..4a17d51a4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ScheduledStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ScheduledStatusListFragment.java @@ -69,7 +69,7 @@ public class ScheduledStatusListFragment extends BaseStatusListFragment buildDisplayItems(ScheduledStatus s) { - return StatusDisplayItem.buildItems(this, s.toStatus(), accountID, s, knownAccounts, false, false, null); + return StatusDisplayItem.buildItems(this, s.toStatus(), accountID, s, knownAccounts, false, false, null, true); } @Override 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 3bed895d5..43f50020e 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 @@ -77,6 +77,10 @@ public abstract class StatusDisplayItem{ } public static ArrayList buildItems(BaseStatusListFragment fragment, Status status, String accountID, DisplayItemsParent parentObject, Map knownAccounts, boolean inset, boolean addFooter, Notification notification){ + return buildItems(fragment, status, accountID, parentObject, knownAccounts, inset, addFooter, notification, false); + } + + public static ArrayList buildItems(BaseStatusListFragment fragment, Status status, String accountID, DisplayItemsParent parentObject, Map knownAccounts, boolean inset, boolean addFooter, Notification notification, boolean disableTranslate){ String parentID=parentObject.getID(); ArrayList items=new ArrayList<>(); Status statusForContent=status.getContentStatus(); @@ -100,7 +104,7 @@ public abstract class StatusDisplayItem{ HeaderStatusDisplayItem header; items.add(header=new HeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID, statusForContent, null, notification, scheduledStatus)); if(!TextUtils.isEmpty(statusForContent.content)) - items.add(new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID), fragment, statusForContent)); + items.add(new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID), fragment, statusForContent, disableTranslate)); else header.needBottomPadding=true; List imageAttachments=statusForContent.mediaAttachments.stream().filter(att->att.type.isImage()).collect(Collectors.toList()); 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 8501abd2e..14a0a518b 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 @@ -40,14 +40,16 @@ public class TextStatusDisplayItem extends StatusDisplayItem{ private CharSequence parsedSpoilerText; public boolean textSelectable; public final Status status; + public boolean disableTranslate; public boolean translated = false; public TranslatedStatus translation = null; private AccountSession session; - public TextStatusDisplayItem(String parentID, CharSequence text, BaseStatusListFragment parentFragment, Status status){ + public TextStatusDisplayItem(String parentID, CharSequence text, BaseStatusListFragment parentFragment, Status status, boolean disableTranslate){ super(parentID, parentFragment); this.text=text; this.status=status; + this.disableTranslate=disableTranslate; emojiHelper.setText(text); if(!TextUtils.isEmpty(status.spoilerText)){ parsedSpoilerText=HtmlParser.parseCustomEmoji(status.spoilerText, status.emojis); @@ -143,7 +145,8 @@ public class TextStatusDisplayItem extends StatusDisplayItem{ } Instance instanceInfo = AccountSessionManager.getInstance().getInstanceInfo(item.session.domain); - boolean translateEnabled = instanceInfo.v2 != null && instanceInfo.v2.configuration.translation != null && instanceInfo.v2.configuration.translation.enabled; + boolean translateEnabled = !item.disableTranslate && instanceInfo.v2 != null && + instanceInfo.v2.configuration.translation != null && instanceInfo.v2.configuration.translation.enabled; translateWrap.setVisibility(translateEnabled && !item.status.visibility.isLessVisibleThan(StatusPrivacy.UNLISTED) &&