Skip to content

Commit

Permalink
Merge pull request #1799 from wordpress-mobile/feature/1795-reader-re…
Browse files Browse the repository at this point in the history
…nder-attachments

Feature/1795 reader render attachments
  • Loading branch information
roundhill committed Sep 3, 2014
2 parents 083a272 + db54ca0 commit 0c5bd2d
Show file tree
Hide file tree
Showing 17 changed files with 676 additions and 315 deletions.
1 change: 0 additions & 1 deletion WordPress/src/main/assets/ic_reader_video_overlay.png

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class ReaderDatabase extends SQLiteOpenHelper {
protected static final String DB_NAME = "wpreader.db";
private static final int DB_VERSION = 83;
private static final int DB_VERSION = 85;

/*
* version history
Expand All @@ -40,6 +40,8 @@ public class ReaderDatabase extends SQLiteOpenHelper {
* 81 - added image_url to tbl_blog_info
* 82 - added idx_posts_timestamp to tbl_posts
* 83 - removed tag_list from tbl_posts
* 84 - added tbl_attachments
* 85 - removed tbl_attachments, added attachments_json to tbl_posts
*/

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class ReaderPostTable {
+ "primary_tag," // 26
+ "secondary_tag," // 27
+ "is_likes_enabled," // 28
+ "is_sharing_enabled"; // 29
+ "is_sharing_enabled," // 29
+ "attachments_json"; // 30


protected static void createTables(SQLiteDatabase db) {
Expand Down Expand Up @@ -81,6 +82,7 @@ protected static void createTables(SQLiteDatabase db) {
+ " secondary_tag TEXT,"
+ " is_likes_enabled INTEGER DEFAULT 0,"
+ " is_sharing_enabled INTEGER DEFAULT 0,"
+ " attachments_json TEXT,"
+ " PRIMARY KEY (post_id, blog_id)"
+ ")");
db.execSQL("CREATE INDEX idx_posts_timestamp ON tbl_posts(timestamp)");
Expand Down Expand Up @@ -373,7 +375,7 @@ public static void addOrUpdatePosts(final ReaderTag tag, ReaderPostList posts) {
SQLiteStatement stmtPosts = db.compileStatement(
"INSERT OR REPLACE INTO tbl_posts ("
+ COLUMN_NAMES
+ ") 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)");
+ ") 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)");
SQLiteStatement stmtTags = db.compileStatement(
"INSERT OR REPLACE INTO tbl_post_tags (post_id, blog_id, pseudo_id, tag_name, tag_type) VALUES (?1,?2,?3,?4,?5)");

Expand Down Expand Up @@ -410,6 +412,7 @@ public static void addOrUpdatePosts(final ReaderTag tag, ReaderPostList posts) {
stmtPosts.bindString(27, post.getSecondaryTag());
stmtPosts.bindLong (28, SqlUtils.boolToSql(post.isLikesEnabled));
stmtPosts.bindLong (29, SqlUtils.boolToSql(post.isSharingEnabled));
stmtPosts.bindString(30, post.getAttachmentsJson());
stmtPosts.execute();
}

Expand Down Expand Up @@ -560,6 +563,8 @@ private static class PostColumnIndexes {
private final int idx_is_likes_enabled;
private final int idx_is_sharing_enabled;

private final int idx_attachments_json;

private PostColumnIndexes(Cursor c) {
if (c == null)
throw new IllegalArgumentException("PostColumnIndexes > null cursor");
Expand Down Expand Up @@ -600,6 +605,8 @@ private PostColumnIndexes(Cursor c) {

idx_is_likes_enabled = c.getColumnIndex("is_likes_enabled");
idx_is_sharing_enabled = c.getColumnIndex("is_sharing_enabled");

idx_attachments_json = c.getColumnIndex("attachments_json");
}
}

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

post.setAttachmentsJson(c.getString(cols.idx_attachments_json));

return post;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class ReaderPost {
public boolean isLikesEnabled;
public boolean isSharingEnabled; // currently unused

private String attachmentsJson;

public static ReaderPost fromJson(JSONObject json) {
if (json == null) {
throw new IllegalArgumentException("null json post");
Expand Down Expand Up @@ -155,6 +157,12 @@ public static ReaderPost fromJson(JSONObject json) {
// parse the tags section
assignTagsFromJson(post, json.optJSONObject("tags"));

// parse the attachments
JSONObject jsonAttachments = json.optJSONObject("attachments");
if (jsonAttachments != null) {
post.attachmentsJson = jsonAttachments.toString();
}

// the single-post sites/$site/posts/$post endpoint returns all site metadata
// under meta/data/site (assuming ?meta=site was added to the request)
JSONObject jsonSite = JSONUtil.getJSONChild(json, "meta/data/site");
Expand Down Expand Up @@ -343,8 +351,6 @@ public void setPublished(String published) {
this.published = StringUtils.notNullStr(published);
}

// --------------------------------------------------------------------------------------------

public String getPrimaryTag() {
return StringUtils.notNullStr(primaryTag);
}
Expand All @@ -368,7 +374,17 @@ public void setSecondaryTag(String tagName) {
}
}

// --------------------------------------------------------------------------------------------
/*
* attachments are stored as the actual JSON to avoid having a separate table for
* them, may need to revisit this if/when attachments become more important
*/
public String getAttachmentsJson() {
return StringUtils.notNullStr(attachmentsJson);
}
public void setAttachmentsJson(String json) {
attachmentsJson = StringUtils.notNullStr(json);
}


public boolean hasText() {
return !TextUtils.isEmpty(text);
Expand Down Expand Up @@ -434,12 +450,8 @@ public String getFeaturedImageForDisplay(int width, int height) {
if (featuredImageForDisplay == null) {
if (!hasFeaturedImage()) {
featuredImageForDisplay = "";
} else if (isPrivate) {
// images in private posts can't use photon, so handle separately
featuredImageForDisplay = ReaderUtils.getPrivateImageForDisplay(featuredImage, width, height);
} else {
// not private, so set to correctly sized photon url
featuredImageForDisplay = PhotonUtils.getPhotonImageUrl(featuredImage, width, height);
featuredImageForDisplay = ReaderUtils.getResizedImageUrl(featuredImage, width, height, isPrivate);
}
}
return featuredImageForDisplay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.wordpress.android.ui.reader.utils.ReaderUtils;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.DisplayUtils;
import org.wordpress.android.util.PhotonUtils;

import uk.co.senab.photoview.PhotoViewAttacher;

Expand Down Expand Up @@ -77,13 +76,8 @@ public void setImageUrl(String imageUrl,
boolean isPrivate,
PhotoViewListener listener) {
int loResWidth = (int) (hiResWidth * 0.10f);
if (isPrivate) {
mLoResImageUrl = ReaderUtils.getPrivateImageForDisplay(imageUrl, loResWidth, 0);
mHiResImageUrl = ReaderUtils.getPrivateImageForDisplay(imageUrl, hiResWidth, 0);
} else {
mLoResImageUrl = PhotonUtils.getPhotonImageUrl(imageUrl, loResWidth, 0);
mHiResImageUrl = PhotonUtils.getPhotonImageUrl(imageUrl, hiResWidth, 0);
}
mLoResImageUrl = ReaderUtils.getResizedImageUrl(imageUrl, loResWidth, 0, isPrivate);
mHiResImageUrl = ReaderUtils.getResizedImageUrl(imageUrl, hiResWidth, 0, isPrivate);

mPhotoViewListener = listener;
loadLoResImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.wordpress.android.ui.reader.ReaderViewPagerTransformer.TransformType;
import org.wordpress.android.ui.reader.models.ReaderImageList;
import org.wordpress.android.ui.reader.utils.ReaderImageScanner;
import org.wordpress.android.util.AppLog;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -68,26 +69,35 @@ public void onPageSelected(int position) {
}

private void loadImageList() {
new Thread() {
@Override
public void run() {
// parse list of images from content that was (optionally) passed to
// this activity, and make sure the list includes the passed url
ReaderImageScanner scanner = new ReaderImageScanner(mContent, mIsPrivate);
final ReaderImageList imageList = scanner.getImageList();
if (!TextUtils.isEmpty(mInitialImageUrl) && !imageList.hasImageUrl(mInitialImageUrl)) {
imageList.addImageUrl(0, mInitialImageUrl);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!isFinishing()) {
setImageList(imageList, mInitialImageUrl);
}
}
});
// content will be empty unless this was called by ReaderPostDetailFragment to show
// a list of images in a post (in which case, it's the content of the post)
if (TextUtils.isEmpty(mContent)) {
final ReaderImageList imageList = new ReaderImageList(mIsPrivate);
if (!TextUtils.isEmpty(mInitialImageUrl)) {
imageList.add(mInitialImageUrl);
}
}.start();
setImageList(imageList, mInitialImageUrl);
} else {
// parse images from content and make sure the list includes the passed url
new Thread() {
@Override
public void run() {
final ReaderImageList imageList = new ReaderImageScanner(mContent, mIsPrivate).getImageList();
if (!TextUtils.isEmpty(mInitialImageUrl) && !imageList.hasImageUrl(mInitialImageUrl)) {
AppLog.w(AppLog.T.READER, "reader photo viewer > initial image not in list");
imageList.addImageUrl(0, mInitialImageUrl);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!isFinishing()) {
setImageList(imageList, mInitialImageUrl);
}
}
});
}
}.start();
}
}

private void setImageList(ReaderImageList imageList, String initialImageUrl) {
Expand Down
Loading

0 comments on commit 0c5bd2d

Please sign in to comment.