Search in sources :

Example 41 with MessageBean

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

the class HomeOtherGroupTimeLineDBTask method addHomeLineMsg.

private static void addHomeLineMsg(MessageListBean list, String accountId, String groupId) {
    if (list == null || list.getSize() == 0) {
        return;
    }
    Gson gson = new Gson();
    List<MessageBean> msgList = list.getItemList();
    DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), HomeOtherGroupTable.HomeOtherGroupDataTable.TABLE_NAME);
    final int mblogidColumn = ih.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.MBLOGID);
    final int accountidColumn = ih.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.ACCOUNTID);
    final int jsondataColumn = ih.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.JSONDATA);
    final int groupidColumn = ih.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.GROUPID);
    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);
                ih.bind(groupidColumn, groupId);
            } else {
                ih.bind(mblogidColumn, "-1");
                ih.bind(accountidColumn, accountId);
                ih.bind(jsondataColumn, "");
                ih.bind(groupidColumn, groupId);
            }
            ih.execute();
        }
        getWsd().setTransactionSuccessful();
    } catch (SQLException e) {
    } finally {
        getWsd().endTransaction();
        ih.close();
    }
    reduceHomeOtherGroupTable(accountId, groupId);
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) SQLException(android.database.SQLException) DatabaseUtils(android.database.DatabaseUtils) Gson(com.google.gson.Gson)

Example 42 with MessageBean

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

the class MentionWeiboTimeLineDBTask method getRepostLineMsgList.

public static MentionTimeLineData getRepostLineMsgList(String accountId) {
    TimeLinePosition position = getPosition(accountId);
    Gson gson = new Gson();
    MessageListBean result = new MessageListBean();
    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<MessageBean> msgList = new ArrayList<MessageBean>();
    String sql = "select * from " + RepostsTable.RepostDataTable.TABLE_NAME + " where " + RepostsTable.RepostDataTable.ACCOUNTID + "  = " + accountId + " order by " + RepostsTable.RepostDataTable.MBLOGID + " desc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(RepostsTable.RepostDataTable.JSONDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                MessageBean value = gson.fromJson(json, MessageBean.class);
                if (!value.isMiddleUnreadItem()) {
                    value.getListViewSpannableString();
                }
                msgList.add(value);
            } catch (JsonSyntaxException e) {
                AppLogger.e(e.getMessage());
            }
        } else {
            msgList.add(null);
        }
    }
    result.setStatuses(msgList);
    c.close();
    MentionTimeLineData mentionTimeLineData = new MentionTimeLineData(result, position);
    return mentionTimeLineData;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) MentionTimeLineData(org.qii.weiciyuan.bean.android.MentionTimeLineData) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) Cursor(android.database.Cursor)

Example 43 with MessageBean

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

the class MentionWeiboTimeLineDBTask method addRepostLineMsg.

public static void addRepostLineMsg(MessageListBean list, String accountId) {
    Gson gson = new Gson();
    List<MessageBean> msgList = list.getItemList();
    int size = msgList.size();
    DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), RepostsTable.RepostDataTable.TABLE_NAME);
    final int mblogidColumn = ih.getColumnIndex(RepostsTable.RepostDataTable.MBLOGID);
    final int accountidColumn = ih.getColumnIndex(RepostsTable.RepostDataTable.ACCOUNTID);
    final int jsondataColumn = ih.getColumnIndex(RepostsTable.RepostDataTable.JSONDATA);
    try {
        getWsd().beginTransaction();
        for (int i = 0; i < 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();
    }
    reduceRepostTable(accountId);
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) SQLException(android.database.SQLException) DatabaseUtils(android.database.DatabaseUtils) Gson(com.google.gson.Gson)

Example 44 with MessageBean

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

the class UserInfoFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data == null) {
        return;
    }
    MessageBean msg = (MessageBean) data.getParcelableExtra("msg");
    if (msg != null) {
        for (int i = 0; i < getList().getSize(); i++) {
            if (msg.equals(getList().getItem(i))) {
                getList().getItem(i).setReposts_count(msg.getReposts_count());
                getList().getItem(i).setComments_count(msg.getComments_count());
                break;
            }
        }
        getAdapter().notifyDataSetChanged();
    }
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) TextPaint(android.text.TextPaint)

Example 45 with MessageBean

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

the class MyFavListFragment 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 = (MessageBean) 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());
                    FavouriteDBTask.asyncReplace(getList(), page, account.getUid());
                    getAdapter().notifyDataSetChanged();
                }
                break;
            }
        }
    }
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean)

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