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;
}
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;
}
Aggregations