Skip to content

Commit 237beb3

Browse files
committed
Merge pull request #1077 from wordpress-mobile/issue/1076-reader-featured-image
Issue/1076 reader featured image
2 parents 042bbc0 + 60dcc10 commit 237beb3

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

res/layout/reader_listitem_post_detail.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-->
66
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
77
android:layout_width="match_parent"
8-
android:layout_height="wrap_content"
8+
android:layout_height="match_parent"
99
android:orientation="vertical"
1010
android:padding="@dimen/margin_large">
1111

@@ -81,7 +81,10 @@
8181

8282
<org.wordpress.android.widgets.WPNetworkImageView
8383
android:id="@+id/image_featured"
84-
style="@style/ReaderImageView.Featured"
84+
android:layout_width="match_parent"
85+
android:layout_height="wrap_content"
86+
android:minHeight="@dimen/reader_featured_image_height"
87+
android:adjustViewBounds="true"
8588
android:layout_marginLeft="@dimen/reader_list_margin"
8689
android:layout_marginRight="@dimen/reader_list_margin"
8790
android:layout_marginTop="@dimen/margin_large"

src/org/wordpress/android/models/ReaderPost.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ReaderPost {
3434
private String tags; // comma-separated list of tags
3535

3636
public long timestamp; // used for sorting
37-
public String published;
37+
private String published;
3838

3939
private String url;
4040
private String featuredImage;
@@ -166,21 +166,23 @@ public static ReaderPost fromJson(JSONObject json) {
166166
// it as a video
167167
if (!post.hasFeaturedImage()) {
168168
JSONObject jsonMedia = json.optJSONObject("featured_media");
169-
if (jsonMedia!=null) {
169+
if (jsonMedia != null) {
170170
String mediaUrl = JSONUtil.getString(jsonMedia, "uri");
171-
String type = JSONUtil.getString(jsonMedia, "type");
172-
boolean isVideo = (type!=null && type.equals("video"));
173-
if (isVideo) {
174-
post.featuredVideo = mediaUrl;
175-
} else {
176-
post.featuredImage = mediaUrl;
171+
if (!TextUtils.isEmpty(mediaUrl)) {
172+
String type = JSONUtil.getString(jsonMedia, "type");
173+
boolean isVideo = (type != null && type.equals("video"));
174+
if (isVideo) {
175+
post.featuredVideo = mediaUrl;
176+
} else {
177+
post.featuredImage = mediaUrl;
178+
}
177179
}
178180
}
179181

180182
// if we still don't have a featured image, parse the content for an image that's
181183
// suitable as a featured image - this is done since featured_media seems to miss
182184
// some images that would work well as featured images on mobile
183-
if (!post.hasFeaturedImage() && post.isWP())
185+
if (!post.hasFeaturedImage())
184186
post.featuredImage = findFeaturedImage(post.text);
185187
}
186188

@@ -257,7 +259,7 @@ private static String extractTitle(final String excerpt, int maxLen) {
257259
/*
258260
* called when a post doesn't have a featured image, searches post's content for an image that
259261
* may still be suitable as a featured image - only works with WP posts due to the search for
260-
* specific WP image classes
262+
* specific WP image classes (but will also work with RSS posts that come from WP blogs)
261263
*/
262264
private static String findFeaturedImage(final String text) {
263265
if (text==null || !text.contains("<img "))
@@ -478,7 +480,7 @@ public boolean hasTags() {
478480
return !TextUtils.isEmpty(tags);
479481
}
480482

481-
public List<String> getTagList() {
483+
List<String> getTagList() {
482484
return Arrays.asList(getTags().split(","));
483485
}
484486

src/org/wordpress/android/ui/reader/ReaderPostDetailFragment.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,10 +1277,12 @@ protected Boolean doInBackground(Void... params) {
12771277
// it will be shown between the post's title and its content (but skip mshots)
12781278
if (mPost.hasFeaturedImage() && !PhotonUtils.isMshotsUrl(mPost.getFeaturedImage())) {
12791279
Uri uri = Uri.parse(mPost.getFeaturedImage());
1280-
if (!mPost.getText().contains(StringUtils.notNullStr(uri.getLastPathSegment()))) {
1280+
String path = StringUtils.notNullStr(uri.getLastPathSegment());
1281+
if (!mPost.getText().contains(path)) {
12811282
showFeaturedImage = true;
1282-
int imgHeight = getResources().getDimensionPixelSize(R.dimen.reader_featured_image_height);
1283-
featuredImageUrl = mPost.getFeaturedImageForDisplay(0, imgHeight);
1283+
// note that only the width is used here - the imageView will adjust
1284+
// the height to match that of the image once loaded
1285+
featuredImageUrl = mPost.getFeaturedImageForDisplay(getFullSizeImageWidth(), 0);
12841286
}
12851287
}
12861288

src/org/wordpress/android/ui/reader/actions/ReaderPostActions.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,19 @@ public void run() {
234234

235235
if (hasChanges) {
236236
AppLog.d(T.READER, "post updated");
237-
// the endpoint for requesting a single post doesn't always support featured images,
238-
// so if the original post had a featured image and the updated post doesn't, set
239-
// the featured image for the updated post to that of the original post
240-
if (post.hasFeaturedImage() && !updatedPost.hasFeaturedImage()) {
241-
AppLog.i(T.READER, "restored featured image after updating post");
237+
// the endpoint for requesting a single post doesn't support featured images,
238+
// so if the original post had a featured image, set the featured image for
239+
// the updated post to that of the original post - this should be done even
240+
// if the updated post has a featured image since that was most likely
241+
// assigned by ReaderPost.findFeaturedImage()
242+
if (post.hasFeaturedImage()) {
242243
updatedPost.setFeaturedImage(post.getFeaturedImage());
243244
}
245+
// likewise for featured video
246+
if (post.hasFeaturedVideo()) {
247+
updatedPost.setFeaturedVideo(post.getFeaturedVideo());
248+
updatedPost.isVideoPress = post.isVideoPress;
249+
}
244250
ReaderPostTable.addOrUpdatePost(updatedPost);
245251
}
246252

0 commit comments

Comments
 (0)