Search in sources :

Example 1 with DraftListViewItemBean

use of org.qii.weiciyuan.support.database.draftbean.DraftListViewItemBean in project weiciyuan by qii.

the class DraftDBManager method getDraftList.

public List<DraftListViewItemBean> getDraftList(String accountId) {
    Gson gson = new Gson();
    List<DraftListViewItemBean> result = new ArrayList<DraftListViewItemBean>();
    String sql = "select * from " + DraftTable.TABLE_NAME + " where " + DraftTable.ACCOUNTID + "  = " + accountId + " order by " + DraftTable.ID + " desc";
    Cursor c = rsd.rawQuery(sql, null);
    while (c.moveToNext()) {
        DraftListViewItemBean item = new DraftListViewItemBean();
        int type = c.getInt(c.getColumnIndex(DraftTable.TYPE));
        item.setType(type);
        item.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
        String content;
        switch(type) {
            case DraftTable.TYPE_WEIBO:
                content = c.getString(c.getColumnIndex(DraftTable.CONTENT));
                StatusDraftBean bean = new StatusDraftBean();
                bean.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
                bean.setContent(content);
                bean.setAccountId(accountId);
                String gpsJson = c.getString(c.getColumnIndex(DraftTable.GPS));
                if (!TextUtils.isEmpty(gpsJson)) {
                    bean.setGps(new Gson().fromJson(gpsJson, GeoBean.class));
                }
                bean.setPic(c.getString(c.getColumnIndex(DraftTable.PIC)));
                item.setStatusDraftBean(bean);
                result.add(item);
                break;
            case DraftTable.TYPE_REPOST:
                content = c.getString(c.getColumnIndex(DraftTable.CONTENT));
                RepostDraftBean repostDraftBean = new RepostDraftBean();
                repostDraftBean.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
                repostDraftBean.setContent(content);
                repostDraftBean.setAccountId(accountId);
                MessageBean messageBean = gson.fromJson(c.getString(c.getColumnIndex(DraftTable.JSONDATA)), MessageBean.class);
                repostDraftBean.setMessageBean(messageBean);
                item.setRepostDraftBean(repostDraftBean);
                result.add(item);
                break;
            case DraftTable.TYPE_COMMENT:
                content = c.getString(c.getColumnIndex(DraftTable.CONTENT));
                CommentDraftBean commentDraftBean = new CommentDraftBean();
                commentDraftBean.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
                commentDraftBean.setContent(content);
                commentDraftBean.setAccountId(accountId);
                MessageBean commentMessageBean = gson.fromJson(c.getString(c.getColumnIndex(DraftTable.JSONDATA)), MessageBean.class);
                commentDraftBean.setMessageBean(commentMessageBean);
                item.setCommentDraftBean(commentDraftBean);
                result.add(item);
                break;
            case DraftTable.TYPE_REPLY:
                content = c.getString(c.getColumnIndex(DraftTable.CONTENT));
                ReplyDraftBean replyDraftBean = new ReplyDraftBean();
                replyDraftBean.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
                replyDraftBean.setContent(content);
                replyDraftBean.setAccountId(accountId);
                CommentBean commentBean = gson.fromJson(c.getString(c.getColumnIndex(DraftTable.JSONDATA)), CommentBean.class);
                replyDraftBean.setCommentBean(commentBean);
                item.setReplyDraftBean(replyDraftBean);
                result.add(item);
                break;
        }
    }
    c.close();
    return result;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) ReplyDraftBean(org.qii.weiciyuan.support.database.draftbean.ReplyDraftBean) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) DraftListViewItemBean(org.qii.weiciyuan.support.database.draftbean.DraftListViewItemBean) Cursor(android.database.Cursor) CommentBean(org.qii.weiciyuan.bean.CommentBean) GeoBean(org.qii.weiciyuan.bean.GeoBean) StatusDraftBean(org.qii.weiciyuan.support.database.draftbean.StatusDraftBean) RepostDraftBean(org.qii.weiciyuan.support.database.draftbean.RepostDraftBean) CommentDraftBean(org.qii.weiciyuan.support.database.draftbean.CommentDraftBean)

Aggregations

Cursor (android.database.Cursor)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 CommentBean (org.qii.weiciyuan.bean.CommentBean)1 GeoBean (org.qii.weiciyuan.bean.GeoBean)1 MessageBean (org.qii.weiciyuan.bean.MessageBean)1 CommentDraftBean (org.qii.weiciyuan.support.database.draftbean.CommentDraftBean)1 DraftListViewItemBean (org.qii.weiciyuan.support.database.draftbean.DraftListViewItemBean)1 ReplyDraftBean (org.qii.weiciyuan.support.database.draftbean.ReplyDraftBean)1 RepostDraftBean (org.qii.weiciyuan.support.database.draftbean.RepostDraftBean)1 StatusDraftBean (org.qii.weiciyuan.support.database.draftbean.StatusDraftBean)1