use of org.wordpress.android.ui.reader.utils.ReaderImageScanner in project WordPress-Android by wordpress-mobile.
the class ReaderPostRenderer method resizeImages.
/*
* scan the content for images and make sure they're correctly sized for the device
*/
private void resizeImages() {
ReaderHtmlUtils.HtmlScannerListener imageListener = new ReaderHtmlUtils.HtmlScannerListener() {
@Override
public void onTagFound(String imageTag, String imageUrl) {
if (!imageUrl.contains("wpcom-smileys")) {
replaceImageTag(imageTag, imageUrl);
}
}
};
ReaderImageScanner scanner = new ReaderImageScanner(mRenderBuilder.toString(), mPost.isPrivate);
scanner.beginScan(imageListener);
}
use of org.wordpress.android.ui.reader.utils.ReaderImageScanner in project WordPress-Android by wordpress-mobile.
the class ReaderPhotoViewerActivity method loadImageList.
private void loadImageList() {
// content will be empty when viewing a single image, otherwise content is HTML
// so parse images from it
final ReaderImageList imageList;
if (TextUtils.isEmpty(mContent)) {
imageList = new ReaderImageList(mIsPrivate);
} else {
int minImageWidth = mIsGallery ? ReaderConstants.MIN_GALLERY_IMAGE_WIDTH : 0;
imageList = new ReaderImageScanner(mContent, mIsPrivate).getImageList(0, minImageWidth);
}
// make sure initial image is in the list
if (!TextUtils.isEmpty(mInitialImageUrl) && !imageList.hasImageUrl(mInitialImageUrl)) {
imageList.addImageUrl(0, mInitialImageUrl);
}
getAdapter().setImageList(imageList, mInitialImageUrl);
}
use of org.wordpress.android.ui.reader.utils.ReaderImageScanner in project WordPress-Android by wordpress-mobile.
the class ReaderPost method fromJson.
public static ReaderPost fromJson(JSONObject json) {
if (json == null) {
throw new IllegalArgumentException("null json post");
}
ReaderPost post = new ReaderPost();
post.postId = json.optLong("ID");
post.blogId = json.optLong("site_ID");
post.feedId = json.optLong("feed_ID");
post.feedItemId = json.optLong("feed_item_ID");
if (json.has("pseudo_ID")) {
// read/ endpoint
post.pseudoId = JSONUtils.getString(json, "pseudo_ID");
} else {
// sites/ endpoint
post.pseudoId = JSONUtils.getString(json, "global_ID");
}
// remove HTML from the excerpt
post.excerpt = HtmlUtils.fastStripHtml(JSONUtils.getString(json, "excerpt")).trim();
post.text = JSONUtils.getString(json, "content");
post.title = JSONUtils.getStringDecoded(json, "title");
post.format = JSONUtils.getString(json, "format");
post.url = JSONUtils.getString(json, "URL");
post.shortUrl = JSONUtils.getString(json, "short_URL");
post.setBlogUrl(JSONUtils.getString(json, "site_URL"));
post.numLikes = json.optInt("like_count");
post.isLikedByCurrentUser = JSONUtils.getBool(json, "i_like");
post.isFollowedByCurrentUser = JSONUtils.getBool(json, "is_following");
post.isExternal = JSONUtils.getBool(json, "is_external");
post.isPrivate = JSONUtils.getBool(json, "site_is_private");
post.isJetpack = JSONUtils.getBool(json, "is_jetpack");
JSONObject jsonDiscussion = json.optJSONObject("discussion");
if (jsonDiscussion != null) {
post.isCommentsOpen = JSONUtils.getBool(jsonDiscussion, "comments_open");
post.numReplies = jsonDiscussion.optInt("comment_count");
} else {
post.isCommentsOpen = JSONUtils.getBool(json, "comments_open");
post.numReplies = json.optInt("comment_count");
}
// parse the author section
assignAuthorFromJson(post, json.optJSONObject("author"));
post.featuredImage = JSONUtils.getString(json, "featured_image");
post.blogName = JSONUtils.getStringDecoded(json, "site_name");
post.datePublished = JSONUtils.getString(json, "date");
post.dateLiked = JSONUtils.getString(json, "date_liked");
post.dateTagged = JSONUtils.getString(json, "tagged_on");
// "score" only exists for search results
post.score = json.optDouble("score");
// if the post is untitled, make up a title from the excerpt
if (!post.hasTitle() && post.hasExcerpt()) {
post.title = extractTitle(post.excerpt, 50);
}
// remove html from title (rare, but does happen)
if (post.hasTitle() && post.title.contains("<") && post.title.contains(">")) {
post.title = HtmlUtils.stripHtml(post.title);
}
// parse the tags section
assignTagsFromJson(post, json.optJSONObject("tags"));
// parse the attachments
JSONObject jsonAttachments = json.optJSONObject("attachments");
if (jsonAttachments != null && jsonAttachments.length() > 0) {
post.attachmentsJson = jsonAttachments.toString();
}
// site metadata - returned when ?meta=site was added to the request
JSONObject jsonSite = JSONUtils.getJSONChild(json, "meta/data/site");
if (jsonSite != null) {
post.blogId = jsonSite.optInt("ID");
post.blogName = JSONUtils.getString(jsonSite, "name");
post.setBlogUrl(JSONUtils.getString(jsonSite, "URL"));
post.isPrivate = JSONUtils.getBool(jsonSite, "is_private");
JSONObject jsonSiteIcon = jsonSite.optJSONObject("icon");
if (jsonSiteIcon != null) {
post.blogImageUrl = JSONUtils.getString(jsonSiteIcon, "img");
}
// TODO: as of 29-Sept-2014, this is broken - endpoint returns false when it should be true
post.isJetpack = JSONUtils.getBool(jsonSite, "jetpack");
}
// "discover" posts
JSONObject jsonDiscover = json.optJSONObject("discover_metadata");
if (jsonDiscover != null) {
post.setDiscoverJson(jsonDiscover.toString());
}
// xpost info
assignXpostIdsFromJson(post, json.optJSONArray("metadata"));
// we can find a suitable image from the content
if (!post.hasFeaturedImage() && post.hasImages()) {
post.featuredImage = new ReaderImageScanner(post.text, post.isPrivate).getLargestImage(ReaderConstants.MIN_FEATURED_IMAGE_WIDTH);
}
// the content for a suitable featured video
if (!post.hasFeaturedImage() && !post.hasFeaturedVideo() && post.getText().contains("<iframe")) {
post.setFeaturedVideo(new ReaderIframeScanner(post.getText()).getFirstUsableVideo());
}
// "railcar" data - currently used in search streams, used by TrainTracks
JSONObject jsonRailcar = json.optJSONObject("railcar");
if (jsonRailcar != null) {
post.setRailcarJson(jsonRailcar.toString());
}
// set the card type last since it depends on information contained in the post - note
// that this is stored in the post table rather than calculated on-the-fly
post.setCardType(ReaderCardType.fromReaderPost(post));
return post;
}
use of org.wordpress.android.ui.reader.utils.ReaderImageScanner in project WordPress-Android by wordpress-mobile.
the class ReaderThumbnailStrip method loadThumbnails.
public void loadThumbnails(long blogId, long postId, boolean isPrivate) {
// get rid of any views already added
mView.removeAllViews();
// get this post's content and scan it for images suitable in a gallery
final String content = ReaderPostTable.getPostText(blogId, postId);
final ReaderImageList imageList = new ReaderImageScanner(content, isPrivate).getImageList(IMAGE_COUNT, ReaderConstants.MIN_GALLERY_IMAGE_WIDTH);
if (imageList.size() < IMAGE_COUNT) {
mView.setVisibility(View.GONE);
return;
}
final EnumSet<PhotoViewerOption> photoViewerOptions = EnumSet.of(PhotoViewerOption.IS_GALLERY_IMAGE);
if (isPrivate) {
photoViewerOptions.add(PhotoViewerOption.IS_PRIVATE_IMAGE);
}
// add a separate imageView for each image up to the max
int numAdded = 0;
LayoutInflater inflater = LayoutInflater.from(getContext());
for (final String imageUrl : imageList) {
View view = inflater.inflate(R.layout.reader_thumbnail_strip_image, mView, false);
WPNetworkImageView imageView = (WPNetworkImageView) view.findViewById(R.id.thumbnail_strip_image);
mView.addView(view);
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, mThumbnailWidth, mThumbnailHeight);
imageView.setImageUrl(photonUrl, WPNetworkImageView.ImageType.PHOTO);
// tapping a thumbnail opens the photo viewer
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
ReaderActivityLauncher.showReaderPhotoViewer(view.getContext(), imageUrl, content, view, photoViewerOptions, 0, 0);
}
});
numAdded++;
if (numAdded >= IMAGE_COUNT) {
break;
}
}
if (mView.getVisibility() != View.VISIBLE) {
AniUtils.fadeIn(mView, AniUtils.Duration.SHORT);
}
}
Aggregations