Search in sources :

Example 1 with CommentListBean

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

the class MainCommentsTimeLineDao method getGSONMsgList.

public CommentListBean getGSONMsgList() throws WeiboException {
    CommentListBean value = getGSONMsgListWithoutClearUnread();
    clearUnread();
    return value;
}
Also used : CommentListBean(org.qii.weiciyuan.bean.CommentListBean)

Example 2 with CommentListBean

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

the class BigTextNotificationService method buildNotification.

private void buildNotification(String uid) {
    final ValueWrapper valueWrapper = valueBagHashMap.get(uid);
    if (valueWrapper == null) {
        return;
    }
    final AccountBean accountBean = valueWrapper.accountBean;
    final MessageListBean mentionsWeibo = valueWrapper.mentionsWeibo;
    final CommentListBean mentionsComment = valueWrapper.mentionsComment;
    final CommentListBean commentsToMe = valueWrapper.commentsToMe;
    final UnreadBean unreadBean = valueWrapper.unreadBean;
    int currentIndex = valueWrapper.currentIndex;
    Intent clickToOpenAppPendingIntentInner = valueWrapper.clickToOpenAppPendingIntentInner;
    String ticker = valueWrapper.ticker;
    ArrayList<Parcelable> notificationItems = valueWrapper.notificationItems;
    //        int count = Math.min(unreadBean.getMention_status(), data.getSize());
    int count = notificationItems.size();
    if (count == 0) {
        return;
    }
    Parcelable itemBean = notificationItems.get(currentIndex);
    Notification.Builder builder = new Notification.Builder(getBaseContext()).setTicker(ticker).setContentText(ticker).setSubText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent(clickToOpenAppPendingIntentInner, itemBean, accountBean)).setOnlyAlertOnce(true);
    builder.setContentTitle(getString(R.string.app_name));
    if (count > 1) {
        builder.setNumber(count);
    }
    Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), valueWrapper.clearNotificationEventReceiver);
    valueWrapper.clearNotificationEventReceiver = new RecordOperationAppBroadcastReceiver() {

        //mark these messages as read, write to database
        @Override
        public void onReceive(Context context, Intent intent) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        ArrayList<String> ids = new ArrayList<String>();
                        if (mentionsWeibo != null) {
                            for (MessageBean msg : mentionsWeibo.getItemList()) {
                                ids.add(msg.getId());
                            }
                            NotificationDBTask.addUnreadNotification(accountBean.getUid(), ids, NotificationDBTask.UnreadDBType.mentionsWeibo);
                        }
                        ids.clear();
                        if (commentsToMe != null) {
                            for (CommentBean msg : commentsToMe.getItemList()) {
                                ids.add(msg.getId());
                            }
                            NotificationDBTask.addUnreadNotification(accountBean.getUid(), ids, NotificationDBTask.UnreadDBType.commentsToMe);
                        }
                        ids.clear();
                        if (mentionsComment != null) {
                            for (CommentBean msg : mentionsComment.getItemList()) {
                                ids.add(msg.getId());
                            }
                            NotificationDBTask.addUnreadNotification(accountBean.getUid(), ids, NotificationDBTask.UnreadDBType.mentionsComment);
                        }
                    } finally {
                        Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), valueWrapper.clearNotificationEventReceiver);
                        if (Utility.isDebugMode()) {
                            new Handler(Looper.getMainLooper()).post(new Runnable() {

                                @Override
                                public void run() {
                                    Toast.makeText(getApplicationContext(), "weiciyuan:remove notification items" + System.currentTimeMillis(), Toast.LENGTH_SHORT).show();
                                }
                            });
                        }
                    }
                }
            }).start();
        }
    };
    IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);
    Utility.registerReceiverIgnoredReceiverHasRegisteredHereException(GlobalContext.getInstance(), valueWrapper.clearNotificationEventReceiver, intentFilter);
    Intent broadcastIntent = new Intent(RESET_UNREAD_MENTIONS_WEIBO_ACTION);
    PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), accountBean.getUid().hashCode(), broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);
    if (itemBean instanceof MessageBean) {
        MessageBean msg = (MessageBean) itemBean;
        Intent intent = WriteCommentActivity.newIntentFromNotification(getApplicationContext(), accountBean, msg);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.comment_light, getApplicationContext().getString(R.string.comments), pendingIntent);
    } else if (itemBean instanceof CommentBean) {
        CommentBean commentBean = (CommentBean) itemBean;
        Intent intent = WriteReplyToCommentActivity.newIntentFromNotification(getApplicationContext(), accountBean, commentBean);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.reply_to_comment_light, getApplicationContext().getString(R.string.reply_to_comment), pendingIntent);
    }
    String avatar = ((ItemBean) itemBean).getUser().getAvatar_large();
    String avatarPath = FileManager.getFilePathFromUrl(avatar, FileLocationMethod.avatar_large);
    if (ImageUtility.isThisBitmapCanRead(avatarPath) && TaskCache.isThisUrlTaskFinished(avatar)) {
        Bitmap bitmap = BitmapFactory.decodeFile(avatarPath, new BitmapFactory.Options());
        if (bitmap != null) {
            builder.setLargeIcon(bitmap);
        }
    }
    if (count > 1) {
        String actionName;
        int nextIndex;
        int actionDrawable;
        if (currentIndex < count - 1) {
            nextIndex = currentIndex + 1;
            actionName = getString(R.string.next_message);
            actionDrawable = R.drawable.notification_action_next;
        } else {
            nextIndex = 0;
            actionName = getString(R.string.first_message);
            actionDrawable = R.drawable.notification_action_previous;
        }
        Intent nextIntent = BigTextNotificationService.newIntent(accountBean, mentionsWeibo, commentsToMe, mentionsComment, unreadBean, clickToOpenAppPendingIntentInner, ticker, nextIndex);
        PendingIntent retrySendIntent = PendingIntent.getService(BigTextNotificationService.this, accountBean.getUid().hashCode(), nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(actionDrawable, actionName, retrySendIntent);
    }
    Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
    bigTextStyle.setBigContentTitle(getItemBigContentTitle(accountBean, notificationItems, currentIndex));
    bigTextStyle.bigText(getItemBigText(notificationItems, currentIndex));
    String summaryText;
    if (count > 1) {
        summaryText = accountBean.getUsernick() + "(" + (currentIndex + 1) + "/" + count + ")";
    } else {
        summaryText = accountBean.getUsernick();
    }
    bigTextStyle.setSummaryText(summaryText);
    builder.setStyle(bigTextStyle);
    Utility.configVibrateLedRingTone(builder);
    NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(getMentionsWeiboNotificationId(accountBean), builder.build());
}
Also used : ArrayList(java.util.ArrayList) CommentBean(org.qii.weiciyuan.bean.CommentBean) Notification(android.app.Notification) Bitmap(android.graphics.Bitmap) UnreadBean(org.qii.weiciyuan.bean.UnreadBean) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) CommentListBean(org.qii.weiciyuan.bean.CommentListBean) BitmapFactory(android.graphics.BitmapFactory) AccountBean(org.qii.weiciyuan.bean.AccountBean) Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) MessageBean(org.qii.weiciyuan.bean.MessageBean) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Parcelable(android.os.Parcelable) RecordOperationAppBroadcastReceiver(org.qii.weiciyuan.support.lib.RecordOperationAppBroadcastReceiver) PendingIntent(android.app.PendingIntent)

Example 3 with CommentListBean

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

the class AppNotificationCenter method refreshToUI.

public void refreshToUI(final AccountBean account) {
    final MessageListBean mentions = unreadMentions.get(account);
    final CommentListBean comments = unreadComments.get(account);
    final CommentListBean mentionsComment = unreadMentionsComment.get(account);
    this.uiHandler.post(new Runnable() {

        @Override
        public void run() {
            AppLogger.i("Post unread data to ui");
            for (Callback callback : callbackList) {
                if (mentions != null) {
                    AppLogger.i("Post unread mention weibo data to ui: " + callback.getClass().getSimpleName());
                    callback.unreadMentionsChanged(account, mentions);
                }
                if (comments != null) {
                    AppLogger.i("Post unread comment to me data to ui: " + callback.getClass().getSimpleName());
                    callback.unreadCommentsChanged(account, comments);
                }
                if (mentionsComment != null) {
                    AppLogger.i("Post unread mention comments data to ui: " + callback.getClass().getSimpleName());
                    callback.unreadMentionsCommentChanged(account, mentionsComment);
                }
            }
        }
    });
}
Also used : MessageListBean(org.qii.weiciyuan.bean.MessageListBean) CommentListBean(org.qii.weiciyuan.bean.CommentListBean)

Example 4 with CommentListBean

use of org.qii.weiciyuan.bean.CommentListBean 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 5 with CommentListBean

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

Aggregations

CommentListBean (org.qii.weiciyuan.bean.CommentListBean)22 CommentBean (org.qii.weiciyuan.bean.CommentBean)7 CommentTimeLineData (org.qii.weiciyuan.bean.android.CommentTimeLineData)7 Gson (com.google.gson.Gson)6 JsonSyntaxException (com.google.gson.JsonSyntaxException)6 MessageListBean (org.qii.weiciyuan.bean.MessageListBean)5 ArrayList (java.util.ArrayList)4 UnreadBean (org.qii.weiciyuan.bean.UnreadBean)4 Cursor (android.database.Cursor)3 HashMap (java.util.HashMap)3 TimeLinePosition (org.qii.weiciyuan.bean.android.TimeLinePosition)3 AccountBean (org.qii.weiciyuan.bean.AccountBean)2 MainCommentsTimeLineDao (org.qii.weiciyuan.dao.maintimeline.MainCommentsTimeLineDao)2 MentionsCommentTimeLineDao (org.qii.weiciyuan.dao.maintimeline.MentionsCommentTimeLineDao)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