Search in sources :

Example 6 with ReaderPost

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());
    }
}
Also used : ReaderTypes(org.wordpress.android.ui.reader.ReaderTypes) ReaderGapMarkerView(org.wordpress.android.ui.reader.views.ReaderGapMarkerView) ReaderSiteHeaderView(org.wordpress.android.ui.reader.views.ReaderSiteHeaderView) ImageView(android.widget.ImageView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) View(android.view.View) ReaderTagHeaderView(org.wordpress.android.ui.reader.views.ReaderTagHeaderView) CardView(android.support.v7.widget.CardView) ReaderIconCountView(org.wordpress.android.ui.reader.views.ReaderIconCountView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ReaderPost(org.wordpress.android.models.ReaderPost) LinearLayout(android.widget.LinearLayout)

Example 7 with ReaderPost

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();
    }
}
Also used : ReaderPostList(org.wordpress.android.models.ReaderPostList) ReaderPost(org.wordpress.android.models.ReaderPost)

Example 8 with ReaderPost

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);
    }
}
Also used : ReaderPost(org.wordpress.android.models.ReaderPost) ReaderActions(org.wordpress.android.ui.reader.actions.ReaderActions)

Example 9 with ReaderPost

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;
}
Also used : ReaderPost(org.wordpress.android.models.ReaderPost)

Example 10 with ReaderPost

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);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) ReaderPost(org.wordpress.android.models.ReaderPost)

Aggregations

ReaderPost (org.wordpress.android.models.ReaderPost)10 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 Handler (android.os.Handler)1 CardView (android.support.v7.widget.CardView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 VolleyError (com.android.volley.VolleyError)1 RestRequest (com.wordpress.rest.RestRequest)1 JSONObject (org.json.JSONObject)1 ReaderPostList (org.wordpress.android.models.ReaderPostList)1 ReaderTypes (org.wordpress.android.ui.reader.ReaderTypes)1 ReaderActions (org.wordpress.android.ui.reader.actions.ReaderActions)1 UpdateResult (org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult)1 UpdateResultListener (org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener)1 ReaderGapMarkerView (org.wordpress.android.ui.reader.views.ReaderGapMarkerView)1 ReaderIconCountView (org.wordpress.android.ui.reader.views.ReaderIconCountView)1