@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); } } } }); }
/** @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); }