@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // setup convert view if it is null
    final ListCell cell;
    if (convertView == null) {
      convertView = inflator.inflate(R.layout.get_all_food, null);
      cell = new ListCell();

      cell.Name = (TextView) convertView.findViewById(R.id.Name);
      cell.Price = (TextView) convertView.findViewById(R.id.Price);

      convertView.setTag(cell);
    } else {
      cell = (ListCell) convertView.getTag();
    }
    // change the data of the cell
    try {

      JSONObject jsonObject = this.dataArray.getJSONObject(position);
      cell.Name.setText("Name :" + jsonObject.getString("Name"));
      cell.Price.setText("Price :" + jsonObject.getDouble("Price"));

    } catch (JSONException e) {
      e.printStackTrace();
    }

    return convertView;
  }
  @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();
    }
  }
Exemple #3
0
 @Override
 protected void updateItem(final Tab tab, boolean empty) {
   super.updateItem(tab, empty);
   if (tab != null) {
     tab.getUnreadProperty()
         .addListener(
             new ChangeListener<Boolean>() {
               @Override
               public void changed(
                   ObservableValue<? extends Boolean> observableValue,
                   Boolean oldValue,
                   Boolean newValue) {
                 if (newValue) {
                   getStyleClass().add("unread");
                 } else {
                   getStyleClass().remove("unread");
                 }
               }
             });
     Entity entity = tab.getEntity();
     setPrefHeight(32);
     if (entity instanceof Server) {
       setPrefHeight(40);
       Label net = new Label("network");
       net.getStyleClass().add("network");
       VBox box = new VBox();
       Label name = new Label(entity.getName());
       name.getStyleClass().add("network-name");
       box.getChildren().addAll(net, name);
       setGraphic(box);
     } else if (entity instanceof Channel) {
       final Label label = new Label(entity.getName().substring(1));
       label.getStyleClass().add("name");
       final HBox box = new HBox();
       box.getChildren().addAll(FontAwesome.createIcon(FontAwesome.COMMENTS), label);
       setGraphic(box);
     } else if (entity instanceof User) {
       final Label label = new Label(entity.getName());
       label.getStyleClass().add("name");
       final HBox box = new HBox();
       box.getChildren().addAll(FontAwesome.createIcon(FontAwesome.USER), label);
       setGraphic(box);
     }
   }
 }
Exemple #4
0
 @Override
 protected void updateItem(Task item, boolean empty) {
   super.updateItem(item, empty);
   updateViewModel();
 }
Exemple #5
0
 @Override
 public void cancelEdit() {
   super.cancelEdit();
   updateViewModel();
 }
Exemple #6
0
 @Override
 public void startEdit() {
   super.startEdit();
   updateViewModel();
 }