Search in sources :

Example 1 with ReportFields

use of com.ushahidi.java.sdk.api.ReportFields 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)

Aggregations

UploadPhotoAdapter (com.ushahidi.android.app.adapters.UploadPhotoAdapter)1 ReportsApi (com.ushahidi.android.app.api.ReportsApi)1 ReportEntity (com.ushahidi.android.app.entities.ReportEntity)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 Response (com.ushahidi.java.sdk.api.json.Response)1 File (java.io.File)1