Android Open Source - Android-VKontakte-SDK Comment






From Project

Back to project page Android-VKontakte-SDK.

License

The source code is released under:

MIT License

If you think the Android project Android-VKontakte-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.perm.kate.api;
//w ww.j ava  2s .  co m
import java.io.Serializable;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Comment implements Serializable {
    private static final long serialVersionUID = 1L;
    public long cid;
    public long from_id;
    public long date;
    public String message;
    public long reply_to_uid;
    public long reply_to_cid;
    public WallMessage post;//parent post, used only for notifications type "reply_comment". Can be moved to Notification class.
    public ArrayList<Attachment> attachments=new ArrayList<Attachment>();

    //likes
    public int like_count;
    public boolean user_like;
    public boolean can_like;

    public static Comment parse(JSONObject o) throws NumberFormatException, JSONException{
        Comment comment=new Comment();
        comment.cid = o.optLong("id");
        //? newsfeed.getComments ??????????? ????????? ??-???????? - ??? ? API
        if(!o.has("id") && o.has("cid"))
            comment.cid = o.optLong("cid");
        
        comment.from_id = o.optLong("from_id");
        comment.date = o.optLong("date");
        comment.message = Api.unescape(o.optString("text"));
        String reply_to_uid = o.optString("reply_to_user");
        if (reply_to_uid != null && !reply_to_uid.equals(""))
            comment.reply_to_uid = Long.parseLong(reply_to_uid);
        String reply_to_cid = o.optString("reply_to_comment");
        if (reply_to_cid != null && !reply_to_cid.equals(""))
            comment.reply_to_cid = Long.parseLong(reply_to_cid);
        parseLikes(o, comment);
        
        JSONArray attachments=o.optJSONArray("attachments");
        comment.attachments=Attachment.parseAttachments(attachments, 0, 0, null);
        
        return comment;
    }

    private static void parseLikes(JSONObject o, Comment comment) throws JSONException {
        if (o.has("likes")){
            JSONObject jlikes = o.getJSONObject("likes");
            comment.like_count = jlikes.optInt("count");
            comment.user_like = jlikes.optInt("user_likes")==1;
            comment.can_like = jlikes.optInt("can_like")==1;
        }
    }

    //for group topic comments 
    public static Comment parseTopicComment(JSONObject o) throws NumberFormatException, JSONException {
        Comment comment = new Comment();
        comment.cid = o.getLong("id");
        comment.from_id = o.optLong("from_id");
        comment.date = o.optLong("date");
        comment.message = Api.unescape(o.optString("text"));
        parseLikes(o, comment);
        
        JSONArray attachments=o.optJSONArray("attachments");
        comment.attachments=Attachment.parseAttachments(attachments, 0, 0, null);
        
        return comment;
    }
     
    public static Comment parseNoteComment(JSONObject o) throws NumberFormatException, JSONException {
        Comment comment = new Comment();
        comment.cid = Long.parseLong(o.getString("id"));
        comment.from_id = Long.parseLong(o.getString("uid"));
        comment.date = Long.parseLong(o.getString("date"));
        comment.message = Api.unescape(o.getString("message"));
        comment.reply_to_uid=o.optLong("reply_to");
        return comment;
    }
    
    public static Comment parseNotificationComment(JSONObject o, boolean parse_post) throws NumberFormatException, JSONException{
        Comment comment = new Comment();
        comment.cid = o.getLong("id");
        if(o.has("owner_id"))
            comment.from_id = o.getLong("owner_id");
        else
            comment.from_id = o.getLong("from_id");//or uid. fix for reply_comment ? comment_post, ???? feedback. ??? ? API.
        comment.date = o.getLong("date");
        comment.message = Api.unescape(o.getString("text"));
        if (o.has("likes")){
            JSONObject jlikes = o.getJSONObject("likes");
            comment.like_count = jlikes.optInt("count");
            comment.user_like = jlikes.optInt("user_likes")==1;
        }
        if(parse_post){
            JSONObject post_json=o.getJSONObject("post");
            comment.post=WallMessage.parse(post_json);
        }
        return comment;
    }
}




Java Source Code List

com.perm.kate.api.Album.java
com.perm.kate.api.Api.java
com.perm.kate.api.Attachment.java
com.perm.kate.api.AudioAlbum.java
com.perm.kate.api.Audio.java
com.perm.kate.api.Auth.java
com.perm.kate.api.BanInfo.java
com.perm.kate.api.BannArg.java
com.perm.kate.api.City.java
com.perm.kate.api.CommentList.java
com.perm.kate.api.Comment.java
com.perm.kate.api.Constants.java
com.perm.kate.api.Contact.java
com.perm.kate.api.Counters.java
com.perm.kate.api.Country.java
com.perm.kate.api.Document.java
com.perm.kate.api.FriendsList.java
com.perm.kate.api.Geo.java
com.perm.kate.api.Gift.java
com.perm.kate.api.Graffiti.java
com.perm.kate.api.GroupBanItem.java
com.perm.kate.api.GroupTopic.java
com.perm.kate.api.Group.java
com.perm.kate.api.IdsPair.java
com.perm.kate.api.KException.java
com.perm.kate.api.LastActivity.java
com.perm.kate.api.Link.java
com.perm.kate.api.Media.java
com.perm.kate.api.Message.java
com.perm.kate.api.NameCases.java
com.perm.kate.api.NewsItem.java
com.perm.kate.api.NewsJTags.java
com.perm.kate.api.NewsTypes.java
com.perm.kate.api.Newsfeed.java
com.perm.kate.api.Note.java
com.perm.kate.api.Notification.java
com.perm.kate.api.Notifications.java
com.perm.kate.api.Page.java
com.perm.kate.api.Params.java
com.perm.kate.api.PhotoComment.java
com.perm.kate.api.PhotoTag.java
com.perm.kate.api.Photo.java
com.perm.kate.api.Place.java
com.perm.kate.api.Reply.java
com.perm.kate.api.SearchDialogItem.java
com.perm.kate.api.User.java
com.perm.kate.api.Video.java
com.perm.kate.api.VkApp.java
com.perm.kate.api.VkPollAnswer.java
com.perm.kate.api.VkPoll.java
com.perm.kate.api.VkStatus.java
com.perm.kate.api.WallMessage.java
com.perm.kate.api.sample.Account.java
com.perm.kate.api.sample.Constants.java
com.perm.kate.api.sample.LoginActivity.java
com.perm.kate.api.sample.MainActivity.java
com.perm.utils.Utils.java
com.perm.utils.WrongResponseCodeException.java