Search in sources :

Example 1 with FavBean

use of org.qii.weiciyuan.bean.FavBean in project weiciyuan by qii.

the class FavDao method executeTask.

private FavBean executeTask(String url) throws WeiboException {
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("id", id);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Post, url, map);
    try {
        FavBean value = new Gson().fromJson(jsonData, FavBean.class);
        if (value != null) {
            return value;
        }
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    return null;
}
Also used : FavBean(org.qii.weiciyuan.bean.FavBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) Gson(com.google.gson.Gson)

Example 2 with FavBean

use of org.qii.weiciyuan.bean.FavBean 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 3 with FavBean

use of org.qii.weiciyuan.bean.FavBean 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 4 with FavBean

use of org.qii.weiciyuan.bean.FavBean in project weiciyuan by qii.

the class FavListDao method getGSONMsgList.

public FavListBean getGSONMsgList() throws WeiboException {
    String json = getMsgListJson();
    Gson gson = new Gson();
    FavListBean value = null;
    try {
        value = gson.fromJson(json, FavListBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    if (value != null) {
        List<MessageBean> msgList = new ArrayList<MessageBean>();
        int size = value.getFavorites().size();
        for (int i = 0; i < size; i++) {
            msgList.add(value.getFavorites().get(i).getStatus());
        }
        Iterator<FavBean> iterator = value.getFavorites().iterator();
        while (iterator.hasNext()) {
            FavBean msg = iterator.next();
            if (msg.getStatus().getUser() == null) {
                iterator.remove();
            } else {
                msg.getStatus().getListViewSpannableString();
                TimeUtility.dealMills(msg.getStatus());
            }
        }
    }
    return value;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) FavBean(org.qii.weiciyuan.bean.FavBean) FavListBean(org.qii.weiciyuan.bean.FavListBean) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 FavBean (org.qii.weiciyuan.bean.FavBean)4 Cursor (android.database.Cursor)2 ArrayList (java.util.ArrayList)2 FavListBean (org.qii.weiciyuan.bean.FavListBean)2 ContentValues (android.content.ContentValues)1 DatabaseUtils (android.database.DatabaseUtils)1 SQLException (android.database.SQLException)1 HashMap (java.util.HashMap)1 MessageBean (org.qii.weiciyuan.bean.MessageBean)1 FavouriteTimeLineData (org.qii.weiciyuan.bean.android.FavouriteTimeLineData)1