use of org.qii.weiciyuan.bean.CommentBean in project weiciyuan by qii.
the class BigTextNotificationService method getPendingIntent.
private PendingIntent getPendingIntent(Intent clickToOpenAppPendingIntentInner, Parcelable itemBean, AccountBean accountBean) {
clickToOpenAppPendingIntentInner.setExtrasClassLoader(getClass().getClassLoader());
UnreadTabIndex unreadTabIndex = UnreadTabIndex.NONE;
if (itemBean instanceof MessageBean) {
unreadTabIndex = UnreadTabIndex.MENTION_WEIBO;
} else if (itemBean instanceof CommentBean) {
CommentBean commentBean = (CommentBean) itemBean;
MessageBean messageBean = commentBean.getStatus();
if (messageBean != null) {
UserBean userBean = messageBean.getUser();
if (accountBean.getInfo().equals(userBean)) {
unreadTabIndex = UnreadTabIndex.COMMENT_TO_ME;
} else {
unreadTabIndex = UnreadTabIndex.MENTION_COMMENT;
}
} else {
unreadTabIndex = UnreadTabIndex.MENTION_COMMENT;
}
}
clickToOpenAppPendingIntentInner.putExtra(BundleArgsConstants.OPEN_NAVIGATION_INDEX_EXTRA, unreadTabIndex);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), getMentionsWeiboNotificationId(accountBean), clickToOpenAppPendingIntentInner, PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
}
use of org.qii.weiciyuan.bean.CommentBean in project weiciyuan by qii.
the class AppNotificationCenter method addDatabaseUnreadMentionsComment.
private void addDatabaseUnreadMentionsComment(String accountId, CommentListBean mentions) {
CommentTimeLineData dbData = MentionCommentsTimeLineDBTask.getCommentLineMsgList(accountId);
List<CommentBean> itemList = dbData.cmtList.getItemList();
TimeLinePosition position = dbData.position;
TreeSet<Long> newMsgIds = position.newMsgIds;
HashMap<Long, CommentBean> map = new HashMap<>();
for (CommentBean 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;
}
CommentBean msg = map.get(id);
if (msg != null) {
mentions.getItemList().add(msg);
}
}
}
use of org.qii.weiciyuan.bean.CommentBean in project weiciyuan by qii.
the class AppNotificationCenter method showNotification.
private void showNotification(Context context, AccountBean accountBean, MessageListBean mentionsWeiboData, CommentListBean commentsToMeData, CommentListBean mentionsCommentData, UnreadBean unreadBean) {
Intent clickNotificationToOpenAppPendingIntentInner = MainTimeLineActivity.newIntent(accountBean, mentionsWeiboData, mentionsCommentData, commentsToMeData, unreadBean);
clickNotificationToOpenAppPendingIntentInner.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
String accountId = accountBean.getUid();
Set<String> dbUnreadMentionsWeibo = NotificationDBTask.getUnreadMsgIds(accountId, NotificationDBTask.UnreadDBType.mentionsWeibo);
Set<String> dbUnreadMentionsComment = NotificationDBTask.getUnreadMsgIds(accountId, NotificationDBTask.UnreadDBType.mentionsComment);
Set<String> dbUnreadCommentsToMe = NotificationDBTask.getUnreadMsgIds(accountId, NotificationDBTask.UnreadDBType.commentsToMe);
if (mentionsWeiboData != null && mentionsWeiboData.getSize() > 0) {
List<MessageBean> msgList = mentionsWeiboData.getItemList();
Iterator<MessageBean> iterator = msgList.iterator();
while (iterator.hasNext()) {
MessageBean msg = iterator.next();
if (dbUnreadMentionsWeibo.contains(msg.getId())) {
iterator.remove();
}
}
}
if (mentionsCommentData != null && mentionsCommentData.getSize() > 0) {
List<CommentBean> msgList = mentionsCommentData.getItemList();
Iterator<CommentBean> iterator = msgList.iterator();
while (iterator.hasNext()) {
CommentBean msg = iterator.next();
if (dbUnreadMentionsComment.contains(msg.getId())) {
iterator.remove();
}
}
}
if (commentsToMeData != null && commentsToMeData.getSize() > 0) {
List<CommentBean> msgList = commentsToMeData.getItemList();
Iterator<CommentBean> iterator = msgList.iterator();
while (iterator.hasNext()) {
CommentBean msg = iterator.next();
if (dbUnreadCommentsToMe.contains(msg.getId())) {
iterator.remove();
}
}
}
boolean mentionsWeibo = (mentionsWeiboData != null && mentionsWeiboData.getSize() > 0);
boolean mentionsComment = (mentionsCommentData != null && mentionsCommentData.getSize() > 0);
boolean commentsToMe = (commentsToMeData != null && commentsToMeData.getSize() > 0);
if (!mentionsWeibo && !mentionsComment && !commentsToMe) {
return;
}
String ticker = NotificationUtility.getTicker(unreadBean, mentionsWeiboData, mentionsCommentData, commentsToMeData);
Intent intent = BigTextNotificationService.newIntent(accountBean, mentionsWeiboData, commentsToMeData, mentionsCommentData, unreadBean, clickNotificationToOpenAppPendingIntentInner, ticker, 0);
context.startService(intent);
}
use of org.qii.weiciyuan.bean.CommentBean in project weiciyuan by qii.
the class DraftDBManager method getDraftList.
public List<DraftListViewItemBean> getDraftList(String accountId) {
Gson gson = new Gson();
List<DraftListViewItemBean> result = new ArrayList<DraftListViewItemBean>();
String sql = "select * from " + DraftTable.TABLE_NAME + " where " + DraftTable.ACCOUNTID + " = " + accountId + " order by " + DraftTable.ID + " desc";
Cursor c = rsd.rawQuery(sql, null);
while (c.moveToNext()) {
DraftListViewItemBean item = new DraftListViewItemBean();
int type = c.getInt(c.getColumnIndex(DraftTable.TYPE));
item.setType(type);
item.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
String content;
switch(type) {
case DraftTable.TYPE_WEIBO:
content = c.getString(c.getColumnIndex(DraftTable.CONTENT));
StatusDraftBean bean = new StatusDraftBean();
bean.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
bean.setContent(content);
bean.setAccountId(accountId);
String gpsJson = c.getString(c.getColumnIndex(DraftTable.GPS));
if (!TextUtils.isEmpty(gpsJson)) {
bean.setGps(new Gson().fromJson(gpsJson, GeoBean.class));
}
bean.setPic(c.getString(c.getColumnIndex(DraftTable.PIC)));
item.setStatusDraftBean(bean);
result.add(item);
break;
case DraftTable.TYPE_REPOST:
content = c.getString(c.getColumnIndex(DraftTable.CONTENT));
RepostDraftBean repostDraftBean = new RepostDraftBean();
repostDraftBean.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
repostDraftBean.setContent(content);
repostDraftBean.setAccountId(accountId);
MessageBean messageBean = gson.fromJson(c.getString(c.getColumnIndex(DraftTable.JSONDATA)), MessageBean.class);
repostDraftBean.setMessageBean(messageBean);
item.setRepostDraftBean(repostDraftBean);
result.add(item);
break;
case DraftTable.TYPE_COMMENT:
content = c.getString(c.getColumnIndex(DraftTable.CONTENT));
CommentDraftBean commentDraftBean = new CommentDraftBean();
commentDraftBean.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
commentDraftBean.setContent(content);
commentDraftBean.setAccountId(accountId);
MessageBean commentMessageBean = gson.fromJson(c.getString(c.getColumnIndex(DraftTable.JSONDATA)), MessageBean.class);
commentDraftBean.setMessageBean(commentMessageBean);
item.setCommentDraftBean(commentDraftBean);
result.add(item);
break;
case DraftTable.TYPE_REPLY:
content = c.getString(c.getColumnIndex(DraftTable.CONTENT));
ReplyDraftBean replyDraftBean = new ReplyDraftBean();
replyDraftBean.setId(c.getString(c.getColumnIndex(DraftTable.ID)));
replyDraftBean.setContent(content);
replyDraftBean.setAccountId(accountId);
CommentBean commentBean = gson.fromJson(c.getString(c.getColumnIndex(DraftTable.JSONDATA)), CommentBean.class);
replyDraftBean.setCommentBean(commentBean);
item.setReplyDraftBean(replyDraftBean);
result.add(item);
break;
}
}
c.close();
return result;
}
use of org.qii.weiciyuan.bean.CommentBean in project weiciyuan by qii.
the class JBCommentsToMeNotificationServiceHelper method buildNotification.
private void buildNotification() {
// int count = (data.getSize() >= Integer.valueOf(SettingUtility.getMsgCount()) ? unreadBean
// .getCmt() : data.getSize());
int count = Math.min(unreadBean.getCmt(), data.getSize());
if (count == 0) {
return;
}
Notification.Builder builder = new Notification.Builder(getBaseContext()).setTicker(ticker).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent()).setOnlyAlertOnce(true);
builder.setContentTitle(String.format(GlobalContext.getInstance().getString(R.string.new_comments), String.valueOf(count)));
if (count > 1) {
builder.setNumber(count);
}
if (clearNotificationEventReceiver.get(accountBean.getUid()) != null) {
Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver.get(accountBean.getUid()));
JBCommentsToMeNotificationServiceHelper.clearNotificationEventReceiver.put(accountBean.getUid(), null);
}
RecordOperationAppBroadcastReceiver receiver = new RecordOperationAppBroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
new Thread(new Runnable() {
@Override
public void run() {
try {
// new ClearUnreadDao(accountBean.getAccess_token())
// .clearCommentUnread(unreadBean, accountBean.getUid());
// } catch (WeiboException ignored) {
ArrayList<String> ids = new ArrayList<String>();
for (CommentBean msg : data.getItemList()) {
ids.add(msg.getId());
}
NotificationDBTask.addUnreadNotification(accountBean.getUid(), ids, NotificationDBTask.UnreadDBType.commentsToMe);
} finally {
Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver.get(accountBean.getUid()));
JBCommentsToMeNotificationServiceHelper.clearNotificationEventReceiver.put(accountBean.getUid(), null);
}
}
}).start();
}
};
clearNotificationEventReceiver.put(accountBean.getUid(), receiver);
IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_COMMENTS_TO_ME_ACTION);
GlobalContext.getInstance().registerReceiver(receiver, intentFilter);
Intent broadcastIntent = new Intent(RESET_UNREAD_COMMENTS_TO_ME_ACTION);
PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setDeleteIntent(deletedPendingIntent);
Intent intent = WriteReplyToCommentActivity.newIntentFromNotification(getApplicationContext(), accountBean, data.getItem(currentIndex));
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);
if (count > 1) {
Intent nextIntent = new Intent(JBCommentsToMeNotificationServiceHelper.this, JBCommentsToMeNotificationServiceHelper.class);
nextIntent.putExtra(NotificationServiceHelper.ACCOUNT_ARG, accountBean);
nextIntent.putExtra(NotificationServiceHelper.COMMENTS_TO_ME_ARG, data);
nextIntent.putExtra(NotificationServiceHelper.UNREAD_ARG, unreadBean);
nextIntent.putExtra(NotificationServiceHelper.PENDING_INTENT_INNER_ARG, clickToOpenAppPendingIntentInner);
nextIntent.putExtra(NotificationServiceHelper.TICKER, ticker);
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;
}
nextIntent.putExtra(NotificationServiceHelper.CURRENT_INDEX_ARG, nextIndex);
PendingIntent retrySendIntent = PendingIntent.getService(JBCommentsToMeNotificationServiceHelper.this, 0, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(actionDrawable, actionName, retrySendIntent);
}
Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
CommentBean commentBean = data.getItem(currentIndex);
if (commentBean.getReply_comment() != null) {
bigTextStyle.setBigContentTitle("@" + data.getItem(currentIndex).getUser().getScreen_name() + getString(R.string.reply_to_you));
} else {
bigTextStyle.setBigContentTitle("@" + data.getItem(currentIndex).getUser().getScreen_name() + getString(R.string.comment_sent_to_you));
}
bigTextStyle.bigText(data.getItem(currentIndex).getText());
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(getCommentsToMeNotificationId(accountBean), builder.build());
}
Aggregations