Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1795 reader render attachments #1810

Merged
merged 78 commits into from
Sep 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
b6ef8b1
1st pass at storing post attachments
nbradbury Aug 27, 2014
df0a325
2nd pass at storing post attachments
nbradbury Aug 27, 2014
8d595f8
3rd pass at storing post attachments
nbradbury Aug 27, 2014
48cf191
4th pass at storing post attachments
nbradbury Aug 27, 2014
4e9a4cc
Fixed db transaction bug saving attachments
nbradbury Aug 27, 2014
82fa99f
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Aug 27, 2014
ee50acb
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Aug 27, 2014
f5c0d65
Added a few utility functions
nbradbury Aug 28, 2014
611953c
Moved ReaderResourceVars to its own class file
nbradbury Aug 28, 2014
fbe24df
Moved formatting code over to ReaderPostRenderer
nbradbury Aug 28, 2014
478069d
Basic mechanism in place for rendering post content after image scan
nbradbury Aug 28, 2014
dd88985
Matched images are now replaced with image tags that have height & wi…
nbradbury Aug 28, 2014
467c119
Renderer now generates content in the background
nbradbury Aug 28, 2014
aaa5f70
Removed unused ic_reader_video_overlay.png asset
nbradbury Aug 28, 2014
87b32b4
Fixed missing close IMG tag
nbradbury Aug 28, 2014
c1f2dc0
Replaced images are now photon-ized
nbradbury Aug 28, 2014
6e22337
Added CSS background-color to full size images, removed size constrai…
nbradbury Aug 28, 2014
05ba418
Removed baseUrl, apparently caused webView to stop firing onPageFinis…
nbradbury Aug 28, 2014
4c431d7
Switched to a StringBuilder for building render content
nbradbury Aug 28, 2014
e82e522
Now getting h/w from actual URL if it's from files.wordpress.com
nbradbury Aug 28, 2014
eb29613
Added margin between full size images
nbradbury Aug 28, 2014
e180688
Centralized handling of private image URLs, featured images are now i…
nbradbury Aug 29, 2014
e674135
Inserted featured image now include width & height attributes
nbradbury Aug 29, 2014
073b0b3
Featured image is now skipped when replacing scanned images
nbradbury Aug 29, 2014
6515923
Featured image now only appears above content if there are no other i…
nbradbury Aug 29, 2014
22d877a
Performance tweaks and fixes to ensure photo viewer is passed the act…
nbradbury Aug 29, 2014
5743ccc
Removed separate attachment table, now storing attachment JSON with t…
nbradbury Aug 29, 2014
b6bb922
First pass at getting rid of WordPress.getCurrentBlog in Stats
daniloercoli Aug 29, 2014
2b365fe
Removed AppLog debug messages from renderer
nbradbury Aug 29, 2014
ed82bb8
Added hint about whether content contains IMG tags to ReaderImageScanner
nbradbury Aug 29, 2014
42b4932
Do not use currentBlog when opening Stats from Notifications.
daniloercoli Aug 29, 2014
73c8fc1
Re-add a comment that was previously removed by chance
daniloercoli Aug 29, 2014
c06c522
Add NPE check to getBlogStatsCredentials
daniloercoli Aug 29, 2014
9d43b0e
Just added another Null Pointer check.
daniloercoli Aug 29, 2014
b9638f9
Fixed bug that caused featured image to be replaced
nbradbury Aug 30, 2014
fb135d7
Logic for getting image h/w from query params moved to separate function
nbradbury Aug 30, 2014
df2d721
Reverted previous commit and optimized logic to get h/w from query pa…
nbradbury Aug 30, 2014
c040d77
Removed ReaderAttachment/ReaderAttachmentList models, added HashMap o…
nbradbury Aug 30, 2014
37a40a3
HashMap of attachment sizes is now built only when needed
nbradbury Aug 30, 2014
ba25aed
Added logic to get image sizes from resize= query param
nbradbury Aug 31, 2014
0e39c8f
Appended "px" to dimen resource variables for clarity
nbradbury Aug 31, 2014
dc7b713
Enabling JavaScript moved from detail fragment to renderer
nbradbury Sep 1, 2014
8ebe947
Renamed video resource vars to clarify that they're DP rather than PX
nbradbury Sep 1, 2014
1784791
Changed to use dp image sizes based on http://developer.android.com/g…
nbradbury Sep 1, 2014
d8a5718
returned missing "height: auto" to IMG style
nbradbury Sep 1, 2014
249f943
Small images are no longer resized to full width
nbradbury Sep 1, 2014
7fca285
Make sure blog_id passed to Stats activity is valid and the blog avai…
daniloercoli Sep 1, 2014
31dc665
Added handling of images higher than they are wide
nbradbury Sep 1, 2014
dee8389
Corrected centering of portrait images
nbradbury Sep 1, 2014
eebddfd
CSS to enforce max image size now only applies to IMG tags without a …
nbradbury Sep 1, 2014
549ebac
Reverted max width
nbradbury Sep 1, 2014
f21a24e
Better error message
daniloercoli Sep 1, 2014
6a8d56d
All images in content are now replaced. If size couldn't be discovere…
nbradbury Sep 1, 2014
84aabd9
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Sep 1, 2014
978cd41
Fixes and simplifications for tiled galleries
nbradbury Sep 1, 2014
361a368
Cleanup
nbradbury Sep 1, 2014
daa585b
Added detection of mid-size images
nbradbury Sep 1, 2014
3d8a79d
Switched to using WordPress.getContext() in pxToDp
nbradbury Sep 1, 2014
ae8abee
Fixed regex bug that caused image tags to be skipped if not closed by />
nbradbury Sep 1, 2014
711c5e4
Replaced String.format() calls in ReaderPostRenderer after profiling …
nbradbury Sep 2, 2014
dabe407
Removed debug code
nbradbury Sep 2, 2014
f6ac198
Add few NPE checks
daniloercoli Sep 2, 2014
6d38297
Define one single constant ARGS_LOCAL_TABLE_BLOG_ID in StatsActivity …
daniloercoli Sep 2, 2014
f959af9
Added max-width:100% for all images
nbradbury Sep 2, 2014
50bcf07
Merge pull request #1801 from wordpress-mobile/issue/1787-get-rid-cur…
nbradbury Sep 2, 2014
765dff7
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Sep 2, 2014
b40578b
Removed unused context from previous merge
nbradbury Sep 2, 2014
5a10744
Removed hyperlink color from blog name in detail header, added divider
nbradbury Sep 2, 2014
c1c4dd8
Removed hyperlink color from blog name in detail header, added divider
nbradbury Sep 2, 2014
b824f5f
Improved .wp_caption styling
nbradbury Sep 2, 2014
d7927d1
Fixed lack of centering of portrait images with captions.
nbradbury Sep 2, 2014
614fd45
Added null check when getting attachments, fixed bug that caused mime…
nbradbury Sep 3, 2014
69b59e1
auto attributes on all text files excepted .sh and .bat
maxme Sep 3, 2014
083a272
Merge branch 'release/3.2' into develop
maxme Sep 3, 2014
572bcc2
Fix #1806 - viewing a single post in the pager now handles the case w…
nbradbury Sep 3, 2014
f10aabe
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Sep 3, 2014
20c49b7
Replaced String.format() with string concatenation in ReaderUtils and…
nbradbury Sep 3, 2014
db54ca0
Fix #1809 - post list now refreshes correctly after reader db is upgr…
nbradbury Sep 3, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* text=auto eol=lf
* text=auto
*.sh text eol=lf
*.bat text eol=crlf
*.png binary
Expand Down
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 @@ -952,8 +952,7 @@ public void onSelectItem(){
mShouldFinish = true;

Intent intent = new Intent(WPActionBarActivity.this, StatsActivity.class);
intent.putExtra("id", WordPress.getCurrentBlog().getLocalTableBlogId());
intent.putExtra("isNew", true);
intent.putExtra(StatsActivity.ARG_LOCAL_TABLE_BLOG_ID, WordPress.getCurrentBlog().getLocalTableBlogId());
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityWithDelay(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,10 @@ private void showStatsActivity(int remoteBlogId) {
return;
}

// stats activity is designed to work with the current blog, so switch blogs if necessary
if (WordPress.getCurrentRemoteBlogId() != remoteBlogId) {
// TODO: should we show a toast to let user know blog was switched?
int localBlogId = WordPress.wpDB.getLocalTableBlogIdForRemoteBlogId(remoteBlogId);
WordPress.setCurrentBlog(localBlogId);
}

int localBlogId = WordPress.wpDB.getLocalTableBlogIdForRemoteBlogId(remoteBlogId);
Intent intent = new Intent(getActivity(), StatsActivity.class);
intent.putExtra(StatsActivity.ARG_NO_MENU_DRAWER, true);
intent.putExtra(StatsActivity.ARG_LOCAL_TABLE_BLOG_ID, localBlogId);
getActivity().startActivity(intent);
}
}
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