feat(status): translate poll options
This commit is contained in:
parent
24677ea239
commit
6c9db5ce0d
|
@ -493,7 +493,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
||||||
spoilerFooterIndex=spoilerItem.contentItems.indexOf(pollItems.get(pollItems.size()-1));
|
spoilerFooterIndex=spoilerItem.contentItems.indexOf(pollItems.get(pollItems.size()-1));
|
||||||
}
|
}
|
||||||
pollItems.clear();
|
pollItems.clear();
|
||||||
StatusDisplayItem.buildPollItems(itemID, this, poll, pollItems);
|
StatusDisplayItem.buildPollItems(itemID, this, poll, status, pollItems);
|
||||||
if(spoilerItem!=null){
|
if(spoilerItem!=null){
|
||||||
spoilerItem.contentItems.subList(spoilerFirstOptionIndex, spoilerFooterIndex+1).clear();
|
spoilerItem.contentItems.subList(spoilerFirstOptionIndex, spoilerFooterIndex+1).clear();
|
||||||
spoilerItem.contentItems.addAll(spoilerFirstOptionIndex, pollItems);
|
spoilerItem.contentItems.addAll(spoilerFirstOptionIndex, pollItems);
|
||||||
|
@ -858,17 +858,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
||||||
return;
|
return;
|
||||||
status.translation=result;
|
status.translation=result;
|
||||||
status.translationState=Status.TranslationState.SHOWN;
|
status.translationState=Status.TranslationState.SHOWN;
|
||||||
MediaGridStatusDisplayItem.Holder media=findHolderOfType(itemID, MediaGridStatusDisplayItem.Holder.class);
|
updateTranslation(itemID);
|
||||||
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());
|
|
||||||
}else{
|
|
||||||
notifyItemChanged(itemID, TextStatusDisplayItem.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -876,12 +866,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
||||||
if(getActivity()==null)
|
if(getActivity()==null)
|
||||||
return;
|
return;
|
||||||
status.translationState=Status.TranslationState.HIDDEN;
|
status.translationState=Status.TranslationState.HIDDEN;
|
||||||
TextStatusDisplayItem.Holder text=findHolderOfType(itemID, TextStatusDisplayItem.Holder.class);
|
updateTranslation(itemID);
|
||||||
if(text!=null){
|
|
||||||
text.updateTranslation(true);
|
|
||||||
}else{
|
|
||||||
notifyItemChanged(itemID, TextStatusDisplayItem.class);
|
|
||||||
}
|
|
||||||
new M3AlertDialogBuilder(getActivity())
|
new M3AlertDialogBuilder(getActivity())
|
||||||
.setTitle(R.string.error)
|
.setTitle(R.string.error)
|
||||||
.setMessage(R.string.translation_failed)
|
.setMessage(R.string.translation_failed)
|
||||||
|
@ -893,6 +878,10 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateTranslation(itemID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTranslation(String itemID) {
|
||||||
TextStatusDisplayItem.Holder text=findHolderOfType(itemID, TextStatusDisplayItem.Holder.class);
|
TextStatusDisplayItem.Holder text=findHolderOfType(itemID, TextStatusDisplayItem.Holder.class);
|
||||||
if(text!=null){
|
if(text!=null){
|
||||||
text.updateTranslation(true);
|
text.updateTranslation(true);
|
||||||
|
@ -905,9 +894,13 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
||||||
if (media!=null) {
|
if (media!=null) {
|
||||||
media.rebind();
|
media.rebind();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTranslation() {}
|
for(int i=0;i<list.getChildCount();i++){
|
||||||
|
if(list.getChildViewHolder(list.getChildAt(i)) instanceof PollOptionStatusDisplayItem.Holder item){
|
||||||
|
item.rebind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void rebuildAllDisplayItems(){
|
public void rebuildAllDisplayItems(){
|
||||||
displayItems.clear();
|
displayItems.clear();
|
||||||
|
|
|
@ -8,9 +8,19 @@ public class Translation extends BaseModel{
|
||||||
public String detectedSourceLanguage;
|
public String detectedSourceLanguage;
|
||||||
public String provider;
|
public String provider;
|
||||||
public MediaAttachment[] mediaAttachments;
|
public MediaAttachment[] mediaAttachments;
|
||||||
|
public PollTranslation poll;
|
||||||
|
|
||||||
public static class MediaAttachment {
|
public static class MediaAttachment {
|
||||||
public String id;
|
public String id;
|
||||||
public String description;
|
public String description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class PollTranslation {
|
||||||
|
public String id;
|
||||||
|
public PollOption[] options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PollOption {
|
||||||
|
public String title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.widget.TextView;
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
||||||
import org.joinmastodon.android.model.Poll;
|
import org.joinmastodon.android.model.Poll;
|
||||||
|
import org.joinmastodon.android.model.Status;
|
||||||
import org.joinmastodon.android.ui.OutlineProviders;
|
import org.joinmastodon.android.ui.OutlineProviders;
|
||||||
import org.joinmastodon.android.ui.text.HtmlParser;
|
import org.joinmastodon.android.ui.text.HtmlParser;
|
||||||
import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
|
import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
|
||||||
|
@ -23,6 +24,7 @@ import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
|
||||||
|
|
||||||
public class PollOptionStatusDisplayItem extends StatusDisplayItem{
|
public class PollOptionStatusDisplayItem extends StatusDisplayItem{
|
||||||
private CharSequence text;
|
private CharSequence text;
|
||||||
|
private CharSequence translatedText;
|
||||||
public final Poll.Option option;
|
public final Poll.Option option;
|
||||||
private CustomEmojiHelper emojiHelper=new CustomEmojiHelper();
|
private CustomEmojiHelper emojiHelper=new CustomEmojiHelper();
|
||||||
private boolean showResults;
|
private boolean showResults;
|
||||||
|
@ -30,12 +32,15 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
|
||||||
private boolean isMostVoted;
|
private boolean isMostVoted;
|
||||||
private final int optionIndex;
|
private final int optionIndex;
|
||||||
public final Poll poll;
|
public final Poll poll;
|
||||||
|
public final Status status;
|
||||||
|
|
||||||
public PollOptionStatusDisplayItem(String parentID, Poll poll, int optionIndex, BaseStatusListFragment parentFragment){
|
|
||||||
|
public PollOptionStatusDisplayItem(String parentID, Poll poll, int optionIndex, BaseStatusListFragment parentFragment, Status status){
|
||||||
super(parentID, parentFragment);
|
super(parentID, parentFragment);
|
||||||
this.optionIndex=optionIndex;
|
this.optionIndex=optionIndex;
|
||||||
option=poll.options.get(optionIndex);
|
option=poll.options.get(optionIndex);
|
||||||
this.poll=poll;
|
this.poll=poll;
|
||||||
|
this.status=status;
|
||||||
text=HtmlParser.parseCustomEmoji(option.title, poll.emojis);
|
text=HtmlParser.parseCustomEmoji(option.title, poll.emojis);
|
||||||
emojiHelper.setText(text);
|
emojiHelper.setText(text);
|
||||||
showResults=poll.isExpired() || poll.voted;
|
showResults=poll.isExpired() || poll.voted;
|
||||||
|
@ -84,7 +89,14 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBind(PollOptionStatusDisplayItem item){
|
public void onBind(PollOptionStatusDisplayItem item){
|
||||||
|
if (item.status.translation != null && item.status.translationState == Status.TranslationState.SHOWN) {
|
||||||
|
if(item.translatedText==null){
|
||||||
|
item.translatedText=item.status.translation.poll.options[item.optionIndex].title;
|
||||||
|
}
|
||||||
|
text.setText(item.translatedText);
|
||||||
|
} else {
|
||||||
text.setText(item.text);
|
text.setText(item.text);
|
||||||
|
}
|
||||||
percent.setVisibility(item.showResults ? View.VISIBLE : View.GONE);
|
percent.setVisibility(item.showResults ? View.VISIBLE : View.GONE);
|
||||||
itemView.setClickable(!item.showResults);
|
itemView.setClickable(!item.showResults);
|
||||||
icon.setImageDrawable(itemView.getContext().getDrawable(item.poll.multiple ?
|
icon.setImageDrawable(itemView.getContext().getDrawable(item.poll.multiple ?
|
||||||
|
|
|
@ -285,7 +285,7 @@ public abstract class StatusDisplayItem{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(statusForContent.poll!=null){
|
if(statusForContent.poll!=null){
|
||||||
buildPollItems(parentID, fragment, statusForContent.poll, contentItems);
|
buildPollItems(parentID, fragment, statusForContent.poll, status, contentItems);
|
||||||
}
|
}
|
||||||
if(statusForContent.card!=null && statusForContent.mediaAttachments.isEmpty()){
|
if(statusForContent.card!=null && statusForContent.mediaAttachments.isEmpty()){
|
||||||
contentItems.add(new LinkCardStatusDisplayItem(parentID, fragment, statusForContent));
|
contentItems.add(new LinkCardStatusDisplayItem(parentID, fragment, statusForContent));
|
||||||
|
@ -339,10 +339,10 @@ public abstract class StatusDisplayItem{
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void buildPollItems(String parentID, BaseStatusListFragment fragment, Poll poll, List<StatusDisplayItem> items){
|
public static void buildPollItems(String parentID, BaseStatusListFragment fragment, Poll poll, Status status, List<StatusDisplayItem> items){
|
||||||
int i=0;
|
int i=0;
|
||||||
for(Poll.Option opt:poll.options){
|
for(Poll.Option opt:poll.options){
|
||||||
items.add(new PollOptionStatusDisplayItem(parentID, poll, i, fragment));
|
items.add(new PollOptionStatusDisplayItem(parentID, poll, i, fragment, status));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
items.add(new PollFooterStatusDisplayItem(parentID, fragment, poll));
|
items.add(new PollFooterStatusDisplayItem(parentID, fragment, poll));
|
||||||
|
|
Loading…
Reference in New Issue