jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/390853 )
Change subject: Use displaytitle from server for link previews ...................................................................... Use displaytitle from server for link previews Prevents article title display inconsistencies by using the displaytitle provided by the server response (and deferring adding the title to the link preview until then). In practice, the delay should be barely user- noticeable. If the summary request fails, the app falls back to the old behavior in the error callback. This should also have the desirable effect of showing the true article title in previews, with any redirects resolved. Bug: T149429 Change-Id: I9030f5871250505e0e0399c94f2b857c30204db5 --- M app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwPageService.java M app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwQueryPageSummary.java M app/src/main/java/org/wikipedia/dataclient/page/PageSummary.java M app/src/main/java/org/wikipedia/dataclient/restbase/page/RbPageSummary.java M app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java 5 files changed, 42 insertions(+), 14 deletions(-) Approvals: jenkins-bot: Verified Cooltey: Looks good to me, approved diff --git a/app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwPageService.java b/app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwPageService.java index 03cb652..f2e2844 100644 --- a/app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwPageService.java +++ b/app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwPageService.java @@ -37,8 +37,8 @@ */ @Headers("x-analytics: preview=1") @GET("w/api.php?action=query&format=json&formatversion=2&redirects=&converttitles=" - + "&prop=extracts%7Cpageimages&exsentences=5&explaintext=&piprop=thumbnail%7Cname" - + "&pilicense=any&pithumbsize=" + Constants.PREFERRED_THUMB_SIZE) + + "&prop=extracts%7Cpageimages%7Cpageprops&exsentences=5&piprop=thumbnail%7Cname" + + "&pilicense=any&explaintext=&pithumbsize=" + Constants.PREFERRED_THUMB_SIZE) @NonNull Call<MwQueryPageSummary> summary(@NonNull @Query("titles") String title); /** diff --git a/app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwQueryPageSummary.java b/app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwQueryPageSummary.java index ba2723f..f670ff7 100644 --- a/app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwQueryPageSummary.java +++ b/app/src/main/java/org/wikipedia/dataclient/mwapi/page/MwQueryPageSummary.java @@ -29,6 +29,11 @@ } @Override @Nullable + public String getDisplayTitle() { + return getFirstPage() == null ? null : getFirstPage().getDisplayTitle(); + } + + @Override @Nullable public String getExtract() { return getFirstPage() == null ? null : getFirstPage().extract; } @@ -49,6 +54,7 @@ private static class MwPage { @SuppressWarnings("unused") @Nullable private String title; + @SuppressWarnings("unused") @Nullable private PageProps pageprops; @SuppressWarnings("unused") @Nullable private String extract; @SuppressWarnings("unused") @Nullable private Thumb thumbnail; @@ -56,16 +62,31 @@ public String getThumbnailUrl() { return thumbnail == null ? null : thumbnail.getUrl(); } + + @Nullable + public String getDisplayTitle() { + return pageprops != null && pageprops.displayTitle() != null + ? pageprops.displayTitle() + : title; + } } /** * For the thumbnail URL of the page */ - public static class Thumb { + static class Thumb { @SuppressWarnings("unused") private String source; - public String getUrl() { + String getUrl() { return source; } } + + static class PageProps { + @SuppressWarnings("unused") @Nullable private String displaytitle; + + String displayTitle() { + return displaytitle; + } + } } diff --git a/app/src/main/java/org/wikipedia/dataclient/page/PageSummary.java b/app/src/main/java/org/wikipedia/dataclient/page/PageSummary.java index 0e92533..80c40a9 100644 --- a/app/src/main/java/org/wikipedia/dataclient/page/PageSummary.java +++ b/app/src/main/java/org/wikipedia/dataclient/page/PageSummary.java @@ -11,6 +11,7 @@ boolean hasError(); @Nullable ServiceError getError(); @Nullable String getTitle(); + @Nullable String getDisplayTitle(); @Nullable String getExtract(); @Nullable String getThumbnailUrl(); } diff --git a/app/src/main/java/org/wikipedia/dataclient/restbase/page/RbPageSummary.java b/app/src/main/java/org/wikipedia/dataclient/restbase/page/RbPageSummary.java index ac27029..bb7af41 100644 --- a/app/src/main/java/org/wikipedia/dataclient/restbase/page/RbPageSummary.java +++ b/app/src/main/java/org/wikipedia/dataclient/restbase/page/RbPageSummary.java @@ -3,8 +3,6 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import com.google.gson.annotations.SerializedName; - import org.wikipedia.dataclient.page.PageSummary; import org.wikipedia.dataclient.restbase.RbServiceError; import org.wikipedia.json.annotations.Required; @@ -15,12 +13,12 @@ * * N.B.: The "title" field here sent by RESTBase is the *normalized* page title. However, in the * FeedPageSummary subclass, "title" becomes the un-normalized, raw title, and the normalized title - * is sent is "normalizedtitle". + * is sent as "normalizedtitle". */ public class RbPageSummary implements PageSummary { @SuppressWarnings("unused,NullableProblems") @Required @NonNull private String title; - @SuppressWarnings("unused,NullableProblems") @Nullable @SerializedName("normalizedtitle") - private String normalizedTitle; + @SuppressWarnings("unused") @Nullable private String normalizedtitle; + @SuppressWarnings("unused,NullableProblems") @NonNull private String displaytitle; @SuppressWarnings("unused") @Nullable private String extract; @SuppressWarnings("unused") @Nullable private String description; @SuppressWarnings("unused") @Nullable private Thumbnail thumbnail; @@ -41,6 +39,11 @@ return title; } + @Override @NonNull + public String getDisplayTitle() { + return displaytitle; + } + @Override @Nullable public String getExtract() { return extract; @@ -58,7 +61,7 @@ @NonNull public String getNormalizedTitle() { - return normalizedTitle == null ? title : normalizedTitle; + return normalizedtitle == null ? title : normalizedtitle; } /** diff --git a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java index ab21a8f..ca54066 100755 --- a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java +++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java @@ -71,6 +71,7 @@ private SimpleDraweeView thumbnailView; private GalleryThumbnailScrollView thumbnailGallery; private LinkPreviewOverlayView overlayView; + private TextView titleText; private View toolbarView; private View overflowButton; @@ -107,8 +108,7 @@ toolbarView = rootView.findViewById(R.id.link_preview_toolbar); toolbarView.setOnClickListener(goToPageListener); - TextView titleText = rootView.findViewById(R.id.link_preview_title); - titleText.setText(pageTitle.getDisplayText()); + titleText = rootView.findViewById(R.id.link_preview_title); setConditionalLayoutDirection(rootView, pageTitle.getWikiSite().languageCode()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // for <5.0, give the title a bit more bottom padding, since these versions @@ -229,7 +229,7 @@ PageClientFactory .create(pageTitle.getWikiSite(), pageTitle.namespace()) .summary(pageTitle.getPrefixedText()) - .enqueue(linkPreviewNetworkOnLoadCallback); + .enqueue(linkPreviewCallback); } private void showPreview(@NonNull LinkPreviewContents contents) { @@ -274,7 +274,7 @@ ViewUtil.loadImageUrlInto(thumbnailView, contents.getTitle().getThumbUrl()); } - private retrofit2.Callback<PageSummary> linkPreviewNetworkOnLoadCallback + private retrofit2.Callback<PageSummary> linkPreviewCallback = new retrofit2.Callback<PageSummary>() { @Override public void onResponse(Call<PageSummary> call, Response<PageSummary> rsp) { if (!isAdded()) { @@ -283,8 +283,10 @@ PageSummary summary = rsp.body(); if (summary != null && !summary.hasError()) { + titleText.setText(summary.getDisplayTitle()); showPreview(new LinkPreviewContents(summary, pageTitle.getWikiSite())); } else { + titleText.setText(pageTitle.getDisplayText()); showError(null); logError(summary.hasError() ? summary.getError() : null, "Page summary network request failed"); @@ -296,6 +298,7 @@ if (!isAdded()) { return; } + titleText.setText(pageTitle.getDisplayText()); showError(caught); } }; -- To view, visit https://gerrit.wikimedia.org/r/390853 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9030f5871250505e0e0399c94f2b857c30204db5 Gerrit-PatchSet: 4 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Cooltey <cf...@wikimedia.org> Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org> Gerrit-Reviewer: Sharvaniharan <sha...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits