Search in sources :

Example 31 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class HomeOtherGroupTimeLineDBTask method updateCount.

static void updateCount(String msgId, int commentCount, int repostCount) {
    String sql = "select * from " + HomeOtherGroupTable.HomeOtherGroupDataTable.TABLE_NAME + " where " + HomeOtherGroupTable.HomeOtherGroupDataTable.MBLOGID + "  = " + msgId + " order by " + HomeOtherGroupTable.HomeOtherGroupDataTable.ID + " asc limit 50";
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String id = c.getString(c.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.ID));
        String json = c.getString(c.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.JSONDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                MessageBean value = gson.fromJson(json, MessageBean.class);
                value.setComments_count(commentCount);
                value.setReposts_count(repostCount);
                String[] args = { id };
                ContentValues cv = new ContentValues();
                cv.put(HomeOtherGroupTable.HomeOtherGroupDataTable.JSONDATA, gson.toJson(value));
                getWsd().update(HomeOtherGroupTable.HomeOtherGroupDataTable.TABLE_NAME, cv, HomeOtherGroupTable.HomeOtherGroupDataTable.ID + "=?", args);
            } catch (JsonSyntaxException e) {
            }
        }
    }
}
Also used : ContentValues(android.content.ContentValues) MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Example 32 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class HomeOtherGroupTimeLineDBTask method getPosition.

static TimeLinePosition getPosition(String accountId, String groupId) {
    String sql = "select * from " + HomeOtherGroupTable.TABLE_NAME + " where " + HomeOtherGroupTable.ACCOUNTID + "  = " + accountId + " and " + HomeOtherGroupTable.GROUPID + " = " + groupId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(HomeOtherGroupTable.TIMELINEDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                TimeLinePosition value = gson.fromJson(json, TimeLinePosition.class);
                c.close();
                return value;
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    c.close();
    return TimeLinePosition.empty();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) Cursor(android.database.Cursor)

Example 33 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class MentionCommentsTimeLineDBTask method getCommentLineMsgList.

public static CommentTimeLineData getCommentLineMsgList(String accountId) {
    TimeLinePosition position = getPosition(accountId);
    int limit = position.position + AppConfig.DB_CACHE_COUNT_OFFSET > AppConfig.DEFAULT_MSG_COUNT_50 ? position.position + AppConfig.DB_CACHE_COUNT_OFFSET : AppConfig.DEFAULT_MSG_COUNT_50;
    CommentListBean result = new CommentListBean();
    List<CommentBean> msgList = new ArrayList<CommentBean>();
    String sql = "select * from " + MentionCommentsTable.MentionCommentsDataTable.TABLE_NAME + " where " + MentionCommentsTable.MentionCommentsDataTable.ACCOUNTID + "  = " + accountId + " order by " + MentionCommentsTable.MentionCommentsDataTable.MBLOGID + " desc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(MentionCommentsTable.MentionCommentsDataTable.JSONDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                CommentBean value = gson.fromJson(json, CommentBean.class);
                if (!value.isMiddleUnreadItem()) {
                    value.getListViewSpannableString();
                }
                msgList.add(value);
            } catch (JsonSyntaxException e) {
                AppLogger.e(e.getMessage());
            }
        } else {
            msgList.add(null);
        }
    }
    result.setComments(msgList);
    c.close();
    CommentTimeLineData mentionTimeLineData = new CommentTimeLineData(result, position);
    return mentionTimeLineData;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) CommentTimeLineData(org.qii.weiciyuan.bean.android.CommentTimeLineData) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) CommentListBean(org.qii.weiciyuan.bean.CommentListBean) Cursor(android.database.Cursor) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Example 34 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class MentionCommentsTimeLineDBTask method updatePosition.

private static void updatePosition(TimeLinePosition position, String accountId) {
    String sql = "select * from " + MentionCommentsTable.TABLE_NAME + " where " + MentionCommentsTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    if (c.moveToNext()) {
        try {
            String[] args = { accountId };
            ContentValues cv = new ContentValues();
            cv.put(MentionCommentsTable.TIMELINEDATA, gson.toJson(position));
            getWsd().update(MentionCommentsTable.TABLE_NAME, cv, MentionCommentsTable.ACCOUNTID + "=?", args);
        } catch (JsonSyntaxException e) {
        }
    } else {
        ContentValues cv = new ContentValues();
        cv.put(MentionCommentsTable.ACCOUNTID, accountId);
        cv.put(MentionCommentsTable.TIMELINEDATA, gson.toJson(position));
        getWsd().insert(MentionCommentsTable.TABLE_NAME, MentionCommentsTable.ID, cv);
    }
}
Also used : ContentValues(android.content.ContentValues) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Example 35 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class MentionCommentsTimeLineDBTask method getPosition.

public static TimeLinePosition getPosition(String accountId) {
    String sql = "select * from " + MentionCommentsTable.TABLE_NAME + " where " + MentionCommentsTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(MentionCommentsTable.TIMELINEDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                TimeLinePosition value = gson.fromJson(json, TimeLinePosition.class);
                c.close();
                return value;
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    c.close();
    return TimeLinePosition.empty();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) Cursor(android.database.Cursor)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)152 Gson (com.google.gson.Gson)103 HashMap (java.util.HashMap)40 Cursor (android.database.Cursor)33 ArrayList (java.util.ArrayList)26 IOException (java.io.IOException)24 MessageBean (org.qii.weiciyuan.bean.MessageBean)16 GsonBuilder (com.google.gson.GsonBuilder)15 BadRequestException (co.cask.cdap.common.BadRequestException)14 InputStreamReader (java.io.InputStreamReader)14 ContentValues (android.content.ContentValues)12 TimeLinePosition (org.qii.weiciyuan.bean.android.TimeLinePosition)12 Reader (java.io.Reader)10 Type (java.lang.reflect.Type)10 FileReader (java.io.FileReader)9 Path (javax.ws.rs.Path)9 CommentBean (org.qii.weiciyuan.bean.CommentBean)9 UserBean (org.qii.weiciyuan.bean.UserBean)9 JsonObject (com.google.gson.JsonObject)8 List (java.util.List)8