Search in sources :

Example 1 with ClearUnreadDao

use of org.qii.weiciyuan.dao.unread.ClearUnreadDao in project weiciyuan by qii.

the class MainFriendsTimeLineDao method getMsgListJson.

private String getMsgListJson() throws WeiboException {
    String url = getUrl();
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("since_id", since_id);
    map.put("max_id", max_id);
    map.put("count", count);
    map.put("page", page);
    map.put("base_app", base_app);
    map.put("feature", feature);
    map.put("trim_user", trim_user);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    try {
        new ClearUnreadDao(access_token, ClearUnreadDao.STATUS).clearUnread();
    } catch (WeiboException ignored) {
    }
    return jsonData;
}
Also used : ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) WeiboException(org.qii.weiciyuan.support.error.WeiboException) HashMap(java.util.HashMap)

Example 2 with ClearUnreadDao

use of org.qii.weiciyuan.dao.unread.ClearUnreadDao in project weiciyuan by qii.

the class JBInboxNotification method get.

public Notification get() {
    Notification.Builder builder = new Notification.Builder(context).setTicker(NotificationUtility.getTicker(unreadBean, null, null, null)).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent()).setOnlyAlertOnce(true);
    builder.setContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
    if (NotificationUtility.getCount(unreadBean) > 1) {
        builder.setNumber(NotificationUtility.getCount(unreadBean));
    }
    if (clearNotificationEventReceiver != null) {
        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
        JBInboxNotification.clearNotificationEventReceiver = null;
    }
    clearNotificationEventReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionStatusUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
                    } catch (WeiboException ignored) {
                    } finally {
                        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
                        JBInboxNotification.clearNotificationEventReceiver = null;
                    }
                }
            }).start();
        }
    };
    IntentFilter intentFilter = new IntentFilter("org.qii.weiciyuan.Notification.unread");
    GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);
    Intent broadcastIntent = new Intent("org.qii.weiciyuan.Notification.unread");
    PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);
    Notification.InboxStyle inboxStyle = new Notification.InboxStyle(builder);
    inboxStyle.setBigContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
    if (comment != null) {
        for (CommentBean c : comment.getItemList()) {
            inboxStyle.addLine(c.getUser().getScreen_name() + ":" + c.getText());
        }
    }
    if (repost != null) {
        for (MessageBean m : repost.getItemList()) {
            inboxStyle.addLine(m.getUser().getScreen_name() + ":" + m.getText());
        }
    }
    if (mentionCommentsResult != null) {
        for (CommentBean m : mentionCommentsResult.getItemList()) {
            inboxStyle.addLine(m.getUser().getScreen_name() + ":" + m.getText());
        }
    }
    inboxStyle.setSummaryText(accountBean.getUsernick());
    builder.setStyle(inboxStyle);
    Utility.configVibrateLedRingTone(builder);
    return builder.build();
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver) Notification(android.app.Notification) ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) WeiboException(org.qii.weiciyuan.support.error.WeiboException) PendingIntent(android.app.PendingIntent)

Example 3 with ClearUnreadDao

use of org.qii.weiciyuan.dao.unread.ClearUnreadDao in project weiciyuan by qii.

the class SimpleTextNotificationService method buildNotification.

private void buildNotification(String uid) {
    ValueWrapper valueWrapper = valueBagHashMap.get(uid);
    if (valueWrapper == null) {
        return;
    }
    final AccountBean accountBean = valueWrapper.accountBean;
    final UnreadBean unreadBean = valueWrapper.unreadBean;
    Intent clickToOpenAppPendingIntentInner = valueWrapper.clickToOpenAppPendingIntentInner;
    String ticker = valueWrapper.ticker;
    final RecordOperationAppBroadcastReceiver clearNotificationEventReceiver = valueWrapper.clearNotificationEventReceiver;
    Notification.Builder builder = new Notification.Builder(getBaseContext()).setTicker(ticker).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent(clickToOpenAppPendingIntentInner)).setOnlyAlertOnce(true);
    builder.setContentTitle(ticker);
    Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver);
    valueWrapper.clearNotificationEventReceiver = new RecordOperationAppBroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionStatusUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
                    } catch (WeiboException ignored) {
                    } finally {
                        Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver);
                        if (Utility.isDebugMode()) {
                            new Handler(Looper.getMainLooper()).post(new Runnable() {

                                @Override
                                public void run() {
                                    Toast.makeText(getApplicationContext(), "weiciyuan:remove notification items", Toast.LENGTH_SHORT).show();
                                }
                            });
                        }
                    }
                }
            }).start();
        }
    };
    IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);
    GlobalContext.getInstance().registerReceiver(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);
    Utility.configVibrateLedRingTone(builder);
    NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(getMentionsWeiboNotificationId(accountBean), builder.build());
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RecordOperationAppBroadcastReceiver(org.qii.weiciyuan.support.lib.RecordOperationAppBroadcastReceiver) Notification(android.app.Notification) ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) UnreadBean(org.qii.weiciyuan.bean.UnreadBean) WeiboException(org.qii.weiciyuan.support.error.WeiboException) PendingIntent(android.app.PendingIntent) AccountBean(org.qii.weiciyuan.bean.AccountBean)

Example 4 with ClearUnreadDao

use of org.qii.weiciyuan.dao.unread.ClearUnreadDao in project weiciyuan by qii.

the class ICSNotification method get.

public Notification get() {
    Notification.Builder builder = new Notification.Builder(context).setTicker(getTicker()).setContentTitle(getTicker()).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent()).setOnlyAlertOnce(true);
    if (getCount() > 1) {
        builder.setNumber(getCount());
    }
    Utility.configVibrateLedRingTone(builder);
    if (clearNotificationEventReceiver != null) {
        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
        ICSNotification.clearNotificationEventReceiver = null;
    }
    clearNotificationEventReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionStatusUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
                    } catch (WeiboException ignored) {
                    } finally {
                        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
                        ICSNotification.clearNotificationEventReceiver = null;
                    }
                }
            }).start();
        }
    };
    IntentFilter intentFilter = new IntentFilter("org.qii.weiciyuan.Notification.unread");
    GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);
    Intent broadcastIntent = new Intent("org.qii.weiciyuan.Notification.unread");
    PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);
    return builder.getNotification();
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) WeiboException(org.qii.weiciyuan.support.error.WeiboException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver) Notification(android.app.Notification)

Example 5 with ClearUnreadDao

use of org.qii.weiciyuan.dao.unread.ClearUnreadDao in project weiciyuan by qii.

the class JBBigTextNotification method get.

public Notification get() {
    Notification.Builder builder = new Notification.Builder(context).setTicker(NotificationUtility.getTicker(unreadBean, null, null, null)).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent()).setOnlyAlertOnce(true);
    builder.setContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
    builder.setNumber(1);
    if (clearNotificationEventReceiver != null) {
        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
        JBBigTextNotification.clearNotificationEventReceiver = null;
    }
    clearNotificationEventReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionStatusUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
                    } catch (WeiboException ignored) {
                    } finally {
                        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
                        JBBigTextNotification.clearNotificationEventReceiver = null;
                    }
                }
            }).start();
        }
    };
    IntentFilter intentFilter = new IntentFilter("org.qii.weiciyuan.Notification.unread");
    GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);
    Intent broadcastIntent = new Intent("org.qii.weiciyuan.Notification.unread");
    PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);
    Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
    if (unreadBean.getMention_status() == 1) {
        bigTextStyle.setBigContentTitle(repost.getItem(0).getUser().getScreen_name() + ":");
        bigTextStyle.bigText(repost.getItem(0).getText());
        Intent intent = new Intent(context, WriteCommentActivity.class);
        intent.putExtra("token", accountBean.getAccess_token());
        intent.putExtra("msg", repost.getItem(0));
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.comment_light, context.getString(R.string.comments), pendingIntent);
    }
    if (unreadBean.getCmt() == 1) {
        bigTextStyle.setBigContentTitle(comment.getItem(0).getUser().getScreen_name() + ":");
        bigTextStyle.bigText(comment.getItem(0).getText());
        Intent intent = new Intent(context, WriteReplyToCommentActivity.class);
        intent.putExtra("token", accountBean.getAccess_token());
        intent.putExtra("msg", comment.getItem(0));
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.reply_to_comment_light, context.getString(R.string.reply_to_comment), pendingIntent);
    }
    if (unreadBean.getMention_cmt() == 1) {
        bigTextStyle.setBigContentTitle(mentionCommentsResult.getItem(0).getUser().getScreen_name() + ":");
        bigTextStyle.bigText(mentionCommentsResult.getItem(0).getText());
        Intent intent = new Intent(context, WriteReplyToCommentActivity.class);
        intent.putExtra("token", accountBean.getAccess_token());
        intent.putExtra("msg", mentionCommentsResult.getItem(0));
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.reply_to_comment_light, context.getString(R.string.reply_to_comment), pendingIntent);
    }
    bigTextStyle.setSummaryText(accountBean.getUsernick());
    builder.setStyle(bigTextStyle);
    Utility.configVibrateLedRingTone(builder);
    return builder.build();
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver) Notification(android.app.Notification) ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) WeiboException(org.qii.weiciyuan.support.error.WeiboException) PendingIntent(android.app.PendingIntent)

Aggregations

ClearUnreadDao (org.qii.weiciyuan.dao.unread.ClearUnreadDao)5 WeiboException (org.qii.weiciyuan.support.error.WeiboException)5 Notification (android.app.Notification)4 PendingIntent (android.app.PendingIntent)4 Context (android.content.Context)4 Intent (android.content.Intent)4 IntentFilter (android.content.IntentFilter)4 GlobalContext (org.qii.weiciyuan.support.utils.GlobalContext)4 BroadcastReceiver (android.content.BroadcastReceiver)3 NotificationManager (android.app.NotificationManager)1 Handler (android.os.Handler)1 HashMap (java.util.HashMap)1 AccountBean (org.qii.weiciyuan.bean.AccountBean)1 UnreadBean (org.qii.weiciyuan.bean.UnreadBean)1 RecordOperationAppBroadcastReceiver (org.qii.weiciyuan.support.lib.RecordOperationAppBroadcastReceiver)1