Search in sources :

Example 81 with Gson

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

the class AtUsersDBTask method add.

public static void add(SQLiteDatabase db, AtUserBean atUserBean, String accountId) {
    Gson gson = new Gson();
    ContentValues cv = new ContentValues();
    cv.put(AtUsersTable.USERID, atUserBean.getUid());
    cv.put(AtUsersTable.ACCOUNTID, accountId);
    String json = gson.toJson(atUserBean);
    cv.put(AtUsersTable.JSONDATA, json);
    db.replace(AtUsersTable.TABLE_NAME, AtUsersTable.ID, cv);
    reduce(accountId);
}
Also used : ContentValues(android.content.ContentValues) Gson(com.google.gson.Gson)

Example 82 with Gson

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

the class CommentByMeTimeLineDBTask method updatePosition.

private static void updatePosition(TimeLinePosition position, String accountId) {
    String sql = "select * from " + CommentByMeTable.TABLE_NAME + " where " + CommentByMeTable.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(CommentByMeTable.TIMELINEDATA, gson.toJson(position));
            getWsd().update(CommentByMeTable.TABLE_NAME, cv, CommentByMeTable.ACCOUNTID + "=?", args);
        } catch (JsonSyntaxException e) {
        }
    } else {
        ContentValues cv = new ContentValues();
        cv.put(CommentByMeTable.ACCOUNTID, accountId);
        cv.put(CommentByMeTable.TIMELINEDATA, gson.toJson(position));
        getWsd().insert(CommentByMeTable.TABLE_NAME, CommentByMeTable.ID, cv);
    }
}
Also used : ContentValues(android.content.ContentValues) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Example 83 with Gson

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

the class CommentByMeTimeLineDBTask method getCommentLineMsgList.

public static CommentTimeLineData getCommentLineMsgList(String accountId) {
    TimeLinePosition position = getPosition(accountId);
    CommentListBean result = new CommentListBean();
    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;
    List<CommentBean> msgList = new ArrayList<CommentBean>();
    String sql = "select * from " + CommentByMeTable.CommentByMeDataTable.TABLE_NAME + " where " + CommentByMeTable.CommentByMeDataTable.ACCOUNTID + "  = " + accountId + " order by " + CommentByMeTable.CommentByMeDataTable.MBLOGID + " desc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(CommentByMeTable.CommentByMeDataTable.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 84 with Gson

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

the class CommentByMeTimeLineDBTask method getPosition.

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

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

the class CommentToMeTimeLineDBTask method updatePosition.

private static void updatePosition(TimeLinePosition position, String accountId) {
    String sql = "select * from " + CommentsTable.TABLE_NAME + " where " + CommentsTable.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(CommentsTable.TIMELINEDATA, gson.toJson(position));
            getWsd().update(CommentsTable.TABLE_NAME, cv, CommentsTable.ACCOUNTID + "=?", args);
        } catch (JsonSyntaxException e) {
        }
    } else {
        ContentValues cv = new ContentValues();
        cv.put(CommentsTable.ACCOUNTID, accountId);
        cv.put(CommentsTable.TIMELINEDATA, gson.toJson(position));
        getWsd().insert(CommentsTable.TABLE_NAME, CommentsTable.ID, cv);
    }
}
Also used : ContentValues(android.content.ContentValues) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

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