Search in sources :

Example 1 with MentionTimeLineData

use of org.qii.weiciyuan.bean.android.MentionTimeLineData 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 2 with MentionTimeLineData

use of org.qii.weiciyuan.bean.android.MentionTimeLineData in project weiciyuan by qii.

the class AppNotificationCenter method addDatabaseUnreadMentionsWeibo.

private void addDatabaseUnreadMentionsWeibo(String accountId, MessageListBean mentions) {
    MentionTimeLineData dbData = MentionWeiboTimeLineDBTask.getRepostLineMsgList(accountId);
    List<MessageBean> itemList = dbData.msgList.getItemList();
    TimeLinePosition position = dbData.position;
    TreeSet<Long> newMsgIds = position.newMsgIds;
    HashMap<Long, MessageBean> map = new HashMap<>();
    for (MessageBean msg : itemList) {
        map.put(msg.getIdLong(), msg);
    }
    for (Object object : newMsgIds) {
        long id;
        if (object instanceof Double) {
            Double value = (Double) object;
            id = value.longValue();
        } else {
            id = (Long) object;
        }
        MessageBean msg = map.get(id);
        if (msg != null) {
            mentions.getItemList().add(msg);
        }
    }
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) HashMap(java.util.HashMap) MentionTimeLineData(org.qii.weiciyuan.bean.android.MentionTimeLineData) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition)

Example 3 with MentionTimeLineData

use of org.qii.weiciyuan.bean.android.MentionTimeLineData in project weiciyuan by qii.

the class MentionsWeiboTimeLineFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    userBean = getArguments().getParcelable(ARGUMENTS_USER_EXTRA);
    accountBean = getArguments().getParcelable(ARGUMENTS_ACCOUNT_EXTRA);
    token = getArguments().getString(ARGUMENTS_TOKEN_EXTRA);
    super.onActivityCreated(savedInstanceState);
    switch(getCurrentState(savedInstanceState)) {
        case FIRST_TIME_START:
            getLoaderManager().initLoader(DB_CACHE_LOADER_ID, null, dbCallback);
            break;
        case ACTIVITY_DESTROY_AND_CREATE:
            timeLinePosition = (TimeLinePosition) savedInstanceState.getSerializable(ARGUMENTS_TIMELINE_POSITION_EXTRA);
            Loader<MentionTimeLineData> loader = getLoaderManager().getLoader(DB_CACHE_LOADER_ID);
            if (loader != null) {
                getLoaderManager().initLoader(DB_CACHE_LOADER_ID, null, dbCallback);
            }
            MessageListBean savedBean = savedInstanceState.getParcelable(ARGUMENTS_DATA_EXTRA);
            if (savedBean != null && savedBean.getSize() > 0) {
                getList().replaceData(savedBean);
                timeLineAdapter.notifyDataSetChanged();
                refreshLayout(getList());
                AppNotificationCenter.getInstance().addCallback(callback);
            } else {
                getLoaderManager().initLoader(DB_CACHE_LOADER_ID, null, dbCallback);
            }
            break;
    }
}
Also used : MessageListBean(org.qii.weiciyuan.bean.MessageListBean) MentionTimeLineData(org.qii.weiciyuan.bean.android.MentionTimeLineData)

Example 4 with MentionTimeLineData

use of org.qii.weiciyuan.bean.android.MentionTimeLineData 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)

Aggregations

MentionTimeLineData (org.qii.weiciyuan.bean.android.MentionTimeLineData)4 MessageListBean (org.qii.weiciyuan.bean.MessageListBean)3 MessageBean (org.qii.weiciyuan.bean.MessageBean)2 TimeLinePosition (org.qii.weiciyuan.bean.android.TimeLinePosition)2 Cursor (android.database.Cursor)1 Gson (com.google.gson.Gson)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CommentListBean (org.qii.weiciyuan.bean.CommentListBean)1 UnreadBean (org.qii.weiciyuan.bean.UnreadBean)1 CommentTimeLineData (org.qii.weiciyuan.bean.android.CommentTimeLineData)1 MainCommentsTimeLineDao (org.qii.weiciyuan.dao.maintimeline.MainCommentsTimeLineDao)1 MentionsCommentTimeLineDao (org.qii.weiciyuan.dao.maintimeline.MentionsCommentTimeLineDao)1 MentionsWeiboTimeLineDao (org.qii.weiciyuan.dao.maintimeline.MentionsWeiboTimeLineDao)1 UnreadDao (org.qii.weiciyuan.dao.unread.UnreadDao)1