package org.wikipedia.gallery;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.gson.annotations.SerializedName;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

@SuppressWarnings("unused")
public class MediaListItem implements Serializable {
    @Nullable private String title;
    @SerializedName("section_id") private int sectionId;
    @Nullable private String type;
    @Nullable private TextInfo caption;
    private boolean showInGallery;
    @Nullable @SerializedName("srcset") private List<ImageSrcSet> srcSets;

    public MediaListItem() {
    }

    public MediaListItem(@NonNull String title) {
        this.title = title;
    }

    @NonNull
    public String getType() {
        return StringUtils.defaultString(type);
    }

    @Nullable
    public TextInfo getCaption() {
        return caption;
    }

    public boolean showInGallery() {
        return showInGallery;
    }

    @NonNull
    public String getTitle() {
        return StringUtils.defaultString(title);
    }

    @NonNull
    public List<ImageSrcSet> getSrcSets() {
        return srcSets != null ? srcSets : Collections.emptyList();
    }

    public class ImageSrcSet implements Serializable {
        @Nullable private String src;
        @Nullable private String scale;

        @NonNull
        public String getSrc() {
            return StringUtils.defaultString(src);
        }

        @NonNull
        public String getScale() {
            return StringUtils.defaultString(scale);
        }
    }
}

@@ -278,16 +278,80 @@
 il.List;
+%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0A@Suppr
@@ -1301,32 +1301,947 @@
 yList();%0A    %7D%0A%0A
+    @NonNull%0A    public String getImageUrl(int preferredSize) %7B%0A        Pattern pattern = Pattern.compile(%22/(%5C%5Cd+)px-%22);%0A%0A        String imageUrl = getSrcSets().get(getSrcSets().size() - 1).getSrc();%0A        int previousSize = 0;%0A        for (ImageSrcSet srcSet : getSrcSets()) %7B%0A            Matcher matcher = pattern.matcher(srcSet.getSrc());%0A            if (matcher.find() && matcher.group(1) != null) %7B%0A                int currentSize = Integer.parseInt(matcher.group(1));%0A%0A                if (currentSize == preferredSize) %7B%0A                    imageUrl = srcSet.getSrc();%0A                    break;%0A                %7D else if (preferredSize %3C currentSize && preferredSize %3E previousSize) %7B%0A                    imageUrl = srcSet.getSrc();%0A                    break;%0A                %7D%0A                previousSize = currentSize;%0A            %7D%0A        %7D%0A%0A        return StringUtils.defaultString(imageUrl);%0A    %7D%0A%0A
     public class
@@ -2404,24 +2404,24 @@
  getSrc() %7B%0A
+
             
@@ -2472,124 +2472,8 @@
    %7D
-%0A%0A        @NonNull%0A        public String getScale() %7B%0A            return StringUtils.defaultString(scale);%0A        %7D
 %0A   

Create a logic to pick best image url from srcset