use of org.wordpress.android.models.ReaderPost in project WordPress-Android by wordpress-mobile.
the class ReaderPostAdapter method renderPost.
private void renderPost(int position, ReaderPostViewHolder holder) {
final ReaderPost post = getItem(position);
ReaderTypes.ReaderPostListType postListType = getPostListType();
holder.txtDateline.setText(DateTimeUtils.javaDateToTimeSpan(post.getDisplayDate(), WordPress.getContext()));
// show avatar if it exists, otherwise show blavatar
if (post.hasPostAvatar()) {
String imageUrl = GravatarUtils.fixGravatarUrl(post.getPostAvatar(), mAvatarSzMedium);
holder.imgAvatarOrBlavatar.setImageUrl(imageUrl, WPNetworkImageView.ImageType.AVATAR);
holder.imgAvatarOrBlavatar.setVisibility(View.VISIBLE);
} else if (post.hasBlogImageUrl()) {
String imageUrl = GravatarUtils.fixGravatarUrl(post.getBlogImageUrl(), mAvatarSzMedium);
holder.imgAvatarOrBlavatar.setImageUrl(imageUrl, WPNetworkImageView.ImageType.BLAVATAR);
holder.imgAvatarOrBlavatar.setVisibility(View.VISIBLE);
} else {
holder.imgAvatarOrBlavatar.setVisibility(View.GONE);
}
// show author and blog name if both are available, otherwise show whichever is available
if (post.hasBlogName() && post.hasAuthorName() && !post.getBlogName().equals(post.getAuthorName())) {
holder.txtAuthorAndBlogName.setText(post.getAuthorName() + ", " + post.getBlogName());
} else if (post.hasBlogName()) {
holder.txtAuthorAndBlogName.setText(post.getBlogName());
} else if (post.hasAuthorName()) {
holder.txtAuthorAndBlogName.setText(post.getAuthorName());
} else {
holder.txtAuthorAndBlogName.setText(null);
}
if (post.getCardType() == ReaderCardType.PHOTO) {
// posts with a suitable featured image that have very little text get the "photo
// card" treatment - show the title overlaid on the featured image without any text
holder.txtText.setVisibility(View.GONE);
holder.txtTitle.setVisibility(View.GONE);
holder.framePhoto.setVisibility(View.VISIBLE);
holder.txtPhotoTitle.setVisibility(View.VISIBLE);
holder.txtPhotoTitle.setText(post.getTitle());
holder.imgFeatured.setImageUrl(post.getFeaturedImageForDisplay(mPhotonWidth, mPhotonHeight), WPNetworkImageView.ImageType.PHOTO);
holder.thumbnailStrip.setVisibility(View.GONE);
} else {
holder.txtTitle.setVisibility(View.VISIBLE);
holder.txtTitle.setText(post.getTitle());
holder.txtPhotoTitle.setVisibility(View.GONE);
if (post.hasExcerpt()) {
holder.txtText.setVisibility(View.VISIBLE);
holder.txtText.setText(post.getExcerpt());
} else {
holder.txtText.setVisibility(View.GONE);
}
final int titleMargin;
if (post.getCardType() == ReaderCardType.GALLERY) {
// if this post is a gallery, scan it for images and show a thumbnail strip of
// them - note that the thumbnail strip will take care of making itself visible
holder.thumbnailStrip.loadThumbnails(post.blogId, post.postId, post.isPrivate);
holder.framePhoto.setVisibility(View.GONE);
titleMargin = mMarginLarge;
} else if (post.getCardType() == ReaderCardType.VIDEO) {
holder.imgFeatured.setVideoUrl(post.postId, post.getFeaturedVideo());
holder.framePhoto.setVisibility(View.VISIBLE);
holder.thumbnailStrip.setVisibility(View.GONE);
titleMargin = mMarginLarge;
} else if (post.hasFeaturedImage()) {
holder.imgFeatured.setImageUrl(post.getFeaturedImageForDisplay(mPhotonWidth, mPhotonHeight), WPNetworkImageView.ImageType.PHOTO);
holder.framePhoto.setVisibility(View.VISIBLE);
holder.thumbnailStrip.setVisibility(View.GONE);
titleMargin = mMarginLarge;
} else {
holder.framePhoto.setVisibility(View.GONE);
holder.thumbnailStrip.setVisibility(View.GONE);
titleMargin = 0;
}
// set the top margin of the title based on whether there's a featured image
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.txtTitle.getLayoutParams();
params.topMargin = titleMargin;
}
// show the video overlay (play icon) when there's a featured video
holder.imgVideoOverlay.setVisibility(post.getCardType() == ReaderCardType.VIDEO ? View.VISIBLE : View.GONE);
showLikes(holder, post);
showComments(holder, post);
// more menu only shows for followed tags
if (!mIsLoggedOutReader && postListType == ReaderTypes.ReaderPostListType.TAG_FOLLOWED) {
holder.imgMore.setVisibility(View.VISIBLE);
holder.imgMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mOnPostPopupListener != null) {
mOnPostPopupListener.onShowPostPopup(view, post);
}
}
});
} else {
holder.imgMore.setVisibility(View.GONE);
holder.imgMore.setOnClickListener(null);
}
if (shouldShowFollowButton()) {
holder.followButton.setIsFollowed(post.isFollowedByCurrentUser);
holder.followButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggleFollow(view.getContext(), view, post);
}
});
holder.followButton.setVisibility(View.VISIBLE);
} else {
holder.followButton.setVisibility(View.GONE);
}
// attribution section for discover posts
if (post.isDiscoverPost()) {
showDiscoverData(holder, post);
} else {
holder.layoutDiscover.setVisibility(View.GONE);
}
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mPostSelectedListener != null) {
mPostSelectedListener.onPostSelected(post);
}
}
});
checkLoadMore(position);
// to the rendered list and record the TrainTracks render event
if (post.hasRailcar() && !mRenderedIds.contains(post.getPseudoId())) {
mRenderedIds.add(post.getPseudoId());
AnalyticsUtils.trackRailcarRender(post.getRailcarJson());
}
}
use of org.wordpress.android.models.ReaderPost in project WordPress-Android by wordpress-mobile.
the class ReaderPostAdapter method removePostsInBlog.
public void removePostsInBlog(long blogId) {
int numRemoved = 0;
ReaderPostList postsInBlog = mPosts.getPostsInBlog(blogId);
for (ReaderPost post : postsInBlog) {
int index = mPosts.indexOfPost(post);
if (index > -1) {
numRemoved++;
mPosts.remove(index);
}
}
if (numRemoved > 0) {
notifyDataSetChanged();
}
}
use of org.wordpress.android.models.ReaderPost in project WordPress-Android by wordpress-mobile.
the class ReaderPostPagerActivity method showPost.
private void showPost(@NonNull InterceptType interceptType, final String blogIdentifier, final String postIdentifier) {
if (!TextUtils.isEmpty(blogIdentifier) && !TextUtils.isEmpty(postIdentifier)) {
mIsSinglePostView = true;
mIsRelatedPostView = false;
switch(interceptType) {
case READER_BLOG:
if (parseIds(blogIdentifier, postIdentifier)) {
AnalyticsUtils.trackWithBlogPostDetails(AnalyticsTracker.Stat.READER_BLOG_POST_INTERCEPTED, mBlogId, mPostId);
// IDs have now been set so, let ReaderPostPagerActivity normally display the post
} else {
ToastUtils.showToast(this, R.string.error_generic);
}
break;
case READER_FEED:
if (parseIds(blogIdentifier, postIdentifier)) {
AnalyticsUtils.trackWithFeedPostDetails(AnalyticsTracker.Stat.READER_FEED_POST_INTERCEPTED, mBlogId, mPostId);
// IDs have now been set so, let ReaderPostPagerActivity normally display the post
} else {
ToastUtils.showToast(this, R.string.error_generic);
}
break;
case WPCOM_POST_SLUG:
AnalyticsUtils.trackWithBlogPostDetails(AnalyticsTracker.Stat.READER_WPCOM_BLOG_POST_INTERCEPTED, blogIdentifier, postIdentifier, mCommentId);
// try to get the post from the local db
ReaderPost post = ReaderPostTable.getBlogPost(blogIdentifier, postIdentifier, true);
if (post != null) {
// set the IDs and let ReaderPostPagerActivity normally display the post
mBlogId = post.blogId;
mPostId = post.postId;
} else {
// not stored locally, so request it
ReaderPostActions.requestBlogPost(blogIdentifier, postIdentifier, new ReaderActions.OnRequestListener() {
@Override
public void onSuccess() {
mPostSlugsResolutionUnderway = false;
ReaderPost post = ReaderPostTable.getBlogPost(blogIdentifier, postIdentifier, true);
ReaderEvents.PostSlugsRequestCompleted slugsResolved = (post != null) ? new ReaderEvents.PostSlugsRequestCompleted(200, post.blogId, post.postId) : new ReaderEvents.PostSlugsRequestCompleted(200, 0, 0);
// notify that the slug resolution request has completed
EventBus.getDefault().post(slugsResolved);
// post wasn't available locally earlier so, track it now
if (post != null) {
trackPost(post.blogId, post.postId);
}
}
@Override
public void onFailure(int statusCode) {
mPostSlugsResolutionUnderway = false;
// notify that the slug resolution request has completed
EventBus.getDefault().post(new ReaderEvents.PostSlugsRequestCompleted(statusCode, 0, 0));
}
});
mPostSlugsResolutionUnderway = true;
}
break;
}
} else {
ToastUtils.showToast(this, R.string.error_generic);
}
}
use of org.wordpress.android.models.ReaderPost in project WordPress-Android by wordpress-mobile.
the class ReaderPostTable method getPostFromCursor.
private static ReaderPost getPostFromCursor(Cursor c) {
if (c == null) {
throw new IllegalArgumentException("getPostFromCursor > null cursor");
}
ReaderPost post = new ReaderPost();
// text column is skipped when retrieving multiple rows
int idxText = c.getColumnIndex("text");
if (idxText > -1) {
post.setText(c.getString(idxText));
}
post.postId = c.getLong(c.getColumnIndex("post_id"));
post.blogId = c.getLong(c.getColumnIndex("blog_id"));
post.feedId = c.getLong(c.getColumnIndex("feed_id"));
post.feedItemId = c.getLong(c.getColumnIndex("feed_item_id"));
post.authorId = c.getLong(c.getColumnIndex("author_id"));
post.setPseudoId(c.getString(c.getColumnIndex("pseudo_id")));
post.setAuthorName(c.getString(c.getColumnIndex("author_name")));
post.setAuthorFirstName(c.getString(c.getColumnIndex("author_first_name")));
post.setBlogName(c.getString(c.getColumnIndex("blog_name")));
post.setBlogUrl(c.getString(c.getColumnIndex("blog_url")));
post.setBlogImageUrl(c.getString(c.getColumnIndex("blog_image_url")));
post.setExcerpt(c.getString(c.getColumnIndex("excerpt")));
post.setFormat(c.getString(c.getColumnIndex("format")));
post.setFeaturedImage(c.getString(c.getColumnIndex("featured_image")));
post.setFeaturedVideo(c.getString(c.getColumnIndex("featured_video")));
post.setTitle(c.getString(c.getColumnIndex("title")));
post.setUrl(c.getString(c.getColumnIndex("url")));
post.setShortUrl(c.getString(c.getColumnIndex("short_url")));
post.setPostAvatar(c.getString(c.getColumnIndex("post_avatar")));
post.setDatePublished(c.getString(c.getColumnIndex("date_published")));
post.setDateLiked(c.getString(c.getColumnIndex("date_liked")));
post.setDateTagged(c.getString(c.getColumnIndex("date_tagged")));
post.score = c.getDouble(c.getColumnIndex("score"));
post.numReplies = c.getInt(c.getColumnIndex("num_replies"));
post.numLikes = c.getInt(c.getColumnIndex("num_likes"));
post.isLikedByCurrentUser = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_liked")));
post.isFollowedByCurrentUser = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_followed")));
post.isCommentsOpen = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_comments_open")));
post.isExternal = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_external")));
post.isPrivate = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_private")));
post.isVideoPress = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_videopress")));
post.isJetpack = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_jetpack")));
post.setPrimaryTag(c.getString(c.getColumnIndex("primary_tag")));
post.setSecondaryTag(c.getString(c.getColumnIndex("secondary_tag")));
post.setAttachmentsJson(c.getString(c.getColumnIndex("attachments_json")));
post.setDiscoverJson(c.getString(c.getColumnIndex("discover_json")));
post.xpostPostId = c.getLong(c.getColumnIndex("xpost_post_id"));
post.xpostBlogId = c.getLong(c.getColumnIndex("xpost_blog_id"));
post.setRailcarJson(c.getString(c.getColumnIndex("railcar_json")));
post.setCardType(ReaderCardType.fromString(c.getString(c.getColumnIndex("card_type"))));
return post;
}
use of org.wordpress.android.models.ReaderPost in project WordPress-Android by wordpress-mobile.
the class ReaderPostTable method addOrUpdatePosts.
public static void addOrUpdatePosts(final ReaderTag tag, ReaderPostList posts) {
if (posts == null || posts.size() == 0) {
return;
}
SQLiteDatabase db = ReaderDatabase.getWritableDb();
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,?30,?31,?32,?33,?34,?35,?36,?37,?38,?39,?40,?41,?42,?43,?44)");
db.beginTransaction();
try {
String tagName = (tag != null ? tag.getTagSlug() : "");
int tagType = (tag != null ? tag.tagType.toInt() : 0);
// we can safely assume there's no gap marker because any existing gap marker is
// already removed before posts are updated
boolean hasGapMarker = false;
for (ReaderPost post : posts) {
stmtPosts.bindLong(1, post.postId);
stmtPosts.bindLong(2, post.blogId);
stmtPosts.bindLong(3, post.feedId);
stmtPosts.bindLong(4, post.feedItemId);
stmtPosts.bindString(5, post.getPseudoId());
stmtPosts.bindString(6, post.getAuthorName());
stmtPosts.bindString(7, post.getAuthorFirstName());
stmtPosts.bindLong(8, post.authorId);
stmtPosts.bindString(9, post.getTitle());
stmtPosts.bindString(10, maxText(post));
stmtPosts.bindString(11, post.getExcerpt());
stmtPosts.bindString(12, post.getFormat());
stmtPosts.bindString(13, post.getUrl());
stmtPosts.bindString(14, post.getShortUrl());
stmtPosts.bindString(15, post.getBlogName());
stmtPosts.bindString(16, post.getBlogUrl());
stmtPosts.bindString(17, post.getBlogImageUrl());
stmtPosts.bindString(18, post.getFeaturedImage());
stmtPosts.bindString(19, post.getFeaturedVideo());
stmtPosts.bindString(20, post.getPostAvatar());
stmtPosts.bindDouble(21, post.score);
stmtPosts.bindString(22, post.getDatePublished());
stmtPosts.bindString(23, post.getDateLiked());
stmtPosts.bindString(24, post.getDateTagged());
stmtPosts.bindLong(25, post.numReplies);
stmtPosts.bindLong(26, post.numLikes);
stmtPosts.bindLong(27, SqlUtils.boolToSql(post.isLikedByCurrentUser));
stmtPosts.bindLong(28, SqlUtils.boolToSql(post.isFollowedByCurrentUser));
stmtPosts.bindLong(29, SqlUtils.boolToSql(post.isCommentsOpen));
stmtPosts.bindLong(30, SqlUtils.boolToSql(post.isExternal));
stmtPosts.bindLong(31, SqlUtils.boolToSql(post.isPrivate));
stmtPosts.bindLong(32, SqlUtils.boolToSql(post.isVideoPress));
stmtPosts.bindLong(33, SqlUtils.boolToSql(post.isJetpack));
stmtPosts.bindString(34, post.getPrimaryTag());
stmtPosts.bindString(35, post.getSecondaryTag());
stmtPosts.bindString(36, post.getAttachmentsJson());
stmtPosts.bindString(37, post.getDiscoverJson());
stmtPosts.bindLong(38, post.xpostPostId);
stmtPosts.bindLong(39, post.xpostBlogId);
stmtPosts.bindString(40, post.getRailcarJson());
stmtPosts.bindString(41, tagName);
stmtPosts.bindLong(42, tagType);
stmtPosts.bindLong(43, SqlUtils.boolToSql(hasGapMarker));
stmtPosts.bindString(44, ReaderCardType.toString(post.getCardType()));
stmtPosts.execute();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
SqlUtils.closeStatement(stmtPosts);
}
}
Aggregations