예제 #1
0
      @Override
      public void onClick(View v) {
        final int currentPos = cells.indexOf(formCell);
        long prevVirtualTimestamp = -1;
        long nextVirtualTimestamp = -1;
        if (currentPos != cells.size() - 1) {
          // The form position is not the end of the list.
          if (currentPos == 0) {
            prevVirtualTimestamp = 0;
            nextVirtualTimestamp = cells.get(currentPos + 1).getVirtualTimestamp();
          } else {
            prevVirtualTimestamp = cells.get(currentPos - 1).getVirtualTimestamp();
            nextVirtualTimestamp = cells.get(currentPos + 1).getVirtualTimestamp();
          }
        }

        if (prevVirtualTimestamp != -1
            && nextVirtualTimestamp != -1
            && !isSameDate(
                Post.virtualTimestampToDate(prevVirtualTimestamp),
                Post.virtualTimestampToDate(nextVirtualTimestamp))) {
          // Make sure to make a post not to beyond a day.
          Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Tokyo"));
          cal.setTime(Post.virtualTimestampToDate(prevVirtualTimestamp));
          cal.set(Calendar.HOUR_OF_DAY, 23);
          cal.set(Calendar.MINUTE, 59);
          cal.set(Calendar.SECOND, 59);
          cal.set(Calendar.MILLISECOND, 999);
          nextVirtualTimestamp = Post.dateToVirtualTimestamp(cal.getTime());
        }

        if (v.getId() == R.id.postButton) {
          Intent intent = new Intent(activity, PostTimelineActivity.class);
          intent.putExtra(PostTimelineActivity.LECTURE_ID, lectureId);
          intent.putExtra(PostTimelineActivity.PREV_VIRTUAL_TS, prevVirtualTimestamp);
          intent.putExtra(PostTimelineActivity.NEXT_VIRTUAL_TS, nextVirtualTimestamp);
          activity.startActivityForResult(intent, 0);
        } else if (v.getId() == R.id.postImageButton) {
          Intent intent = new Intent(activity, PostImageActivity.class);
          intent.putExtra(PostImageActivity.LECTURE_ID, lectureId);
          intent.putExtra(PostImageActivity.PREV_VIRTUAL_TS, prevVirtualTimestamp);
          intent.putExtra(PostImageActivity.NEXT_VIRTUAL_TS, nextVirtualTimestamp);
          activity.startActivityForResult(intent, 0);
        }
      }
예제 #2
0
  @Override
  public void onUpdate(SortedSet<Post> posts) {
    synchronized (cells) {
      boolean formCellAdded = false;
      long beforeFormCellId = Long.MAX_VALUE;
      if (!cells.get(cells.size() - 1).equals(formCell)) {
        final int currentPos = cells.indexOf(formCell);
        beforeFormCellId = cells.get(currentPos - 1).getItemId();
      }

      cells.clear();
      Date prevDate = null;
      Date lastSeparatorDate = null;
      ListCell prevCell = null;
      for (Post post : posts) {
        Date currentDate = Post.virtualTimestampToDate(post.getVirtualTimestamp());
        if (prevDate == null || !isSameDate(prevDate, currentDate)) {
          lastSeparatorDate = currentDate;
          prevCell = new DateSeparatorCell(currentDate);
          cells.add(prevCell);
          if (!formCellAdded && prevCell.getItemId() == beforeFormCellId) {
            cells.add(formCell);
            formCellAdded = true;
          }
        }
        prevDate = currentDate;

        prevCell = new PostCell(post);
        cells.add(prevCell);
        if (!formCellAdded && prevCell.getItemId() == beforeFormCellId) {
          cells.add(formCell);
          formCellAdded = true;
        }
      }

      if (lastSeparatorDate == null || !isSameDate(lastSeparatorDate, new Date())) {
        cells.add(new DateSeparatorCell(new Date()));
      }

      if (!formCellAdded) {
        cells.add(formCell);
      }
      observable.notifyChanged();
    }
  }