Search in sources :

Example 36 with JsonSyntaxException

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

the class MentionWeiboTimeLineDBTask method getPosition.

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

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

the class FavouriteDBTask method updatePosition.

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

Example 38 with JsonSyntaxException

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

the class FavouriteDBTask method getFavouriteMsgList.

public static FavouriteTimeLineData getFavouriteMsgList(String accountId) {
    FavListBean result = new FavListBean();
    List<FavBean> msgList = new ArrayList<FavBean>();
    String sql = "select * from " + FavouriteTable.FavouriteDataTable.TABLE_NAME + " where " + FavouriteTable.FavouriteDataTable.ACCOUNTID + "  = " + accountId + " order by " + FavouriteTable.FavouriteDataTable.MBLOGID + " desc";
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(FavouriteTable.FavouriteDataTable.JSONDATA));
        try {
            FavBean value = gson.fromJson(json, FavBean.class);
            if (value != null && !value.getStatus().isMiddleUnreadItem()) {
                value.getStatus().getListViewSpannableString();
            }
            msgList.add(value);
        } catch (JsonSyntaxException e) {
            AppLogger.e(e.getMessage());
        }
    }
    result.setFavorites(msgList);
    c.close();
    sql = "select * from " + FavouriteTable.TABLE_NAME + " where " + FavouriteTable.ACCOUNTID + "  = " + accountId;
    c = getRsd().rawQuery(sql, null);
    int page = 0;
    while (c.moveToNext()) {
        page = c.getInt(c.getColumnIndex(FavouriteTable.PAGE));
    }
    c.close();
    return new FavouriteTimeLineData(result, page, getPosition(accountId));
}
Also used : FavBean(org.qii.weiciyuan.bean.FavBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) FavListBean(org.qii.weiciyuan.bean.FavListBean) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) FavouriteTimeLineData(org.qii.weiciyuan.bean.android.FavouriteTimeLineData) Cursor(android.database.Cursor)

Example 39 with JsonSyntaxException

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

the class FavouriteDBTask method add.

private static void add(List<FavBean> msgList, int page, String accountId) {
    Gson gson = new Gson();
    DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), FavouriteTable.FavouriteDataTable.TABLE_NAME);
    final int mblogidColumn = ih.getColumnIndex(FavouriteTable.FavouriteDataTable.MBLOGID);
    final int accountidColumn = ih.getColumnIndex(FavouriteTable.FavouriteDataTable.ACCOUNTID);
    final int jsondataColumn = ih.getColumnIndex(FavouriteTable.FavouriteDataTable.JSONDATA);
    try {
        getWsd().beginTransaction();
        for (FavBean msg : msgList) {
            ih.prepareForInsert();
            ih.bind(mblogidColumn, msg.getStatus().getId());
            ih.bind(accountidColumn, accountId);
            String json = gson.toJson(msg);
            ih.bind(jsondataColumn, json);
            ih.execute();
        }
        getWsd().setTransactionSuccessful();
    } catch (SQLException e) {
    } finally {
        getWsd().endTransaction();
        ih.close();
    }
    String sql = "select * from " + FavouriteTable.TABLE_NAME + " where " + FavouriteTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    if (c.moveToNext()) {
        try {
            String[] args = { accountId };
            ContentValues cv = new ContentValues();
            cv.put(FavouriteTable.PAGE, page);
            getWsd().update(FavouriteTable.TABLE_NAME, cv, FavouriteTable.ACCOUNTID + "=?", args);
        } catch (JsonSyntaxException e) {
        }
    } else {
        ContentValues cv = new ContentValues();
        cv.put(FavouriteTable.ACCOUNTID, accountId);
        cv.put(FavouriteTable.PAGE, page);
        getWsd().insert(FavouriteTable.TABLE_NAME, FavouriteTable.ID, cv);
    }
}
Also used : ContentValues(android.content.ContentValues) FavBean(org.qii.weiciyuan.bean.FavBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) SQLException(android.database.SQLException) DatabaseUtils(android.database.DatabaseUtils) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Example 40 with JsonSyntaxException

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

the class FriendsTimeLineDBTask method getHomeLineMsgList.

private static MessageListBean getHomeLineMsgList(String accountId, int limitCount) {
    Gson gson = new Gson();
    MessageListBean result = new MessageListBean();
    int limit = limitCount > AppConfig.DEFAULT_MSG_COUNT_50 ? limitCount : AppConfig.DEFAULT_MSG_COUNT_50;
    List<MessageBean> msgList = new ArrayList<MessageBean>();
    String sql = "select * from " + HomeTable.HomeDataTable.TABLE_NAME + " where " + HomeTable.HomeDataTable.ACCOUNTID + "  = " + accountId + " order by " + HomeTable.HomeDataTable.ID + " asc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(HomeTable.HomeDataTable.JSONDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                MessageBean value = gson.fromJson(json, MessageBean.class);
                if (!value.isMiddleUnreadItem() && !TextUtils.isEmpty(value.getText())) {
                    value.getListViewSpannableString();
                }
                msgList.add(value);
            } catch (JsonSyntaxException e) {
                AppLogger.e(e.getMessage());
            }
        } else {
            msgList.add(null);
        }
    }
    //delete the null flag at the head positon and the end position
    for (int i = msgList.size() - 1; i >= 0; i--) {
        if (msgList.get(i) == null) {
            msgList.remove(i);
        } else {
            break;
        }
    }
    for (int i = 0; i < msgList.size(); i++) {
        if (msgList.get(i) == null) {
            msgList.remove(i);
        } else {
            break;
        }
    }
    result.setStatuses(msgList);
    c.close();
    return result;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) 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