Search in sources :

Example 6 with MessageListBean

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

the class FetchNewMsgService method fetchMsg.

private void fetchMsg(AccountBean accountBean) throws WeiboException {
    CommentListBean commentResult = null;
    MessageListBean mentionStatusesResult = null;
    CommentListBean mentionCommentsResult = null;
    UnreadBean unreadBean = null;
    String token = accountBean.getAccess_token();
    UnreadDao unreadDao = new UnreadDao(token, accountBean.getUid());
    unreadBean = unreadDao.getCount();
    if (unreadBean == null) {
        return;
    }
    int unreadCommentCount = unreadBean.getCmt();
    int unreadMentionStatusCount = unreadBean.getMention_status();
    int unreadMentionCommentCount = unreadBean.getMention_cmt();
    if (unreadCommentCount > 0 && SettingUtility.allowCommentToMe()) {
        MainCommentsTimeLineDao dao = new MainCommentsTimeLineDao(token);
        CommentListBean oldData = null;
        CommentTimeLineData commentTimeLineData = CommentToMeTimeLineDBTask.getCommentLineMsgList(accountBean.getUid());
        if (commentTimeLineData != null) {
            oldData = commentTimeLineData.cmtList;
        }
        if (oldData != null && oldData.getSize() > 0) {
            dao.setSince_id(oldData.getItem(0).getId());
        }
        commentResult = dao.getGSONMsgListWithoutClearUnread();
    }
    if (unreadMentionStatusCount > 0 && SettingUtility.allowMentionToMe()) {
        MentionsWeiboTimeLineDao dao = new MentionsWeiboTimeLineDao(token);
        MessageListBean oldData = null;
        MentionTimeLineData mentionStatusTimeLineData = MentionWeiboTimeLineDBTask.getRepostLineMsgList(accountBean.getUid());
        if (mentionStatusTimeLineData != null) {
            oldData = mentionStatusTimeLineData.msgList;
        }
        if (oldData != null && oldData.getSize() > 0) {
            dao.setSince_id(oldData.getItem(0).getId());
        }
        mentionStatusesResult = dao.getGSONMsgListWithoutClearUnread();
    }
    if (unreadMentionCommentCount > 0 && SettingUtility.allowMentionCommentToMe()) {
        MainCommentsTimeLineDao dao = new MentionsCommentTimeLineDao(token);
        CommentListBean oldData = null;
        CommentTimeLineData commentTimeLineData = MentionCommentsTimeLineDBTask.getCommentLineMsgList(accountBean.getUid());
        if (commentTimeLineData != null) {
            oldData = commentTimeLineData.cmtList;
        }
        if (oldData != null && oldData.getSize() > 0) {
            dao.setSince_id(oldData.getItem(0).getId());
        }
        mentionCommentsResult = dao.getGSONMsgListWithoutClearUnread();
    }
    clearDatabaseUnreadInfo(accountBean.getUid(), unreadBean.getMention_status(), unreadBean.getMention_cmt(), unreadBean.getCmt());
    boolean mentionsWeibo = (mentionStatusesResult != null && mentionStatusesResult.getSize() > 0);
    boolean mentionsComment = (mentionCommentsResult != null && mentionCommentsResult.getSize() > 0);
    boolean commentsToMe = (commentResult != null && commentResult.getSize() > 0);
    if (mentionsWeibo || mentionsComment || commentsToMe) {
        sendTwoKindsOfBroadcast(accountBean, commentResult, mentionStatusesResult, mentionCommentsResult, unreadBean);
    } else {
    //            NotificationManager notificationManager = (NotificationManager) getApplicationContext()
    //                    .getSystemService(NOTIFICATION_SERVICE);
    //            notificationManager.cancel(
    //                    NotificationServiceHelper.getMentionsWeiboNotificationId(accountBean));
    }
}
Also used : MainCommentsTimeLineDao(org.qii.weiciyuan.dao.maintimeline.MainCommentsTimeLineDao) UnreadBean(org.qii.weiciyuan.bean.UnreadBean) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) CommentTimeLineData(org.qii.weiciyuan.bean.android.CommentTimeLineData) MentionTimeLineData(org.qii.weiciyuan.bean.android.MentionTimeLineData) MentionsCommentTimeLineDao(org.qii.weiciyuan.dao.maintimeline.MentionsCommentTimeLineDao) CommentListBean(org.qii.weiciyuan.bean.CommentListBean) UnreadDao(org.qii.weiciyuan.dao.unread.UnreadDao) MentionsWeiboTimeLineDao(org.qii.weiciyuan.dao.maintimeline.MentionsWeiboTimeLineDao)

Example 7 with MessageListBean

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

the class UnreadMsgReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    AccountBean accountBean = (AccountBean) intent.getParcelableExtra(BundleArgsConstants.ACCOUNT_EXTRA);
    CommentListBean commentsToMeData = (CommentListBean) intent.getParcelableExtra(BundleArgsConstants.COMMENTS_TO_ME_EXTRA);
    MessageListBean mentionsWeiboData = (MessageListBean) intent.getParcelableExtra(BundleArgsConstants.MENTIONS_WEIBO_EXTRA);
    CommentListBean mentionsCommentData = (CommentListBean) intent.getParcelableExtra(BundleArgsConstants.MENTIONS_COMMENT_EXTRA);
    UnreadBean unreadBean = (UnreadBean) intent.getParcelableExtra(BundleArgsConstants.UNREAD_EXTRA);
    showNotification(context, accountBean, mentionsWeiboData, commentsToMeData, mentionsCommentData, unreadBean);
}
Also used : UnreadBean(org.qii.weiciyuan.bean.UnreadBean) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) CommentListBean(org.qii.weiciyuan.bean.CommentListBean) AccountBean(org.qii.weiciyuan.bean.AccountBean)

Example 8 with MessageListBean

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

the class FriendsTimeLineDBTask method getOtherGroupData.

public static List<MessageTimeLineData> getOtherGroupData(String accountId, String exceptGroupId) {
    List<MessageTimeLineData> data = new ArrayList<MessageTimeLineData>();
    if (!"0".equals(exceptGroupId)) {
        TimeLinePosition position = getPosition(accountId);
        MessageListBean msgList = getHomeLineMsgList(accountId, position.position + AppConfig.DB_CACHE_COUNT_OFFSET);
        MessageTimeLineData home = new MessageTimeLineData("0", msgList, position);
        data.add(home);
    }
    MessageTimeLineData biGroup = HomeOtherGroupTimeLineDBTask.getTimeLineData(accountId, "1");
    data.add(biGroup);
    GroupListBean groupListBean = GroupDBTask.get(accountId);
    if (groupListBean != null) {
        List<GroupBean> lists = groupListBean.getLists();
        for (GroupBean groupBean : lists) {
            MessageTimeLineData dbMsg = HomeOtherGroupTimeLineDBTask.getTimeLineData(accountId, groupBean.getId());
            data.add(dbMsg);
        }
    }
    Iterator<MessageTimeLineData> iterator = data.iterator();
    while (iterator.hasNext()) {
        MessageTimeLineData single = iterator.next();
        if (single.groupId.equals(exceptGroupId)) {
            iterator.remove();
            break;
        }
    }
    return data;
}
Also used : MessageListBean(org.qii.weiciyuan.bean.MessageListBean) ArrayList(java.util.ArrayList) GroupListBean(org.qii.weiciyuan.bean.GroupListBean) GroupBean(org.qii.weiciyuan.bean.GroupBean) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) MessageTimeLineData(org.qii.weiciyuan.bean.android.MessageTimeLineData)

Example 9 with MessageListBean

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

Example 10 with MessageListBean

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

the class HomeOtherGroupTimeLineDBTask method get.

static MessageListBean get(String accountId, String groupId, 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 " + HomeOtherGroupTable.HomeOtherGroupDataTable.TABLE_NAME + " where " + HomeOtherGroupTable.HomeOtherGroupDataTable.ACCOUNTID + "  = " + accountId + " and " + HomeOtherGroupTable.HomeOtherGroupDataTable.GROUPID + " =  " + groupId + " order by " + HomeOtherGroupTable.HomeOtherGroupDataTable.ID + " asc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.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);
        }
    }
    //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;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Aggregations

MessageListBean (org.qii.weiciyuan.bean.MessageListBean)25 Gson (com.google.gson.Gson)8 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 MessageBean (org.qii.weiciyuan.bean.MessageBean)8 ArrayList (java.util.ArrayList)6 CommentListBean (org.qii.weiciyuan.bean.CommentListBean)5 Cursor (android.database.Cursor)4 UnreadBean (org.qii.weiciyuan.bean.UnreadBean)4 TimeLinePosition (org.qii.weiciyuan.bean.android.TimeLinePosition)4 MentionTimeLineData (org.qii.weiciyuan.bean.android.MentionTimeLineData)3 MessageTimeLineData (org.qii.weiciyuan.bean.android.MessageTimeLineData)3 AccountBean (org.qii.weiciyuan.bean.AccountBean)2 MentionsWeiboTimeLineDao (org.qii.weiciyuan.dao.maintimeline.MentionsWeiboTimeLineDao)2 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Bitmap (android.graphics.Bitmap)1