Search in sources :

Example 36 with MessageBean

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);
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) SQLException(android.database.SQLException) DatabaseUtils(android.database.DatabaseUtils) Gson(com.google.gson.Gson)

Example 37 with MessageBean

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();
}
Also used : ContentValues(android.content.ContentValues) MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Example 38 with MessageBean

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;
            }
        }
    }
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean)

Example 39 with MessageBean

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());
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) ViewTreeObserver(android.view.ViewTreeObserver)

Example 40 with MessageBean

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));
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) MyStatusTimeLineData(org.qii.weiciyuan.bean.android.MyStatusTimeLineData) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Aggregations

MessageBean (org.qii.weiciyuan.bean.MessageBean)52 Gson (com.google.gson.Gson)21 JsonSyntaxException (com.google.gson.JsonSyntaxException)16 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 MessageListBean (org.qii.weiciyuan.bean.MessageListBean)8 Cursor (android.database.Cursor)7 Intent (android.content.Intent)6 CommentBean (org.qii.weiciyuan.bean.CommentBean)6 UserBean (org.qii.weiciyuan.bean.UserBean)6 DatabaseUtils (android.database.DatabaseUtils)4 SQLException (android.database.SQLException)4 View (android.view.View)4 PendingIntent (android.app.PendingIntent)3 Drawable (android.graphics.drawable.Drawable)3 SpannableString (android.text.SpannableString)3 AbsListView (android.widget.AbsListView)3 ListView (android.widget.ListView)3 RelativeLayout (android.widget.RelativeLayout)3 TextView (android.widget.TextView)3