Пример #1
0
  /**
   * @param events
   * @return
   */
  private Group<RecommendMsg> filterEventsFromJiepang(Group<Event> events) {

    Group<RecommendMsg> recommends = new Group<RecommendMsg>();

    if (events.isHasMore()) {
      recommends.setHasMore(true);
    } else {
      recommends.setHasMore(false);
    }

    // remove the events which doesn't come from jianjian and then set it to recommendMsg group
    for (Event it : events) {
      if (it.getFragment() instanceof RecommendMsg) {
        RecommendMsg re = (RecommendMsg) it.getFragment();
        if (re.getProduct() != null) {
          if (it.getCreateDate() != null) {
            re.setCreateDate(it.getCreateDate());
          }
          if (it.getEventId() != null) {
            re.setFragmentId(it.getEventId());
          }

          recommends.add(re);
        }
      }
    }

    return recommends;
  }
Пример #2
0
  /**
   * @param recommends
   * @param mListAdapter2
   */
  private void sortRecommendsRecent(
      Group<RecommendMsg> recommends, SeparatedListAdapter listAdapter) {

    // Sort all by timestamp first.
    Collections.sort(recommends, Comparators.getRecommendsRecencyComparator());

    // We'll group in different section adapters based on some time thresholds.
    Group<RecommendMsg> recent = new Group<RecommendMsg>();
    Group<RecommendMsg> today = new Group<RecommendMsg>();
    Group<RecommendMsg> yesterday = new Group<RecommendMsg>();
    Group<RecommendMsg> older = new Group<RecommendMsg>();

    EventTimestampSort timestamps = new EventTimestampSort();

    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    for (RecommendMsg it : recommends) {
      try {
        Date date = format.parse(it.getCreateDate());
        if (date.after(timestamps.getBoundaryRecent())) {
          recent.add(it);
        } else if (date.after(timestamps.getBoundaryToday())) {
          today.add(it);
        } else if (date.after(timestamps.getBoundaryYesterday())) {
          yesterday.add(it);
        } else {
          older.add(it);
        }
      } catch (Exception ex) {
        Log.e(TAG, "exception during parsing date: " + ex.getMessage());
        older.add(it);
      }
    }
    if (recent.size() > 0) {
      RecommendListAdapter adapter =
          new RecommendListAdapter(
              this, ((Jianjianroid) getApplication()).getRemoteResourceManager());
      adapter.setGroup(recent);
      listAdapter.addSection(
          getResources().getString(R.string.friendsactivity_title_sort_recent), adapter);
    }

    if (today.size() > 0) {
      RecommendListAdapter adapter =
          new RecommendListAdapter(
              this, ((Jianjianroid) getApplication()).getRemoteResourceManager());
      adapter.setGroup(today);
      listAdapter.addSection(
          getResources().getString(R.string.friendsactivity_title_sort_today), adapter);
    }
    if (yesterday.size() > 0) {
      RecommendListAdapter adapter =
          new RecommendListAdapter(
              this, ((Jianjianroid) getApplication()).getRemoteResourceManager());
      adapter.setGroup(yesterday);
      listAdapter.addSection(
          getResources().getString(R.string.friendsactivity_title_sort_yesterday), adapter);
    }
    if (older.size() > 0) {
      RecommendListAdapter adapter =
          new RecommendListAdapter(
              this, ((Jianjianroid) getApplication()).getRemoteResourceManager());
      adapter.setGroup(older);
      listAdapter.addSection(
          getResources().getString(R.string.friendsactivity_title_sort_older), adapter);
    }
  }