Example #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);
                 }
               }
             }
           });
 }
Example #2
0
  public CloudPicDataStore(
      ICommonItemService picService,
      ICommentService commentService,
      PicItemDao picItemDao,
      MetaDao metaDao) {
    this.picService = picService;
    this.commentService = commentService;
    this.picItemDao = picItemDao;
    this.metaDao = metaDao;

    this.refreshComment =
        picItems -> {
          CloudPicDataStore.this
              .commentService
              .getDuoshuoCommentList(
                  Joiner.on(",")
                      .join(
                          Lists.transform(
                              picItems, picItem -> Constants.THREAD_PREFIX + picItem.getPicId())))
              .subscribeOn(Schedulers.io())
              .observeOn(Schedulers.io())
              .subscribe(
                  commentCountResponse -> {
                    // TODO: optimize this with tx
                    List<PicItem> picItemList = new ArrayList<PicItem>();
                    for (String key : commentCountResponse.getResponse().keySet()) {
                      CommentCountResponse.CommentCount commentCount =
                          commentCountResponse.getResponse().get(key);
                      Long picId = commentCount.getCommonItemId();
                      logger.info("{}:{}", commentCount.getThreadKey(), commentCount.getCount());
                      PicItem picItem =
                          CloudPicDataStore.this
                              .picItemDao
                              .queryBuilder()
                              .where(PicItemDao.Properties.PicId.eq(picId))
                              .unique();
                      if (picItem != null) {
                        picItem.setCommentCount(commentCount.getCount());
                        picItem.setThreadId(commentCount.getThreadId());
                        picItemList.add(picItem);
                      }
                    }
                    if (picItemList.size() > 0)
                      CloudPicDataStore.this.picItemDao.updateInTx(picItemList);
                  },
                  throwable -> {});
        };
  }
Example #3
0
 /** @inheritdoc */
 @Override
 public Long getKey(PicItem entity) {
   if (entity != null) {
     return entity.getId();
   } else {
     return null;
   }
 }
Example #4
0
 /** @inheritdoc */
 @Override
 protected Long updateKeyAfterInsert(PicItem entity, long rowId) {
   entity.setId(rowId);
   return rowId;
 }
Example #5
0
 /** @inheritdoc */
 @Override
 protected void readEntity(Cursor cursor, PicItem entity, int offset) {
   entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
   entity.setPicId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
   entity.setAuthor(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
   entity.setAuthorEmail(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
   entity.setAuthorUrl(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
   entity.setDate(
       cursor.isNull(offset + 5)
           ? null
           : dateConverter.convertToEntityProperty(Timestamp.class, cursor.getLong(offset + 5)));
   entity.setVotePositive(cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6));
   entity.setVoteNegative(cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7));
   entity.setCommentCount(cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8));
   entity.setThreadId(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
   entity.setContent(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
   entity.setTextContent(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
   entity.setPics(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
   entity.setPicFirst(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
   entity.setPicCount(cursor.isNull(offset + 14) ? null : cursor.getLong(offset + 14));
   entity.setHasGif(cursor.isNull(offset + 15) ? null : cursor.getShort(offset + 15) != 0);
 }
Example #6
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);
    }
  }