jenkins-bot has submitted this change and it was merged.
Change subject: Remove in-Wikitext image captions from news stories
......................................................................
Remove in-Wikitext image captions from news stories
The Wikitext we scrape for the In the News stories often includes a
parenthetical referral to a thumbnail for the section, which we don't use.
Instead, we get thumbnails for each card from the metadata for the linked
pages for each story. This patch removes the inapplicable caption.
Note that this has a soft dependency on
I295c01b48a0d4feea6b21e07e85179deadf1f216 in that merging without it won't
hurt anything, but you'll need that patch applied to the service to see
the effect here.
Among current stories on enwiki, this applies to the one concerning the
Juno spacecraft.
Change-Id: I04284d257858f9d50494c8b0f4a459da099a2091
---
M app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
M
app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardItemView.java
M app/src/main/java/org/wikipedia/richtext/RichTextUtil.java
3 files changed, 33 insertions(+), 5 deletions(-)
Approvals:
Niedzielski: Looks good to me, approved
jenkins-bot: Verified
diff --git a/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
b/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
index 2269e7e..9f29c0d 100644
--- a/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
+++ b/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java
@@ -1,14 +1,18 @@
package org.wikipedia.feed.news;
+import android.graphics.Typeface;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.Spanned;
+import android.text.style.StyleSpan;
import org.wikipedia.Site;
import org.wikipedia.feed.model.Card;
import org.wikipedia.feed.model.CardPageItem;
+import org.wikipedia.richtext.RichTextUtil;
+import org.wikipedia.util.log.L;
import java.util.List;
@@ -38,8 +42,8 @@
}
@NonNull
- public Spanned text() {
- return Html.fromHtml(newsItem.story());
+ public CharSequence text() {
+ return removeImageCaption(Html.fromHtml(newsItem.story()));
}
public List<CardPageItem> links() {
@@ -52,4 +56,20 @@
public String title() {
return "";
}
+
+ /* Remove the in-Wikitext thumbnail caption, which will almost certainly
not apply here */
+ private CharSequence removeImageCaption(Spanned text) {
+ Object[] spans = RichTextUtil.getSpans(text, 0, text.length());
+ for (Object span : spans) {
+ if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() ==
Typeface.ITALIC) {
+ int start = text.getSpanStart(span);
+ int end = text.getSpanEnd(span);
+ if (text.charAt(start) == '(' && text.charAt(end - 1) == ')') {
+ L.v("Removing spanned text: " + text.subSequence(start,
end));
+ return RichTextUtil.remove(text, start, end);
+ }
+ }
+ }
+ return text;
+ }
}
diff --git
a/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardItemView.java
b/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardItemView.java
index 9ecb8a5..25997d1 100644
---
a/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardItemView.java
+++
b/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardItemView.java
@@ -5,7 +5,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
-import android.text.Spanned;
import android.widget.TextView;
import org.wikipedia.R;
@@ -36,7 +35,7 @@
return callback;
}
- public void setText(@NonNull Spanned text) {
+ public void setText(@NonNull CharSequence text) {
textView.setText(text);
RichTextUtil.removeUnderlinesFromLinksAndMakeBold(textView);
}
diff --git a/app/src/main/java/org/wikipedia/richtext/RichTextUtil.java
b/app/src/main/java/org/wikipedia/richtext/RichTextUtil.java
index 8f726fd..8aaad08 100644
--- a/app/src/main/java/org/wikipedia/richtext/RichTextUtil.java
+++ b/app/src/main/java/org/wikipedia/richtext/RichTextUtil.java
@@ -1,10 +1,13 @@
package org.wikipedia.richtext;
+import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
+import android.text.SpannedString;
+import android.text.TextUtils;
import android.text.style.URLSpan;
import android.widget.TextView;
@@ -123,9 +126,15 @@
}
}
- public static String stripHtml(String html) {
+ public static String stripHtml(@NonNull String html) {
return Html.fromHtml(html).toString();
}
+
+ public static CharSequence remove(@NonNull CharSequence text,
@IntRange(from = 1) int start, int end) {
+ return new SpannedString(TextUtils.concat(text.subSequence(0, start -
1),
+ text.subSequence(end, text.length())));
+ }
+
private RichTextUtil() { }
}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/298036
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I04284d257858f9d50494c8b0f4a459da099a2091
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits