use of com.ushahidi.java.sdk.api.Person 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;
}
Aggregations