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);
}
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);
}
}
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);
}
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();
}
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);
}
}
Aggregations