Search in sources :

Example 86 with Gson

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

the class CommentToMeTimeLineDBTask method getPosition.

public static TimeLinePosition getPosition(String accountId) {
    String sql = "select * from " + CommentsTable.TABLE_NAME + " where " + CommentsTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(CommentsTable.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 87 with Gson

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

the class CommentToMeTimeLineDBTask 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 " + CommentsTable.CommentsDataTable.TABLE_NAME + " where " + CommentsTable.CommentsDataTable.ACCOUNTID + "  = " + accountId + " order by " + CommentsTable.CommentsDataTable.MBLOGID + " desc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(CommentsTable.CommentsDataTable.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();
    return new CommentTimeLineData(result, position);
}
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 88 with Gson

use of com.google.gson.Gson 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 89 with Gson

use of com.google.gson.Gson 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 90 with Gson

use of com.google.gson.Gson 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)

Aggregations

Gson (com.google.gson.Gson)1309 Test (org.junit.Test)280 HashMap (java.util.HashMap)227 GsonBuilder (com.google.gson.GsonBuilder)174 JsonObject (com.google.gson.JsonObject)157 IOException (java.io.IOException)147 CommandWrapper (ClientServerApi.CommandWrapper)123 ArrayList (java.util.ArrayList)121 CommandExecuter (CommandHandler.CommandExecuter)119 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)118 JsonSyntaxException (com.google.gson.JsonSyntaxException)103 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)96 JsonElement (com.google.gson.JsonElement)78 Type (java.lang.reflect.Type)77 Map (java.util.Map)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)53 SmartCode (BasicCommonClasses.SmartCode)50 InputStreamReader (java.io.InputStreamReader)49 List (java.util.List)49 TypeToken (com.google.gson.reflect.TypeToken)44