Ejemplo n.º 1
0
 @Override
 public Observable<VoteResult> voteCommonItem(Long commentId, VoteType voteType) {
   return this.picService
       .voteCommonItem(voteType == VoteType.OO ? 1 : 0, commentId)
       .map(
           responseBody -> {
             try {
               return VoteResult.fromString(responseBody.string(), voteType);
             } catch (IOException e) {
               return VoteResult.Voted;
             }
           })
       .doOnNext(
           voteResult -> {
             if (voteResult == VoteResult.Thanks) {
               PicItem picItem =
                   CloudPicDataStore.this
                       .picItemDao
                       .queryBuilder()
                       .where(PicItemDao.Properties.PicId.eq(commentId))
                       .build()
                       .forCurrentThread()
                       .unique();
               if (picItem != null) {
                 if (voteType == VoteType.OO) {
                   picItem.setVotePositive(picItem.getVotePositive() + 1);
                   CloudPicDataStore.this.picItemDao.update(picItem);
                 } else if (voteType == VoteType.XX) {
                   picItem.setVoteNegative(picItem.getVoteNegative() + 1);
                   CloudPicDataStore.this.picItemDao.update(picItem);
                 }
               }
             }
           });
 }
Ejemplo n.º 2
0
  /** @inheritdoc */
  @Override
  protected void bindValues(SQLiteStatement stmt, PicItem entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
      stmt.bindLong(1, id);
    }

    Long picId = entity.getPicId();
    if (picId != null) {
      stmt.bindLong(2, picId);
    }

    String author = entity.getAuthor();
    if (author != null) {
      stmt.bindString(3, author);
    }

    String authorEmail = entity.getAuthorEmail();
    if (authorEmail != null) {
      stmt.bindString(4, authorEmail);
    }

    String authorUrl = entity.getAuthorUrl();
    if (authorUrl != null) {
      stmt.bindString(5, authorUrl);
    }

    Timestamp date = entity.getDate();
    if (date != null) {
      stmt.bindLong(6, dateConverter.convertToDatabaseValue(date));
    }

    Long votePositive = entity.getVotePositive();
    if (votePositive != null) {
      stmt.bindLong(7, votePositive);
    }

    Long voteNegative = entity.getVoteNegative();
    if (voteNegative != null) {
      stmt.bindLong(8, voteNegative);
    }

    Long commentCount = entity.getCommentCount();
    if (commentCount != null) {
      stmt.bindLong(9, commentCount);
    }

    String threadId = entity.getThreadId();
    if (threadId != null) {
      stmt.bindString(10, threadId);
    }

    String content = entity.getContent();
    if (content != null) {
      stmt.bindString(11, content);
    }

    String textContent = entity.getTextContent();
    if (textContent != null) {
      stmt.bindString(12, textContent);
    }

    String pics = entity.getPics();
    if (pics != null) {
      stmt.bindString(13, pics);
    }

    String picFirst = entity.getPicFirst();
    if (picFirst != null) {
      stmt.bindString(14, picFirst);
    }

    Long picCount = entity.getPicCount();
    if (picCount != null) {
      stmt.bindLong(15, picCount);
    }

    Boolean hasGif = entity.getHasGif();
    if (hasGif != null) {
      stmt.bindLong(16, hasGif ? 1L : 0L);
    }
  }