package org.wikipedia.feed.mostread;

import android.net.Uri;
import android.text.TextUtils;

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

import org.wikipedia.dataclient.WikiSite;
import org.wikipedia.dataclient.page.PageSummary;
import org.wikipedia.feed.model.Card;
import org.wikipedia.feed.model.CardType;
import org.wikipedia.page.PageTitle;

public class MostReadItemCard extends Card {
    @NonNull private final PageSummary page;
    @NonNull private final WikiSite wiki;

    MostReadItemCard(@NonNull PageSummary page, @NonNull WikiSite wiki) {
        this.page = page;
        this.wiki = wiki;
    }

    @NonNull @Override public String title() {
        return page.getDisplayTitle();
    }

    @Nullable @Override public String subtitle() {
        return page.getDescription();
    }

    @Nullable @Override public Uri image() {
        String thumbUrl = page.getThumbnailUrl();
        return thumbUrl != null ? Uri.parse(thumbUrl) : null;
    }

    @NonNull @Override public CardType type() {
        return CardType.MOST_READ_ITEM;
    }

    @NonNull public PageTitle pageTitle() {
        PageTitle title = new PageTitle(page.getApiTitle(), wiki);
        if (page.getThumbnailUrl() != null) {
            title.setThumbUrl(page.getThumbnailUrl());
        }
        if (!TextUtils.isEmpty(page.getDescription())) {
            title.setDescription(page.getDescription());
        }
        return title;
    }
}

@@ -58,39 +58,8 @@
 Uri;
-%0Aimport android.text.TextUtils;
 %0A%0Aim
@@ -1110,322 +1110,38 @@
     
-PageTitle title = new PageTitle(page.getApiTitle(), wiki);%0A        if (page.getThumbnailUrl() != null) %7B%0A            title.setThumbUrl(page.getThumbnailUrl());%0A        %7D%0A        if (!TextUtils.isEmpty(page.getDescription())) %7B%0A            title.setDescription(page.getDescription());%0A        %7D%0A        return title
+return page.getPageTitle(wiki)
 ;%0A  

set PageTitle correctly to show the correct displayTitle