use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.
the class FriendsTimeLineDBTask method addHomeLineMsg.
private static void addHomeLineMsg(MessageListBean list, String accountId) {
if (list == null || list.getSize() == 0) {
return;
}
Gson gson = new Gson();
List<MessageBean> msgList = list.getItemList();
DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), HomeTable.HomeDataTable.TABLE_NAME);
final int mblogidColumn = ih.getColumnIndex(HomeTable.HomeDataTable.MBLOGID);
final int accountidColumn = ih.getColumnIndex(HomeTable.HomeDataTable.ACCOUNTID);
final int jsondataColumn = ih.getColumnIndex(HomeTable.HomeDataTable.JSONDATA);
try {
getWsd().beginTransaction();
for (int i = 0; i < msgList.size(); i++) {
MessageBean msg = msgList.get(i);
ih.prepareForInsert();
if (msg != null) {
ih.bind(mblogidColumn, msg.getId());
ih.bind(accountidColumn, accountId);
String json = gson.toJson(msg);
ih.bind(jsondataColumn, json);
} else {
ih.bind(mblogidColumn, "-1");
ih.bind(accountidColumn, accountId);
ih.bind(jsondataColumn, "");
}
ih.execute();
}
getWsd().setTransactionSuccessful();
} catch (SQLException e) {
} finally {
getWsd().endTransaction();
ih.close();
}
reduceHomeTable(accountId);
}
use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.
the class FriendsTimeLineDBTask method updateCount.
private static void updateCount(String msgId, int commentCount, int repostCount) {
String sql = "select * from " + HomeTable.HomeDataTable.TABLE_NAME + " where " + HomeTable.HomeDataTable.MBLOGID + " = " + msgId + " order by " + HomeTable.HomeDataTable.ID + " asc limit 50";
Cursor c = getRsd().rawQuery(sql, null);
Gson gson = new Gson();
while (c.moveToNext()) {
String id = c.getString(c.getColumnIndex(HomeTable.HomeDataTable.ID));
String json = c.getString(c.getColumnIndex(HomeTable.HomeDataTable.JSONDATA));
if (!TextUtils.isEmpty(json)) {
try {
MessageBean value = gson.fromJson(json, MessageBean.class);
value.setComments_count(commentCount);
value.setReposts_count(repostCount);
String[] args = { id };
ContentValues cv = new ContentValues();
cv.put(HomeTable.HomeDataTable.JSONDATA, gson.toJson(value));
getWsd().update(HomeTable.HomeDataTable.TABLE_NAME, cv, HomeTable.HomeDataTable.ID + "=?", args);
} catch (JsonSyntaxException e) {
}
}
}
c.close();
}
use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.
the class MentionsWeiboTimeLineFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//use Up instead of Back to reach this fragment
if (data == null) {
return;
}
final MessageBean msg = data.getParcelableExtra("msg");
if (msg != null) {
for (int i = 0; i < getList().getSize(); i++) {
if (msg.equals(getList().getItem(i))) {
MessageBean ori = getList().getItem(i);
if (ori.getComments_count() != msg.getComments_count() || ori.getReposts_count() != msg.getReposts_count()) {
ori.setReposts_count(msg.getReposts_count());
ori.setComments_count(msg.getComments_count());
MentionWeiboTimeLineDBTask.asyncReplace(getList(), accountBean.getUid());
getAdapter().notifyDataSetChanged();
}
break;
}
}
}
}
use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.
the class MentionsWeiboTimeLineFragment method addNewDataAndRememberPosition.
private void addNewDataAndRememberPosition(final MessageListBean newValue) {
AppLogger.i("Add new unread data to memory cache");
if (getActivity() == null || newValue.getSize() == 0) {
AppLogger.i("Activity is destroyed or new data count is zero, give up");
return;
}
final boolean isDataSourceEmpty = getList().getSize() == 0;
TimeLinePosition previousPosition = Utility.getCurrentPositionFromListView(getListView());
getList().addNewData(newValue);
if (isDataSourceEmpty) {
newMsgTipBar.setValue(newValue, true);
newMsgTipBar.clearAndReset();
getAdapter().notifyDataSetChanged();
AppLogger.i("Init data source is empty, ListView jump to zero position after refresh, first time open app? ");
getListView().setSelection(0);
saveTimeLinePositionToDB();
} else {
if (previousPosition.isEmpty() && timeLinePosition != null) {
previousPosition = timeLinePosition;
}
AppLogger.i("Previous first visible item id " + previousPosition.firstItemId);
getAdapter().notifyDataSetChanged();
List<MessageBean> unreadData = newValue.getItemList();
for (MessageBean message : unreadData) {
if (message != null) {
MentionsWeiboTimeLineFragment.this.timeLinePosition.newMsgIds.add(message.getIdLong());
}
}
newMsgTipBar.setValue(MentionsWeiboTimeLineFragment.this.timeLinePosition.newMsgIds);
int positionInAdapter = Utility.getAdapterPositionFromItemId(getAdapter(), previousPosition.firstItemId);
//use 1 px to show newMsgTipBar
AppLogger.i("ListView restore to previous position " + positionInAdapter);
getListView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
getListView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
AppLogger.i("Save ListView position to database");
saveTimeLinePositionToDB();
}
});
Utility.setListViewAdapterPosition(getListView(), positionInAdapter, previousPosition.top - 1, null);
}
showUIUnreadCount(MentionsWeiboTimeLineFragment.this.timeLinePosition.newMsgIds.size());
MentionWeiboTimeLineDBTask.asyncReplace(getList(), accountBean.getUid());
}
use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.
the class MyStatusDBTask method get.
public static MyStatusTimeLineData get(String accountId) {
Gson gson = new Gson();
MessageListBean result = new MessageListBean();
List<MessageBean> msgList = new ArrayList<MessageBean>();
String sql = "select * from " + MyStatusTable.StatusDataTable.TABLE_NAME + " where " + MyStatusTable.StatusDataTable.ACCOUNTID + " = " + accountId + " order by " + MyStatusTable.StatusDataTable.MBLOGID + " desc limit 50";
Cursor c = getRsd().rawQuery(sql, null);
while (c.moveToNext()) {
String json = c.getString(c.getColumnIndex(MyStatusTable.StatusDataTable.JSONDATA));
try {
MessageBean value = gson.fromJson(json, MessageBean.class);
if (!value.isMiddleUnreadItem()) {
value.getListViewSpannableString();
}
msgList.add(value);
} catch (JsonSyntaxException ignored) {
}
}
result.setStatuses(msgList);
c.close();
return new MyStatusTimeLineData(result, getPosition(accountId));
}
Aggregations