@Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    switch (getCurrentState(savedInstanceState)) {
      case FIRST_TIME_START:
        getLoaderManager().initLoader(DB_CACHE_LOADER_ID, null, dbCallback);
        break;
      case ACTIVITY_DESTROY_AND_CREATE:
        userBean = savedInstanceState.getParcelable(Constants.USERBEAN);
        accountBean = savedInstanceState.getParcelable(Constants.ACCOUNT);
        token = savedInstanceState.getString(Constants.TOKEN);
        timeLinePosition =
            (TimeLinePosition) savedInstanceState.getSerializable("timeLinePosition");
        unreadBean = savedInstanceState.getParcelable("unreadBean");

        Loader<CommentTimeLineData> loader = getLoaderManager().getLoader(DB_CACHE_LOADER_ID);
        if (loader != null) {
          getLoaderManager().initLoader(DB_CACHE_LOADER_ID, null, dbCallback);
        }

        CommentListBean savedBean =
            (CommentListBean) savedInstanceState.getSerializable(Constants.BEAN);
        if (savedBean != null && savedBean.getSize() > 0) {
          clearAndReplaceValue(savedBean);
          timeLineAdapter.notifyDataSetChanged();
          // setListViewPositionFromPositionsCache();
        } else {
          getLoaderManager().initLoader(DB_CACHE_LOADER_ID, null, dbCallback);
        }
        break;
    }
  }
 private void addUnreadMessage(CommentListBean data) {
   if (data != null && data.getSize() > 0) {
     CommentBean last = data.getItem(data.getSize() - 1);
     boolean dup = getDataList().getItemList().contains(last);
     if (!dup) {
       addNewDataAndRememberPosition(data);
     }
   }
 }
 @Override
 protected void onNewMsgLoaderSuccessCallback(CommentListBean newValue, Bundle loaderArgs) {
   if (newValue != null && newValue.getItemList() != null && newValue.getItemList().size() > 0) {
     addNewDataAndRememberPosition(newValue);
   }
   unreadBean = null;
   NotificationManager notificationManager =
       (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
   notificationManager.cancel(
       NotificationServiceHelper.getCommentsToMeNotificationId(
           BeeboApplication.getInstance().getAccountBean()));
 }
 @Override
 protected void onOldMsgLoaderSuccessCallback(CommentListBean newValue) {
   if (newValue != null && newValue.getItemList().size() > 1) {
     getDataList().addOldData(newValue);
     getAdapter().notifyDataSetChanged();
     CommentToMeTimeLineDBTask.asyncReplace(getDataList(), accountBean.getUid());
   }
 }
  private void addNewDataAndRememberPosition(final CommentListBean newValue) {

    int initSize = getDataList().getSize();

    if (getActivity() != null && newValue.getSize() > 0) {

      final boolean jumpToTop = getDataList().getSize() == 0;

      getDataList().addNewData(newValue);

      if (!jumpToTop) {
        int index = getListView().getFirstVisiblePosition();
        getAdapter().notifyDataSetChanged();
        int finalSize = getDataList().getSize();
        final int positionAfterRefresh =
            index + finalSize - initSize + getListView().getHeaderViewsCount();
        // use 1 px to show newMsgTipBar
        Utility.setListViewSelectionFromTop(
            getListView(),
            positionAfterRefresh,
            1,
            new Runnable() {

              @Override
              public void run() {
                newMsgTipBar.setValue(newValue, false);
              }
            });
      } else {
        newMsgTipBar.setValue(newValue, true);
        newMsgTipBar.clearAndReset();
        getAdapter().notifyDataSetChanged();
        getListView().setSelection(0);
      }
      CommentToMeTimeLineDBTask.asyncReplace(getDataList(), accountBean.getUid());
      saveTimeLinePositionToDB();
    }
  }
Ejemplo n.º 6
0
  @Deprecated
  public static String getTicker(
      UnreadBean unreadBean,
      MessageListBean mentionsWeibo,
      CommentListBean mentionsComment,
      CommentListBean commentsToMe) {
    int unreadMentionCmt = unreadBean.getMention_cmt();
    int unreadMentionStatus = unreadBean.getMention_status();
    int mention = 0;
    if (SettingUtils.allowMentionToMe() && unreadMentionStatus > 0 && mentionsWeibo != null) {
      int actualFetchedSize = mentionsWeibo.getSize();
      if (actualFetchedSize < Integer.valueOf(SettingUtils.getMsgCount())) {
        mention += actualFetchedSize;
      } else {
        mention += Math.max(actualFetchedSize, unreadMentionStatus);
      }
    }
    if (SettingUtils.allowMentionCommentToMe() && unreadMentionCmt > 0 && mentionsComment != null) {
      int actualFetchedSize = mentionsComment.getSize();
      if (actualFetchedSize < Integer.valueOf(SettingUtils.getMsgCount())) {
        mention += actualFetchedSize;
      } else {
        mention += Math.max(actualFetchedSize, unreadMentionCmt);
      }
    }

    StringBuilder stringBuilder = new StringBuilder();
    if (mention > 0) {
      String txt =
          String.format(
              BeeboApplication.getInstance().getString(R.string.new_mentions),
              String.valueOf(mention));
      stringBuilder.append(txt);
    }

    int unreadCmt = unreadBean.getCmt();

    int cmt = 0;

    if (SettingUtils.allowCommentToMe() && unreadCmt > 0 && commentsToMe != null) {
      //
      int actualFetchedSize = commentsToMe.getSize();
      if (actualFetchedSize < Integer.valueOf(SettingUtils.getMsgCount())) {
        cmt += actualFetchedSize;
      } else {
        cmt += Math.max(actualFetchedSize, unreadCmt);
      }

      if (mention > 0) {
        stringBuilder.append("、");
      }

      if (cmt > 0) {
        String txt =
            String.format(
                BeeboApplication.getInstance().getString(R.string.new_comments),
                String.valueOf(cmt));
        stringBuilder.append(txt);
      }
    }
    return stringBuilder.toString();
  }
 protected void clearAndReplaceValue(CommentListBean value) {
   getDataList().getItemList().clear();
   getDataList().getItemList().addAll(value.getItemList());
 }