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