Search in sources :

Example 1 with Response

use of com.ushahidi.java.sdk.api.json.Response in project Ushahidi_Android by ushahidi.

the class ListReportFragment method uploadPendingReports.

private boolean uploadPendingReports() {
    boolean retVal = true;
    ReportFields fields = new ReportFields();
    Incident incident = new Incident();
    ReportsApi reportApi = new ReportsApi();
    if (mPendingReports != null) {
        for (ReportEntity report : mPendingReports) {
            long rid = report.getDbId();
            ;
            int state = Database.mOpenGeoSmsDao.getReportState(rid);
            if (state != IOpenGeoSmsSchema.STATE_NOT_OPENGEOSMS) {
                if (!sendOpenGeoSmsReport(report, state)) {
                    retVal = false;
                }
                continue;
            }
            // Set the incident details
            incident.setTitle(report.getIncident().getTitle());
            incident.setDescription(report.getIncident().getDescription());
            incident.setDate(report.getIncident().getDate());
            incident.setLatitude(report.getIncident().getLatitude());
            incident.setLongitude(report.getIncident().getLongitude());
            incident.setLocationName(report.getIncident().getLocationName());
            fields.fill(incident);
            // Set person details
            if ((!TextUtils.isEmpty(Preferences.fileName)) && (!TextUtils.isEmpty(Preferences.lastname)) && (!TextUtils.isEmpty(Preferences.email))) {
                fields.setPerson(new Person(Preferences.firstname, Preferences.lastname, Preferences.email));
            }
            // Add categories
            fields.addCategory(report.getCategories());
            // Add photos
            List<File> photos = new UploadPhotoAdapter(getActivity()).pendingPhotos((int) report.getDbId());
            if (photos != null && photos.size() > 0)
                fields.addPhotos(photos);
            // Upload
            Response response = reportApi.submitReport(fields);
            if (response != null) {
                if (response.getErrorCode() == 0) {
                    deletePendingReport((int) report.getDbId());
                } else {
                    retVal = false;
                }
            } else {
                deletePendingReport((int) report.getDbId());
            }
        }
    }
    return retVal;
}
Also used : Response(com.ushahidi.java.sdk.api.json.Response) ReportsApi(com.ushahidi.android.app.api.ReportsApi) UploadPhotoAdapter(com.ushahidi.android.app.adapters.UploadPhotoAdapter) Incident(com.ushahidi.java.sdk.api.Incident) ReportEntity(com.ushahidi.android.app.entities.ReportEntity) Person(com.ushahidi.java.sdk.api.Person) File(java.io.File) ReportFields(com.ushahidi.java.sdk.api.ReportFields)

Example 2 with Response

use of com.ushahidi.java.sdk.api.json.Response in project Ushahidi_Android by ushahidi.

the class UploadComments method addComments.

private int addComments(Bundle bundle) {
    CommentFields comment = new CommentFields();
    CommentsApi commentApi = new CommentsApi();
    if (bundle != null) {
        Comment c = new Comment();
        c.setAuthor(bundle.getString("comment_author"));
        c.setDescription(bundle.getString("comment_description"));
        c.setReportId(bundle.getInt("report_id"));
        comment.fill(c);
        comment.setEmail(bundle.getString("comment_email"));
        Response response = commentApi.submit(comment);
        if (response != null) {
            if (response.getErrorCode() == 0) {
                commentApi.saveComments(bundle.getInt("report_id"));
            }
        }
    }
    return 1;
}
Also used : Response(com.ushahidi.java.sdk.api.json.Response) Comment(com.ushahidi.java.sdk.api.Comment) CommentFields(com.ushahidi.java.sdk.api.CommentFields) CommentsApi(com.ushahidi.android.app.api.CommentsApi)

Aggregations

Response (com.ushahidi.java.sdk.api.json.Response)2 UploadPhotoAdapter (com.ushahidi.android.app.adapters.UploadPhotoAdapter)1 CommentsApi (com.ushahidi.android.app.api.CommentsApi)1 ReportsApi (com.ushahidi.android.app.api.ReportsApi)1 ReportEntity (com.ushahidi.android.app.entities.ReportEntity)1 Comment (com.ushahidi.java.sdk.api.Comment)1 CommentFields (com.ushahidi.java.sdk.api.CommentFields)1 Incident (com.ushahidi.java.sdk.api.Incident)1 Person (com.ushahidi.java.sdk.api.Person)1 ReportFields (com.ushahidi.java.sdk.api.ReportFields)1 File (java.io.File)1