Search in sources :

Example 1 with CommentEntity

use of com.ushahidi.android.app.entities.CommentEntity in project Ushahidi_Android by ushahidi.

the class CommentsApi method getCommentsList.

/**
	 * Fetch report's comments using the Ushahidi API
	 * 
	 * @param reportId
	 *            The report ID
	 * @return
	 */
public List<CommentEntity> getCommentsList(int reportId) {
    new Util().log("Save comments");
    if (processingResult) {
        try {
            for (com.ushahidi.java.sdk.api.Comment c : task.reportId(reportId)) {
                CommentEntity comment = new CommentEntity();
                comment.addComment(c);
                comments.add(comment);
            }
        } catch (UshahidiException e) {
            processingResult = false;
            log("CommentsApi getCommentsList", e);
        } catch (JsonSyntaxException e) {
            processingResult = false;
            log("CommentsApi getCommentsList", e);
        }
    }
    return comments;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Util(com.ushahidi.android.app.util.Util) UshahidiException(com.ushahidi.java.sdk.UshahidiException) CommentEntity(com.ushahidi.android.app.entities.CommentEntity)

Example 2 with CommentEntity

use of com.ushahidi.android.app.entities.CommentEntity in project Ushahidi_Android by ushahidi.

the class CommentDao method addComment.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ushahidi.android.app.database.ICommentDao#addComment(java.util.List)
	 */
@Override
public boolean addComment(List<CommentEntity> comments) {
    try {
        mDb.beginTransaction();
        for (CommentEntity comment : comments) {
            addComment(comment);
        }
        mDb.setTransactionSuccessful();
    } finally {
        mDb.endTransaction();
    }
    return true;
}
Also used : CommentEntity(com.ushahidi.android.app.entities.CommentEntity)

Example 3 with CommentEntity

use of com.ushahidi.android.app.entities.CommentEntity in project Ushahidi_Android by ushahidi.

the class CommentDao method fetchCheckinComment.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ushahidi.android.app.database.ICommentDao#fetchCheckinComment(int)
	 */
@Override
public List<CommentEntity> fetchCheckinComment(int checkinId) {
    listComment = new ArrayList<CommentEntity>();
    final String sortOrder = COMMENT_DATE + " DESC";
    final String selection = CHECKIN_ID + " = " + checkinId;
    cursor = super.query(TABLE, COMMENT_COLUMN, selection, null, sortOrder);
    if (cursor != null) {
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            CommentEntity comment = cursorToEntity(cursor);
            listComment.add(comment);
            cursor.moveToNext();
        }
        cursor.close();
    }
    return listComment;
}
Also used : CommentEntity(com.ushahidi.android.app.entities.CommentEntity)

Example 4 with CommentEntity

use of com.ushahidi.android.app.entities.CommentEntity in project Ushahidi_Android by ushahidi.

the class CommentDao method cursorToEntity.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ushahidi.android.app.database.DbContentProvider#cursorToEntity(android
	 * .database.Cursor)
	 */
@SuppressWarnings("unchecked")
@Override
protected CommentEntity cursorToEntity(Cursor cursor) {
    CommentEntity comment = new CommentEntity();
    int idIndex;
    int reportIdIndex;
    int checkinIdIndex;
    int commentIdIndex;
    int commentAuthorIndex;
    int commentDateIndex;
    int commentDescriptionIndex;
    if (cursor != null) {
        if (cursor.getColumnIndex(ID) != -1) {
            idIndex = cursor.getColumnIndexOrThrow(ID);
            comment.setDbId(cursor.getInt(idIndex));
        }
        if (cursor.getColumnIndex(REPORT_ID) != -1) {
            reportIdIndex = cursor.getColumnIndexOrThrow(REPORT_ID);
            comment.setReportId(cursor.getInt(reportIdIndex));
        }
        if (cursor.getColumnIndex(CHECKIN_ID) != -1) {
            checkinIdIndex = cursor.getColumnIndexOrThrow(CHECKIN_ID);
            comment.setCheckinId(cursor.getInt(checkinIdIndex));
        }
        if (cursor.getColumnIndex(COMMENT_AUTHOR) != -1) {
            commentAuthorIndex = cursor.getColumnIndexOrThrow(COMMENT_AUTHOR);
            comment.setCommentAuthor(cursor.getString(commentAuthorIndex));
        }
        if (cursor.getColumnIndex(COMMENT_DESCRIPTION) != -1) {
            commentDescriptionIndex = cursor.getColumnIndexOrThrow(COMMENT_DESCRIPTION);
            comment.setCommentDescription(cursor.getString(commentDescriptionIndex));
        }
        if (cursor.getColumnIndex(COMMENT_DATE) != -1) {
            commentDateIndex = cursor.getColumnIndexOrThrow(COMMENT_DATE);
            comment.setCommentDate(cursor.getString(commentDateIndex));
        }
        if (cursor.getColumnIndex(COMMENT_ID) != -1) {
            commentIdIndex = cursor.getColumnIndexOrThrow(COMMENT_ID);
            comment.setCommentId(cursor.getInt(commentIdIndex));
        }
    }
    return comment;
}
Also used : CommentEntity(com.ushahidi.android.app.entities.CommentEntity)

Example 5 with CommentEntity

use of com.ushahidi.android.app.entities.CommentEntity in project Ushahidi_Android by ushahidi.

the class ListCommentModel method getCommentsByReportId.

public List<ListCommentModel> getCommentsByReportId(int reportId) {
    final List<ListCommentModel> comments = new ArrayList<ListCommentModel>();
    mCommentModel = new ArrayList<CommentEntity>();
    mCommentModel = Database.mCommentDao.fetchReportComment(reportId);
    if (mCommentModel != null && mCommentModel.size() > 0) {
        for (CommentEntity item : mCommentModel) {
            ListCommentModel comment = new ListCommentModel();
            comment.setDbId(item.getDbId());
            comment.setCommentAuthor(item.getCommentAuthor());
            comment.setCommentDescription(item.getCommentDescription());
            comment.setReportId(item.getReportId());
            comment.setCommentId(item.getCommentId());
            comment.setCommentDate(item.getCommentDate());
            comments.add(comment);
        }
    }
    return comments;
}
Also used : ArrayList(java.util.ArrayList) CommentEntity(com.ushahidi.android.app.entities.CommentEntity)

Aggregations

CommentEntity (com.ushahidi.android.app.entities.CommentEntity)7 ArrayList (java.util.ArrayList)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Util (com.ushahidi.android.app.util.Util)1 UshahidiException (com.ushahidi.java.sdk.UshahidiException)1