From be5f3b18af13e8d2d0f73f603dfbf335a93a0b2a Mon Sep 17 00:00:00 2001 From: FineFindus Date: Wed, 1 Nov 2023 19:52:45 +0100 Subject: [PATCH] feat(status): translate poll options --- .../fragments/BaseStatusListFragment.java | 29 +++++++++---------- .../android/model/Translation.java | 10 +++++++ .../PollOptionStatusDisplayItem.java | 16 ++++++++-- .../ui/displayitems/StatusDisplayItem.java | 6 ++-- 4 files changed, 40 insertions(+), 21 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 8655ac0e..e7da46ba 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -357,7 +357,7 @@ public abstract class BaseStatusListFragment exten List pollItems=displayItems.subList(firstOptionIndex, footerIndex+1); int prevSize=pollItems.size(); pollItems.clear(); - StatusDisplayItem.buildPollItems(itemID, this, poll, pollItems); + StatusDisplayItem.buildPollItems(itemID, this, poll, pollItems, status); if(prevSize!=pollItems.size()){ adapter.notifyItemRangeRemoved(firstOptionIndex, prevSize); adapter.notifyItemRangeInserted(firstOptionIndex, pollItems.size()); @@ -586,15 +586,7 @@ public abstract class BaseStatusListFragment exten return; status.translation=result; status.translationState=Status.TranslationState.SHOWN; - MediaGridStatusDisplayItem.Holder media=findHolderOfType(itemID, MediaGridStatusDisplayItem.Holder.class); - if (media!=null) { - media.rebind(); - } - TextStatusDisplayItem.Holder text=findHolderOfType(itemID, TextStatusDisplayItem.Holder.class); - if(text!=null){ - text.updateTranslation(true); - imgLoader.bindViewHolder((ImageLoaderRecyclerAdapter) list.getAdapter(), text, text.getAbsoluteAdapterPosition()); - } + updateTranslation(itemID); } @Override @@ -602,10 +594,7 @@ public abstract class BaseStatusListFragment exten if(getActivity()==null) return; status.translationState=Status.TranslationState.HIDDEN; - TextStatusDisplayItem.Holder text=findHolderOfType(itemID, TextStatusDisplayItem.Holder.class); - if(text!=null){ - text.updateTranslation(true); - } + updateTranslation(itemID); new M3AlertDialogBuilder(getActivity()) .setTitle(R.string.error) .setMessage(R.string.translation_failed) @@ -617,6 +606,10 @@ public abstract class BaseStatusListFragment exten } } } + updateTranslation(itemID); + } + + private void updateTranslation(String itemID) { TextStatusDisplayItem.Holder text=findHolderOfType(itemID, TextStatusDisplayItem.Holder.class); if(text!=null){ text.updateTranslation(true); @@ -627,9 +620,13 @@ public abstract class BaseStatusListFragment exten if (media!=null) { media.rebind(); } - } - private void updateTranslation() {} + for(int i=0;i items){ + public static void buildPollItems(String parentID, BaseStatusListFragment fragment, Poll poll, Status status, List items){ int i=0; for(Poll.Option opt:poll.options){ - items.add(new PollOptionStatusDisplayItem(parentID, poll, i, fragment)); + items.add(new PollOptionStatusDisplayItem(parentID, poll, i, fragment, status)); i++; } items.add(new PollFooterStatusDisplayItem(parentID, fragment, poll));