feat: add alt text translation to previewlessMedia items
This commit is contained in:
parent
533032ca75
commit
b42862dd9b
|
@ -1027,6 +1027,11 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
|||
media.rebind();
|
||||
}
|
||||
|
||||
PreviewlessMediaGridStatusDisplayItem.Holder previewLessMedia=findHolderOfType(itemID, PreviewlessMediaGridStatusDisplayItem.Holder.class);
|
||||
if (previewLessMedia!=null) {
|
||||
previewLessMedia.rebind();
|
||||
}
|
||||
|
||||
for(int i=0;i<list.getChildCount();i++){
|
||||
if(list.getChildViewHolder(list.getChildAt(i)) instanceof PollOptionStatusDisplayItem.Holder item){
|
||||
item.rebind();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.joinmastodon.android.ui.displayitems;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
@ -9,6 +10,7 @@ import android.widget.LinearLayout;
|
|||
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
||||
import org.joinmastodon.android.model.Attachment;
|
||||
import org.joinmastodon.android.model.Status;
|
||||
import org.joinmastodon.android.model.Translation;
|
||||
import org.joinmastodon.android.ui.OutlineProviders;
|
||||
import org.joinmastodon.android.ui.PhotoLayoutHelper;
|
||||
import org.joinmastodon.android.ui.utils.PreviewlessMediaAttachmentViewController;
|
||||
|
@ -16,7 +18,12 @@ import org.joinmastodon.android.ui.views.FrameLayoutThatOnlyMeasuresFirstChild;
|
|||
import org.joinmastodon.android.utils.TypedObjectPool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
|
||||
import me.grishka.appkit.utils.V;
|
||||
|
@ -27,6 +34,7 @@ public class PreviewlessMediaGridStatusDisplayItem extends StatusDisplayItem{
|
|||
private PhotoLayoutHelper.TiledLayoutResult tiledLayout;
|
||||
private final TypedObjectPool<MediaGridStatusDisplayItem.GridItemType, PreviewlessMediaAttachmentViewController> viewPool;
|
||||
private final List<Attachment> attachments;
|
||||
private final Map<String, Pair<String, String>> translatedAttachments = new HashMap<>();
|
||||
private final ArrayList<ImageLoaderRequest> requests=new ArrayList<>();
|
||||
public final Status status;
|
||||
public String sensitiveTitle;
|
||||
|
@ -115,6 +123,25 @@ public class PreviewlessMediaGridStatusDisplayItem extends StatusDisplayItem{
|
|||
c.view.setOnClickListener(clickListener);
|
||||
c.view.setTag(i);
|
||||
controllers.add(c);
|
||||
|
||||
if (item.status.translation != null){
|
||||
if(item.status.translationState==Status.TranslationState.SHOWN){
|
||||
if(!item.translatedAttachments.containsKey(att.id)){
|
||||
Optional<Translation.MediaAttachment> translatedAttachment=Arrays.stream(item.status.translation.mediaAttachments).filter(mediaAttachment->mediaAttachment.id.equals(att.id)).findFirst();
|
||||
translatedAttachment.ifPresent(mediaAttachment->{
|
||||
item.translatedAttachments.put(mediaAttachment.id, new Pair<>(att.description, mediaAttachment.description));
|
||||
att.description=mediaAttachment.description;
|
||||
});
|
||||
}else{
|
||||
//SAFETY: must be non-null, as we check if the map contains the attachment before
|
||||
att.description=Objects.requireNonNull(item.translatedAttachments.get(att.id)).second;
|
||||
}
|
||||
}else{
|
||||
if (item.translatedAttachments.containsKey(att.id)) {
|
||||
att.description=Objects.requireNonNull(item.translatedAttachments.get(att.id)).first;
|
||||
}
|
||||
}
|
||||
}
|
||||
c.bind(att, item.status);
|
||||
i++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue