private static void decideTimeLineBigPic(Context context) {

    if (SettingUtility.getListAvatarMode() == 3) {
      SettingUtility.setEnableBigAvatar(Utility.isWifi(context));
    }
    if (SettingUtility.getListPicMode() == 3) {
      SettingUtility.setEnableBigPic(Utility.isWifi(context));
    }
  }
 @Override
 protected void onCancelled(Boolean aBoolean) {
   super.onCancelled(aBoolean);
   if (Utility.isAllNotNull(getActivity(), this.e)) {
     Toast.makeText(getActivity(), e.getError(), Toast.LENGTH_SHORT).show();
   }
 }
  public static void judgeNetworkStatus(Context context) {
    if (Utility.isConnected(context)) {

      if (SettingUtility.getEnableFetchMSG()) {
        AppNewMsgAlarm.startAlarm(context, true);
      } else {
        AppNewMsgAlarm.stopAlarm(context, false);
      }

      decideTimeLineBigPic(context);
      decideCommentRepostAvatar(context);
    } else {
      AppNewMsgAlarm.stopAlarm(context, false);
    }
  }
  @Override
  protected void middleMsgOnPostExecute(
      int position, CommentListBean newValue, boolean towardsBottom) {

    if (newValue != null) {
      int size = newValue.getSize();

      if (getActivity() != null && newValue.getSize() > 0) {
        getList().addMiddleData(position, newValue, towardsBottom);

        if (towardsBottom) {
          getAdapter().notifyDataSetChanged();
        } else {

          View v = Utility.getListViewItemViewFromPosition(getListView(), position + 1 + 1);
          int top = (v == null) ? 0 : v.getTop();
          getAdapter().notifyDataSetChanged();
          int ss = position + 1 + size - 1;
          getListView().setSelectionFromTop(ss, top);
        }
      }
    }
  }
  private void buildNotification() {

    int count =
        (data.getSize() >= Integer.valueOf(SettingUtility.getMsgCount())
            ? unreadBean.getMention_status()
            : data.getSize());

    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_mentions_weibo),
            String.valueOf(count)));

    if (data.getSize() > 1) {
      builder.setNumber(count);
    }

    if (clearNotificationEventReceiver != null) {
      Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(
          GlobalContext.getInstance(), clearNotificationEventReceiver);
      JBMentionsWeiboNotificationServiceHelper.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());

                        } catch (WeiboException ignored) {

                        } finally {
                          Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(
                              GlobalContext.getInstance(), clearNotificationEventReceiver);
                          JBMentionsWeiboNotificationServiceHelper.clearNotificationEventReceiver =
                              null;
                        }
                      }
                    })
                .start();
          }
        };

    IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);

    GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);

    Intent broadcastIntent = new Intent(RESET_UNREAD_MENTIONS_WEIBO_ACTION);

    PendingIntent deletedPendingIntent =
        PendingIntent.getBroadcast(
            GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);

    Intent intent = new Intent(getApplicationContext(), WriteCommentActivity.class);
    intent.putExtra("token", accountBean.getAccess_token());
    intent.putExtra("msg", data.getItem(0));

    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.addAction(
        R.drawable.comment_light,
        getApplicationContext().getString(R.string.comments),
        pendingIntent);

    if (data.getSize() > 1) {
      Intent nextIntent =
          new Intent(
              JBMentionsWeiboNotificationServiceHelper.this,
              JBMentionsWeiboNotificationServiceHelper.class);
      nextIntent.putExtra(NotificationServiceHelper.ACCOUNT_ARG, accountBean);
      nextIntent.putExtra(NotificationServiceHelper.MENTIONS_WEIBO_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 < data.getSize() - 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(
              JBMentionsWeiboNotificationServiceHelper.this,
              0,
              nextIntent,
              PendingIntent.FLAG_UPDATE_CURRENT);
      builder.addAction(actionDrawable, actionName, retrySendIntent);
    }

    Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
    if (data.getItem(currentIndex).getText().contains(accountBean.getUsernick())) {
      // mentioned you
      bigTextStyle.setBigContentTitle(
          "@"
              + data.getItem(currentIndex).getUser().getScreen_name()
              + getString(R.string.weibo_at_to_you));
    } else {
      // retweeted your weibo
      bigTextStyle.setBigContentTitle(
          "@"
              + data.getItem(currentIndex).getUser().getScreen_name()
              + getString(R.string.retweeted_your_weibo));
    }
    bigTextStyle.bigText(data.getItem(currentIndex).getText());
    String summaryText;
    if (data.getSize() > 1) {
      summaryText =
          accountBean.getUsernick() + "(" + (currentIndex + 1) + "/" + data.getSize() + ")";
    } 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());
  }
  private static void decideCommentRepostAvatar(Context context) {

    if (SettingUtility.getCommentRepostAvatar() == 3) {
      SettingUtility.setEnableCommentRepostAvatar(Utility.isWifi(context));
    }
  }
 @Override
 protected void onListViewScrollStop() {
   super.onListViewScrollStop();
   timeLinePosition = Utility.getCurrentPositionFromListView(getListView());
 }
Esempio n. 8
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   Utility.cancelTasks(task, avatarTask, topicListTask);
 }