Skip to content

Commit 0c5bd2d

Browse files
committed
Merge pull request #1799 from wordpress-mobile/feature/1795-reader-render-attachments
Feature/1795 reader render attachments
2 parents 083a272 + db54ca0 commit 0c5bd2d

File tree

17 files changed

+676
-315
lines changed

17 files changed

+676
-315
lines changed

WordPress/src/main/assets/ic_reader_video_overlay.png

Lines changed: 0 additions & 1 deletion
This file was deleted.

WordPress/src/main/java/org/wordpress/android/datasets/ReaderDatabase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
public class ReaderDatabase extends SQLiteOpenHelper {
2121
protected static final String DB_NAME = "wpreader.db";
22-
private static final int DB_VERSION = 83;
22+
private static final int DB_VERSION = 85;
2323

2424
/*
2525
* version history
@@ -40,6 +40,8 @@ public class ReaderDatabase extends SQLiteOpenHelper {
4040
* 81 - added image_url to tbl_blog_info
4141
* 82 - added idx_posts_timestamp to tbl_posts
4242
* 83 - removed tag_list from tbl_posts
43+
* 84 - added tbl_attachments
44+
* 85 - removed tbl_attachments, added attachments_json to tbl_posts
4345
*/
4446

4547
/*

WordPress/src/main/java/org/wordpress/android/datasets/ReaderPostTable.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class ReaderPostTable {
4747
+ "primary_tag," // 26
4848
+ "secondary_tag," // 27
4949
+ "is_likes_enabled," // 28
50-
+ "is_sharing_enabled"; // 29
50+
+ "is_sharing_enabled," // 29
51+
+ "attachments_json"; // 30
5152

5253

5354
protected static void createTables(SQLiteDatabase db) {
@@ -81,6 +82,7 @@ protected static void createTables(SQLiteDatabase db) {
8182
+ " secondary_tag TEXT,"
8283
+ " is_likes_enabled INTEGER DEFAULT 0,"
8384
+ " is_sharing_enabled INTEGER DEFAULT 0,"
85+
+ " attachments_json TEXT,"
8486
+ " PRIMARY KEY (post_id, blog_id)"
8587
+ ")");
8688
db.execSQL("CREATE INDEX idx_posts_timestamp ON tbl_posts(timestamp)");
@@ -373,7 +375,7 @@ public static void addOrUpdatePosts(final ReaderTag tag, ReaderPostList posts) {
373375
SQLiteStatement stmtPosts = db.compileStatement(
374376
"INSERT OR REPLACE INTO tbl_posts ("
375377
+ COLUMN_NAMES
376-
+ ") VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29)");
378+
+ ") VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29,?30)");
377379
SQLiteStatement stmtTags = db.compileStatement(
378380
"INSERT OR REPLACE INTO tbl_post_tags (post_id, blog_id, pseudo_id, tag_name, tag_type) VALUES (?1,?2,?3,?4,?5)");
379381

@@ -410,6 +412,7 @@ public static void addOrUpdatePosts(final ReaderTag tag, ReaderPostList posts) {
410412
stmtPosts.bindString(27, post.getSecondaryTag());
411413
stmtPosts.bindLong (28, SqlUtils.boolToSql(post.isLikesEnabled));
412414
stmtPosts.bindLong (29, SqlUtils.boolToSql(post.isSharingEnabled));
415+
stmtPosts.bindString(30, post.getAttachmentsJson());
413416
stmtPosts.execute();
414417
}
415418

@@ -560,6 +563,8 @@ private static class PostColumnIndexes {
560563
private final int idx_is_likes_enabled;
561564
private final int idx_is_sharing_enabled;
562565

566+
private final int idx_attachments_json;
567+
563568
private PostColumnIndexes(Cursor c) {
564569
if (c == null)
565570
throw new IllegalArgumentException("PostColumnIndexes > null cursor");
@@ -600,6 +605,8 @@ private PostColumnIndexes(Cursor c) {
600605

601606
idx_is_likes_enabled = c.getColumnIndex("is_likes_enabled");
602607
idx_is_sharing_enabled = c.getColumnIndex("is_sharing_enabled");
608+
609+
idx_attachments_json = c.getColumnIndex("attachments_json");
603610
}
604611
}
605612

@@ -652,6 +659,8 @@ private static ReaderPost getPostFromCursor(Cursor c, PostColumnIndexes cols) {
652659
post.isLikesEnabled = SqlUtils.sqlToBool(c.getInt(cols.idx_is_likes_enabled));
653660
post.isSharingEnabled = SqlUtils.sqlToBool(c.getInt(cols.idx_is_sharing_enabled));
654661

662+
post.setAttachmentsJson(c.getString(cols.idx_attachments_json));
663+
655664
return post;
656665
}
657666
}

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class ReaderPost {
5252
public boolean isLikesEnabled;
5353
public boolean isSharingEnabled; // currently unused
5454

55+
private String attachmentsJson;
56+
5557
public static ReaderPost fromJson(JSONObject json) {
5658
if (json == null) {
5759
throw new IllegalArgumentException("null json post");
@@ -155,6 +157,12 @@ public static ReaderPost fromJson(JSONObject json) {
155157
// parse the tags section
156158
assignTagsFromJson(post, json.optJSONObject("tags"));
157159

160+
// parse the attachments
161+
JSONObject jsonAttachments = json.optJSONObject("attachments");
162+
if (jsonAttachments != null) {
163+
post.attachmentsJson = jsonAttachments.toString();
164+
}
165+
158166
// the single-post sites/$site/posts/$post endpoint returns all site metadata
159167
// under meta/data/site (assuming ?meta=site was added to the request)
160168
JSONObject jsonSite = JSONUtil.getJSONChild(json, "meta/data/site");
@@ -343,8 +351,6 @@ public void setPublished(String published) {
343351
this.published = StringUtils.notNullStr(published);
344352
}
345353

346-
// --------------------------------------------------------------------------------------------
347-
348354
public String getPrimaryTag() {
349355
return StringUtils.notNullStr(primaryTag);
350356
}
@@ -368,7 +374,17 @@ public void setSecondaryTag(String tagName) {
368374
}
369375
}
370376

371-
// --------------------------------------------------------------------------------------------
377+
/*
378+
* attachments are stored as the actual JSON to avoid having a separate table for
379+
* them, may need to revisit this if/when attachments become more important
380+
*/
381+
public String getAttachmentsJson() {
382+
return StringUtils.notNullStr(attachmentsJson);
383+
}
384+
public void setAttachmentsJson(String json) {
385+
attachmentsJson = StringUtils.notNullStr(json);
386+
}
387+
372388

373389
public boolean hasText() {
374390
return !TextUtils.isEmpty(text);
@@ -434,12 +450,8 @@ public String getFeaturedImageForDisplay(int width, int height) {
434450
if (featuredImageForDisplay == null) {
435451
if (!hasFeaturedImage()) {
436452
featuredImageForDisplay = "";
437-
} else if (isPrivate) {
438-
// images in private posts can't use photon, so handle separately
439-
featuredImageForDisplay = ReaderUtils.getPrivateImageForDisplay(featuredImage, width, height);
440453
} else {
441-
// not private, so set to correctly sized photon url
442-
featuredImageForDisplay = PhotonUtils.getPhotonImageUrl(featuredImage, width, height);
454+
featuredImageForDisplay = ReaderUtils.getResizedImageUrl(featuredImage, width, height, isPrivate);
443455
}
444456
}
445457
return featuredImageForDisplay;

WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoView.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.wordpress.android.ui.reader.utils.ReaderUtils;
2222
import org.wordpress.android.util.AppLog;
2323
import org.wordpress.android.util.DisplayUtils;
24-
import org.wordpress.android.util.PhotonUtils;
2524

2625
import uk.co.senab.photoview.PhotoViewAttacher;
2726

@@ -77,13 +76,8 @@ public void setImageUrl(String imageUrl,
7776
boolean isPrivate,
7877
PhotoViewListener listener) {
7978
int loResWidth = (int) (hiResWidth * 0.10f);
80-
if (isPrivate) {
81-
mLoResImageUrl = ReaderUtils.getPrivateImageForDisplay(imageUrl, loResWidth, 0);
82-
mHiResImageUrl = ReaderUtils.getPrivateImageForDisplay(imageUrl, hiResWidth, 0);
83-
} else {
84-
mLoResImageUrl = PhotonUtils.getPhotonImageUrl(imageUrl, loResWidth, 0);
85-
mHiResImageUrl = PhotonUtils.getPhotonImageUrl(imageUrl, hiResWidth, 0);
86-
}
79+
mLoResImageUrl = ReaderUtils.getResizedImageUrl(imageUrl, loResWidth, 0, isPrivate);
80+
mHiResImageUrl = ReaderUtils.getResizedImageUrl(imageUrl, hiResWidth, 0, isPrivate);
8781

8882
mPhotoViewListener = listener;
8983
loadLoResImage();

WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.wordpress.android.ui.reader.ReaderViewPagerTransformer.TransformType;
1717
import org.wordpress.android.ui.reader.models.ReaderImageList;
1818
import org.wordpress.android.ui.reader.utils.ReaderImageScanner;
19+
import org.wordpress.android.util.AppLog;
1920

2021
import javax.annotation.Nonnull;
2122

@@ -68,26 +69,35 @@ public void onPageSelected(int position) {
6869
}
6970

7071
private void loadImageList() {
71-
new Thread() {
72-
@Override
73-
public void run() {
74-
// parse list of images from content that was (optionally) passed to
75-
// this activity, and make sure the list includes the passed url
76-
ReaderImageScanner scanner = new ReaderImageScanner(mContent, mIsPrivate);
77-
final ReaderImageList imageList = scanner.getImageList();
78-
if (!TextUtils.isEmpty(mInitialImageUrl) && !imageList.hasImageUrl(mInitialImageUrl)) {
79-
imageList.addImageUrl(0, mInitialImageUrl);
80-
}
81-
runOnUiThread(new Runnable() {
82-
@Override
83-
public void run() {
84-
if (!isFinishing()) {
85-
setImageList(imageList, mInitialImageUrl);
86-
}
87-
}
88-
});
72+
// content will be empty unless this was called by ReaderPostDetailFragment to show
73+
// a list of images in a post (in which case, it's the content of the post)
74+
if (TextUtils.isEmpty(mContent)) {
75+
final ReaderImageList imageList = new ReaderImageList(mIsPrivate);
76+
if (!TextUtils.isEmpty(mInitialImageUrl)) {
77+
imageList.add(mInitialImageUrl);
8978
}
90-
}.start();
79+
setImageList(imageList, mInitialImageUrl);
80+
} else {
81+
// parse images from content and make sure the list includes the passed url
82+
new Thread() {
83+
@Override
84+
public void run() {
85+
final ReaderImageList imageList = new ReaderImageScanner(mContent, mIsPrivate).getImageList();
86+
if (!TextUtils.isEmpty(mInitialImageUrl) && !imageList.hasImageUrl(mInitialImageUrl)) {
87+
AppLog.w(AppLog.T.READER, "reader photo viewer > initial image not in list");
88+
imageList.addImageUrl(0, mInitialImageUrl);
89+
}
90+
runOnUiThread(new Runnable() {
91+
@Override
92+
public void run() {
93+
if (!isFinishing()) {
94+
setImageList(imageList, mInitialImageUrl);
95+
}
96+
}
97+
});
98+
}
99+
}.start();
100+
}
91101
}
92102

93103
private void setImageList(ReaderImageList imageList, String initialImageUrl) {

0 commit comments

Comments
 (0)