@Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    itemposition = info.position;
    if (itemposition > 0) itemposition--; // hay que restar 1 porque la lista tiene un header

    Comment comment = listaComments.get(itemposition);
    // Cuando pulsamos nos aparece como título la fecha y la hora para saber cual seleccionamos
    final int MAXLENGHT = 10;
    String txt = comment.getTxt();
    if (txt.length() > MAXLENGHT) { // truncamos por la longitud maxima
      txt = txt.substring(0, MAXLENGHT) + " ...";
    }
    menu.setHeaderTitle(comment.getUsername() + " : \"" + txt + "\"");

    byte[] img = comment.getImage();
    if (img != null) {
      ByteArrayInputStream is = new ByteArrayInputStream(img);
      menu.setHeaderIcon(Drawable.createFromStream(is, "image"));
    }

    // si somos supervaca o somos los dueños del mensaje
    if ((BuildConfig.SUPERAPP) || (comment.getDevid() == Utilidades.getDevId(getActivity()))) {
      menu.add(
          FRAGMENT_GROUPID,
          R.id.action_borrar_comentario,
          0,
          "Borrar comentario"); // podremos borrar
    }
  }
Пример #2
0
  /* (non-Javadoc)
   * @see ca.cmput301f13t03.adventure_datetime.model.IWebStorage#putComment(ca.cmput301f13t03.adventure_datetime.model.Comment)
   */
  @Override
  public boolean putComment(Comment comment) throws Exception {
    Index index =
        new Index.Builder(comment)
            .index(_index)
            .type("comment")
            .id(comment.getId().toString())
            .build();
    JestResult result = execute(index);

    boolean success = result.isSucceeded();
    if (comment.getImage() != null) {
      success &= putImage(comment.getImage());
    }

    return success;
  }
  public void testGetComments() throws Exception {
    List<Comment> comments = new ArrayList<Comment>();
    List<Comment> returned = new ArrayList<Comment>();
    UUID targetId = UUID.randomUUID();

    for (int i = 0; i < 5; i++) {
      comments.add(createComment(i, targetId));
    }

    for (Comment c : comments) {
      boolean result = es.putComment(c);
      assertTrue(es.getErrorMessage(), result);
    }

    // give elasticsearch some time to sort out its life issues
    Thread.sleep(4000);

    returned = es.getComments(targetId, 0, 10);

    assertEquals(
        "Lists different size!, " + es.getErrorMessage(), comments.size(), returned.size());

    for (Comment c : returned) {
      try {
        es.deleteComment(c.getId());
      } catch (Exception e) {

      }
    }

    for (Comment c : comments) {
      assertTrue("Comment missing from results", returned.contains(c));
    }

    for (Comment c : returned) {
      assertEquals(c.getId(), c.getImage().getId());
      assertNotNull(c.getImage().getEncodedBitmap());
    }
  }