Search in sources :

Example 1 with ReaderUser

use of org.wordpress.android.models.ReaderUser in project WordPress-Android by wordpress-mobile.

the class ReaderUserTable method getUserFromCursor.

private static ReaderUser getUserFromCursor(Cursor c) {
    ReaderUser user = new ReaderUser();
    user.userId = c.getLong(c.getColumnIndex("user_id"));
    user.blogId = c.getLong(c.getColumnIndex("blog_id"));
    user.setUserName(c.getString(c.getColumnIndex("user_name")));
    user.setDisplayName(c.getString(c.getColumnIndex("display_name")));
    user.setUrl(c.getString(c.getColumnIndex("url")));
    user.setProfileUrl(c.getString(c.getColumnIndex("profile_url")));
    user.setAvatarUrl(c.getString(c.getColumnIndex("avatar_url")));
    return user;
}
Also used : ReaderUser(org.wordpress.android.models.ReaderUser)

Example 2 with ReaderUser

use of org.wordpress.android.models.ReaderUser in project WordPress-Android by wordpress-mobile.

the class ReaderUserTable method addOrUpdateUsers.

public static void addOrUpdateUsers(ReaderUserList users) {
    if (users == null || users.size() == 0)
        return;
    SQLiteDatabase db = ReaderDatabase.getWritableDb();
    db.beginTransaction();
    SQLiteStatement stmt = db.compileStatement("INSERT OR REPLACE INTO tbl_users (" + COLUMN_NAMES + ") VALUES (?1,?2,?3,?4,?5,?6,?7)");
    try {
        for (ReaderUser user : users) {
            stmt.bindLong(1, user.userId);
            stmt.bindLong(2, user.blogId);
            stmt.bindString(3, user.getUserName());
            stmt.bindString(4, user.getDisplayName());
            stmt.bindString(5, user.getUrl());
            stmt.bindString(6, user.getProfileUrl());
            stmt.bindString(7, user.getAvatarUrl());
            stmt.execute();
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        SqlUtils.closeStatement(stmt);
    }
}
Also used : ReaderUser(org.wordpress.android.models.ReaderUser) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 3 with ReaderUser

use of org.wordpress.android.models.ReaderUser in project WordPress-Android by wordpress-mobile.

the class ReaderUserAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(UserViewHolder holder, int position) {
    final ReaderUser user = mUsers.get(position);
    holder.txtName.setText(user.getDisplayName());
    if (user.hasUrl()) {
        holder.txtUrl.setVisibility(View.VISIBLE);
        holder.txtUrl.setText(user.getUrlDomain());
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (user.hasBlogId()) {
                    ReaderActivityLauncher.showReaderBlogPreview(v.getContext(), user.blogId);
                }
            }
        });
    } else {
        holder.txtUrl.setVisibility(View.GONE);
        holder.itemView.setOnClickListener(null);
    }
    if (user.hasAvatarUrl()) {
        holder.imgAvatar.setImageUrl(GravatarUtils.fixGravatarUrl(user.getAvatarUrl(), mAvatarSz), WPNetworkImageView.ImageType.AVATAR);
    } else {
        holder.imgAvatar.showDefaultGravatarImage();
    }
}
Also used : ReaderUser(org.wordpress.android.models.ReaderUser) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 4 with ReaderUser

use of org.wordpress.android.models.ReaderUser in project WordPress-Android by wordpress-mobile.

the class ReaderCommentActions method submitPostComment.

/*
     * add the passed comment text to the passed post - caller must pass a unique "fake" comment id
     * to give the comment that's generated locally
     */
public static ReaderComment submitPostComment(final ReaderPost post, final long fakeCommentId, final String commentText, final long replyToCommentId, final ReaderActions.CommentActionListener actionListener, final long wpComUserId) {
    if (post == null || TextUtils.isEmpty(commentText)) {
        return null;
    }
    // determine which page this new comment should be assigned to
    final int pageNumber;
    if (replyToCommentId != 0) {
        pageNumber = ReaderCommentTable.getPageNumberForComment(post.blogId, post.postId, replyToCommentId);
    } else {
        pageNumber = ReaderCommentTable.getLastPageNumberForPost(post.blogId, post.postId);
    }
    // create a "fake" comment that's added to the db so it can be shown right away - will be
    // replaced with actual comment if it succeeds to be posted, or deleted if comment fails
    // to be posted
    ReaderComment newComment = new ReaderComment();
    newComment.commentId = fakeCommentId;
    newComment.postId = post.postId;
    newComment.blogId = post.blogId;
    newComment.parentId = replyToCommentId;
    newComment.pageNumber = pageNumber;
    newComment.setText(commentText);
    Date dtPublished = DateTimeUtils.nowUTC();
    newComment.setPublished(DateTimeUtils.iso8601FromDate(dtPublished));
    newComment.timestamp = dtPublished.getTime();
    ReaderUser currentUser = ReaderUserTable.getCurrentUser(wpComUserId);
    if (currentUser != null) {
        newComment.setAuthorAvatar(currentUser.getAvatarUrl());
        newComment.setAuthorName(currentUser.getDisplayName());
    }
    ReaderCommentTable.addOrUpdateComment(newComment);
    // different endpoint depending on whether the new comment is a reply to another comment
    final String path;
    if (replyToCommentId == 0) {
        path = "sites/" + post.blogId + "/posts/" + post.postId + "/replies/new";
    } else {
        path = "sites/" + post.blogId + "/comments/" + Long.toString(replyToCommentId) + "/replies/new";
    }
    Map<String, String> params = new HashMap<>();
    params.put("content", commentText);
    RestRequest.Listener listener = new RestRequest.Listener() {

        @Override
        public void onResponse(JSONObject jsonObject) {
            ReaderCommentTable.deleteComment(post, fakeCommentId);
            AppLog.i(T.READER, "comment succeeded");
            ReaderComment newComment = ReaderComment.fromJson(jsonObject, post.blogId);
            newComment.pageNumber = pageNumber;
            ReaderCommentTable.addOrUpdateComment(newComment);
            if (actionListener != null) {
                actionListener.onActionResult(true, newComment);
            }
        }
    };
    RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            ReaderCommentTable.deleteComment(post, fakeCommentId);
            AppLog.w(T.READER, "comment failed");
            AppLog.e(T.READER, volleyError);
            if (actionListener != null) {
                actionListener.onActionResult(false, null);
            }
        }
    };
    AppLog.i(T.READER, "submitting comment");
    WordPress.getRestClientUtilsV1_1().post(path, params, null, listener, errorListener);
    return newComment;
}
Also used : VolleyError(com.android.volley.VolleyError) ReaderUser(org.wordpress.android.models.ReaderUser) HashMap(java.util.HashMap) Date(java.util.Date) RestRequest(com.wordpress.rest.RestRequest) JSONObject(org.json.JSONObject) ReaderComment(org.wordpress.android.models.ReaderComment)

Aggregations

ReaderUser (org.wordpress.android.models.ReaderUser)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 VolleyError (com.android.volley.VolleyError)1 RestRequest (com.wordpress.rest.RestRequest)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1 ReaderComment (org.wordpress.android.models.ReaderComment)1 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)1